Context and cost control
Keep answer quality high over long, multi-task sessions with Claude Code, while keeping usage under control.
I. What context is and why Claude seems to get “dumber”
Everything in a session sits in the context: what you say, the files it has read, command output, and screenshots. The longer the context gets:
- every request gets slower and more expensive;
- early details are more easily diluted;
- the more irrelevant information there is, the more likely answers drift off target.
So managing context really comes down to keeping only useful information in the main conversation.
II. Key commands
| Command | What it does | When to use it |
|---|---|---|
/clear |
Clears the current session | When switching to a completely unrelated task |
/compact |
Compresses earlier content into a summary | When you’ve been on the same task for a long time and want to continue |
--continue / --resume |
Resumes a previous session | When picking up the same task the next day |
Rule of thumb: one task per session. Run /clear after finishing one thing. That works far better than doing ten things in one session.
III. Keeping the main conversation clean
- Hand broad searches to a subagent (Part 04): hundreds of lines of search results stay in the subagent, and the main conversation only gets the conclusion.
- Don’t read large files in full: have it use
grepto locate the spot first, then read only the few dozen lines it needs. - Truncate long output: when command output is very long, have it look only at
head/tailor the key lines after filtering. - Take screenshots with a purpose: every screenshot takes up context space, and once a screenshot has served its verification purpose, there’s no need to keep looking at it.
IV. Put rules in files, not in chat
Repeating the same requirement in chat every time wastes context and is easy to miss. Instead:
- Project conventions →
CLAUDE.md; - Personal habits (language, style) → the user-level
~/.claude/CLAUDE.md; - Fixed workflows → Skills;
- Mistakes it has made and approaches you’ve corrected → have it save them to memory or to
CLAUDE.md.
V. Cutting rework is the biggest saving
The most expensive thing isn’t reading files, it’s doing something wrong and starting over. A few habits help:
- Plan first (Part 03): write code only once the direction is right;
- Be clear whether you want discussion or execution: avoid treating “would this work?” as “go change it”;
- Small commits, verify early: verify each step, so a mistake only costs a small rework;
- Give screenshots and the exact error text: more accurate than a description, and fewer detours.
VI. Choosing a model
Use different models for different tasks (switch with /model):
- Complex design, hard debugging, large changes: use the strongest model. Getting it right in one pass is cheaper than repeated trial and error;
- Simple edits, formatting cleanup, bulk mechanical operations: a faster, cheaper model is fine;
- Subagents: mechanical search tasks can use a fast model, and review tasks should use a strong model.
VII. A checklist
Before finishing a task, go through this list:
- ☐ Did this session only cover one task? Should I run
/clear? - ☐ Is there a large search in the main conversation that should have gone to a subagent?
- ☐ Have I repeated the same rule over and over? It should be written into
CLAUDE.md. - ☐ Does the change have verification evidence (build / tests / screenshots)?
- ☐ Are there lessons worth keeping (a Skill, memory, docs)?