Context is a budget. Five habits that stretch it.
One task per session, files over pastes, a lean CLAUDE.md, fewer tools and a three-line handoff. Five habits that keep Claude Code sharp in long sessions.
Every message, every file Claude reads and every command output lands in the same context window. It fills faster than you expect, and quality drops as it fills: earlier instructions get missed and mistakes creep in. A bigger window doesn’t remove the problem. It just moves it.
So treat context as a budget. Here are five habits that stretch it, plus the three commands you need to see where it goes. They apply to Claude Code directly, and most of them apply to any coding agent.
First, look at the budget
Before changing anything, see what you’re spending context on. Claude Code has three commands for this:
/contextshows current context usage as a coloured grid, with suggestions for context-heavy tools, memory files and capacity warnings./compact [instructions]summarizes the conversation so far to free space. The optional instructions tell it what to keep./clearstarts a new conversation with empty context. The old one is saved and you can return to it with/resume.
Run /context at the start of a fresh session, before your first prompt. You may be surprised. Across 30 days of our own work (157 Claude Code sessions and 134 Codex sessions), the median session had already used 58k tokens of context before the first prompt, mostly on tool and skill listings. Method and details are on the Xval Engine page.
1. One task per session
The most expensive context is context you no longer need. When you finish a task and start an unrelated one in the same session, the old file reads, failed attempts and test output all ride along. Run /clear between unrelated tasks.
The same goes for corrections. If you’ve corrected the agent twice on the same point, the context is full of failed approaches. Clear it and start again with a better first prompt that includes what you learned. A clean session with a better prompt usually beats a long session with accumulated corrections.
2. Point at files, don’t paste them
Pasting a file into the prompt puts all of it into context, including the parts that don’t matter. Reference it instead with @ (for example @src/auth/session.ts) or name the path and let the agent read what it needs. For broad investigations, ask for a subagent: “use a subagent to investigate how token refresh works”. The subagent reads files in its own context window and returns only a summary.
For quick side questions that don’t need to stay in the conversation, Claude Code has /btw: the answer never enters the session history.
3. Keep standing instructions short
CLAUDE.md is loaded into every session, so every line costs context every time. Keep it to what the agent can’t work out from the code: build and test commands, style rules that differ from defaults, project-specific gotchas. For each line, ask whether removing it would cause mistakes. If not, cut it.
Knowledge you need only sometimes belongs in a skill, which loads on demand, not in CLAUDE.md. A short file is also a file the agent actually follows: when rules get lost in a long one, they stop being applied.
4. Turn off tools the task doesn’t need
Every connected MCP server and every installed skill is listed to the model, whether the task uses it or not. In our own sessions, a median of 10 MCP servers were offered and 1 was used. Review them with /mcp, and switch off the ones this project doesn’t need with /mcp disable <server>. Uninstall skills you never call.
This is the habit that saves the most for the least effort, and it’s the one we automated: Xval Engine in XAgents is a small on-device model that gives Claude only the tools and skills a task needs. In our benchmark of 32 hard coding tasks, full tool routing (arriving in v0.4.1) cut cost per task by 15–20% with the same success rate. Long sessions save less, as the Xval page explains.
5. Before you stop, write a three-line handoff
Compaction is lossy, and so is your memory of yesterday. Before you end a session, ask the agent for three lines:
Done: session refresh moved to middleware; tests pass.
Next: remove the old refresh call in api/client.ts.
Gotchas: staging tokens expire in 5 min, not 60.Save it in the repo or in the session itself. Next time, the new session starts warm from three lines instead of a long replay. It also makes a better /compact: pass it as the instructions, for example /compact keep the done/next/gotchas list and the test command. You can make that permanent in CLAUDE.md with a line such as “When compacting, always keep the list of modified files and the test commands.”
When to compact, and when to clear
- Same task, long history:
/compactwith focus instructions, at a natural break rather than mid-change. - New, unrelated task:
/clear. Nothing from the old task helps. - Wrong turn: press Esc twice or run
/rewindto go back to an earlier point instead of arguing forward.
Claude Code also compacts automatically when you approach the limit. Doing it yourself at a clean break means you choose what survives.
The five habits
- One task per session; clear between unrelated tasks.
- Point at files instead of pasting them; send research to a subagent.
- Keep
CLAUDE.mdshort; move occasional knowledge into skills. - Switch off MCP servers and skills the task doesn’t need.
- End every session with a three-line handoff: done, next, gotchas.
XAgents runs your Claude Code and Codex agents side by side on your Mac, and Xval Engine keeps their context clean. Join the waitlist and we’ll email you when your invite is ready.