~/academy $ claude learn context-and-cost
Context, models and cost in Claude Code
How the Claude Code context window fills, how to use /context, /compact and /clear, how to choose models and effort, and how to keep usage and spend under control. 8 min
$ Read
What fills the context window
The context window is everything Claude has in front of it. Before you type, it already holds the system prompt, your CLAUDE.md files, auto memory, MCP tool names and skill descriptions. Then every file Claude reads, every command output and every reply is added.
Each request sends the whole conversation again. Prompt caching makes repeats cheaper, but a long session still costs more per message than a short one, even for a one-line question.
When the window gets close to full, Claude Code compacts automatically: it replaces older history with a summary so you can keep going.
Lesson notes: Context, models and cost in Claude Code
Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You can see what is filling your context, trim it, and pick a model and effort level that fits the job.
Step 1 of 7 · Read
What fills the context window
The context window is everything Claude has in front of it. Before you type, it already holds the system prompt, your CLAUDE.md files, auto memory, MCP tool names and skill descriptions. Then every file Claude reads, every command output and every reply is added.
Each request sends the whole conversation again. Prompt caching makes repeats cheaper, but a long session still costs more per message than a short one, even for a one-line question.
When the window gets close to full, Claude Code compacts automatically: it replaces older history with a summary so you can keep going.
Step 2 of 7 · Try it in the terminal
See what is using space
In a Claude Code session, show a breakdown of what is filling the context window right now.
Hint: A slash command named after what you want to inspect.
Show the command
$ /context Context usage ██████░░░░░░░░░░░░░░ 58k / 1M tokens System prompt 4.2k Memory files 2.1k (CLAUDE.md, MEMORY.md) Skills 0.5k MCP tools 0.1k Messages 51.3k Suggestion: CLAUDE.md loads in every request. Consider moving workflow steps into skills.
Step 3 of 7 · Read
Clear, compact or keep going
/clear starts a new conversation with empty context, and costs nothing. Use it when you switch to unrelated work. Run
/renamefirst so you can find the old one again with/resume./compact summarises the conversation so far and carries on. Add a focus to steer the summary:
/compact keep the auth bug details and test results. It reads the whole conversation to do this, so compacting a huge session is itself a large request.After compacting, the project CLAUDE.md, auto memory and the plan are reloaded, and up to five recently used files are re-read. Detailed earlier discussion survives only as summary.
Step 4 of 7 · Read
Choose the model and the effort
/modelswitches model and saves it as your default;claude --model sonnetsets it for one session. Aliases includeopus,sonnet,haiku,fableandopusplan, which plans with Opus and builds with Sonnet. On Pro, Max, Ultra, Team, Enterprise and the API the default is Opus 5.5 (checked 18 November 2026).The docs suggest Sonnet for most coding because it costs less, Opus for hard architecture and multi-step reasoning, and
model: haikufor simple subagent tasks.Effort sets how much the model thinks before answering.
/efforttakeslow,medium,high,xhighormax, and the 5.5 models default to medium (checked 18 November 2026). Thinking is billed as output, so lower effort on simple jobs saves usage.Step 5 of 7 · Read
Keep usage under control
/usage(also/cost) shows your session's token use and an estimated cost. On a subscription it also shows your plan limits and what is using them, with suggested fixes. For scale, Anthropic reports enterprise averages of about $13 per developer per active day and $150 to $250 per developer per month (checked 18 November 2026).The habits that save most: clear between tasks, keep CLAUDE.md under about 200 lines, move rarely used instructions into skills, turn off MCP servers you are not using in
/mcp, send noisy work to subagents and write specific prompts. In scripts, cap spend with--max-budget-usd.Step 6 of 7 · Quiz
Check your understanding
You finish a long debugging session and now want to write documentation for an unrelated module. What should you do first?
- Run /compact so the debugging details stay available
- Switch to Opus with /model
- Just keep going in the same session
- Run /rename, then /clear
Show the answer
Run /rename, then /clear Unrelated work deserves a clean slate, which costs nothing. The name lets you /resume the old session later.
Step 7 of 7 · Sort
Clear or compact?
Which fits each moment?
- Moving from a payments bug to a new marketing page
- Halfway through a big refactor and the context is filling up
- Claude has gone down the wrong path and the history is now confusing it
- Before a long test run on the feature you are still building
- Starting the next ticket in the morning
Show the answers
- Moving from a payments bug to a new marketing page: /clear. Nothing carries over. Start clean.
- Halfway through a big refactor and the context is filling up: /compact. You need continuity. A focused summary keeps the thread.
- Claude has gone down the wrong path and the history is now confusing it: /clear. A fresh start with a better prompt usually beats summarising a muddle.
- Before a long test run on the feature you are still building: /compact. Compact with a focus such as /compact keep the test plan, then carry on.
- Starting the next ticket in the morning: /clear. A new task gets a new conversation. /resume is there if you need yesterday.