Managing Context and Cost in Claude Code
In the last two posts we covered the building blocks that give Claude Code real power — subagents and hooks. Now for the skill that quietly decides your speed and your bill: managing context. Every fact here is checked against the official docs.
What the context window actually is
Context is everything Claude can see in this session: the system prompt, your CLAUDE.md, auto memory, the files it has read, and the whole conversation so far. It is finite — a fixed budget of tokens. Run /context any time for a live breakdown of what is loaded.
Here is the part people miss: Claude Code sends your full conversation with every message. So a one-line question in a session that has been open all day does not cost one line — it pays for the whole history again. That is why a long session gets slower and more expensive even when you are barely typing.
/clear, /compact, and /context
# wipe the context when a task is finished — costs nothing
/clear
# summarize a long session but keep the important parts
/compact
# see exactly what is loaded right now
/contextUse /clear when you switch to unrelated work — old conversation crowds out the files you need next and taxes every message. Use /compact when one long task starts to drag; you can even focus it, like /compact focus on the auth fix. One honest caveat: /compact reads the whole conversation to summarize it, so it is itself a large request, while /clear is free. And you do not have to remember — Claude Code auto-compacts as you approach the limit.
Why cost follows context
- Prompt caching reuses repeated content like the system prompt and your CLAUDE.md, so it is not reprocessed every time. On a subscription the cache lasts about an hour.
- Match the model to the job — Sonnet handles most coding and costs less than Opus. Switch with /model.
- Tune thinking. Extended thinking helps hard reasoning but is billed as output tokens; for simple tasks lower the effort with /effort.
- Delegate big reads to a subagent — the verbose file reads stay in its context and only a short summary returns to yours.
Treat context as your main budget. Keep it small on purpose: /clear between tasks, /compact when one drags, /context to check, /usage to see your spend, and the right model for the job. Do that and both speed and cost take care of themselves.
Next post: MCP — connecting Claude to your outside tools and data.