Context Engineering
Claude Code techniques for a lean session: the context cost of MCP servers, priming over a growing CLAUDE.md, fresh-agent handoffs, compact versus clear.
Written by
-
Benedikt Stemmildt Founder & Co-CEO
Updated:
Tools 4
Our position. We treat context hygiene as a habit, not a setting: start bare metal (opens in a new tab), load only what the task in front of you needs, and watch the context fill like a build status. Research in one window, then implement from the written plan in a fresh one.
The context window holds everything the agent sees: the system prompt, CLAUDE.md, MCP tool definitions, file reads and the conversation itself. As it fills, the agent starts cutting corners to finish before its budget runs out (I Didn’t Know These Claude Code Rules (Big Mistake) (opens in a new tab)).
How does it differ from prompt engineering?
Prompt engineering polishes one request; context engineering manages everything around it, across many steps. An agent runs in a loop and pulls in new tokens on every turn, so the quality of its next step depends less on the wording of the first prompt than on what has accumulated in the window by then (Anthropic - Effective context engineering for AI agents (opens in a new tab)).
How do you keep the context window small?
Every context technique either reduces what the primary agent carries or delegates work to another window.
There are only two ways to manage your context window:
- Reduce – Keep unnecessary tokens out of your primary agent
- Delegate – Move work to sub-agents or background agents with their own context windows
Every context engineering technique maps to one or both of these.
“A focused agent is a performant agent.” – Elite Context Engineering with Claude Code (opens in a new tab)
How much context do MCP servers cost?
MCP servers loaded by default consume context before any work starts.
In the presenter’s own session, the MCP tools loaded by default took 24,100 tokens of Claude Code with Opus, 12% of the available context window (Elite Context Engineering with Claude Code (opens in a new tab)).
Fix:
- Delete your default
.mcp.jsonfile - Load MCP servers on demand:
claude --mcp-config path/to/specific-config.json - Use
--strict-mcp-configto prevent globals from loading - Verify with
/contextcommand
# Load only the specific MCP server you need:
claude --mcp-config .mcp-firecrawl-4k.json
# Verify:
/context
# Should show ~92% free on startup
“Be very conscious with the state going into your context window. There are many places to be wasteful as an engineer. The context window of your agents is not one of them.” – Elite Context Engineering with Claude Code (opens in a new tab)
How do you load only the MCP servers a session needs?
Split MCP servers into separate config files and pass only the ones a session needs.
Claude Code accepts several --mcp-config files in one session, so you can keep each MCP server in its own config file and combine only the ones you need (LATEST Claude Code Features & Tools (opens in a new tab)).
claude --mcp-config browser-automation.json --mcp-config supabase-readonly.json
Benefit: Cleaner than stuffing everything into one .mcp.json. Load only what you need per session. Separate read-only vs. write versions of the same service.
Should you prime context or grow CLAUDE.md?
Keep CLAUDE.md to universal essentials and load task context with a priming command.
Problem: CLAUDE.md is always loaded. It only grows. A 23,000-token CLAUDE.md consumes 10% of your Opus context window (Elite Context Engineering with Claude Code (opens in a new tab)).
“Large CLAUDE.md will impact performance. The CLAUDE.md file is incredible for one reason: it’s a reusable memory file that’s always loaded. Simultaneously, it’s terrible for the exact same reason.” – Elite Context Engineering with Claude Code (opens in a new tab)
Solution: Shrink CLAUDE.md to absolute universal essentials (~43 lines, ~350 tokens). Replace the rest with context priming via custom slash commands.
Context priming = using a dedicated reusable prompt (/prime) to set up your agent’s initial context specifically for the task type at hand.
Implementation:
.claude/commands/prime.md # General codebase understanding
.claude/commands/prime-cc.md # Prime for Claude Code file operations
.claude/commands/prime-feature.md # Prime for feature work
.claude/commands/prime-bug.md # Prime for bug investigation
Example prime command structure:
# Prime: General Codebase Understanding
## Purpose
Execute the workflow and report sections to understand the codebase and summarize your understanding.
## Workflow
1. Run: Read the README.md
2. Read: Review the directory structure
## Report
Summarize your understanding of the codebase architecture.
“Instead of relying on a static always-loaded memory file, we’re using context priming to gain full control over the initial context of our agents.” – Elite Context Engineering with Claude Code (opens in a new tab)
Rule: Your CLAUDE.md should only contain things you are 100% sure you want loaded 100% of the time.
How do you hand a full context to a fresh agent?
A hook-built log of tool calls lets a fresh agent replay the essential state of a session.
Use Claude Code hooks to create an append-only log of tool calls during a session. This “context bundle” can replay the essential state into a fresh agent (Elite Context Engineering with Claude Code (opens in a new tab)).
How it works:
- A
post-tool-usehook logs each tool call (tool name, input, output) to a session-specific bundle file - Bundle files are organized by
day/hour/session-id - When context explodes, start a new Claude Code instance
- Run
/load-bundle <path>to replay the essential reads/writes from the previous session - The new agent rebuilds an understanding of the work done so far without consuming all the tokens
Key detail: Bundles do NOT record every operation in full detail. They trim down to the essential replay: which files were read, what prompts were given, what was written. This prevents the bundle itself from overflowing the next agent’s context.
# .claude/commands/load-bundle.md
Load the context bundle at $ARGUMENTS and deduplicate read commands.
Create an understanding of the work done up till this point.
Why plan and implement in separate context windows?
Spend one context window on planning and start a fresh one for implementation.
Use a dedicated first context window for planning/research and a separate fresh context window for implementation.
Steps:
- Open Claude Code, describe the task, tell it to fully map out and plan (spend tokens on research)
- Have it save the plan to a markdown file
- Open a new context window
- Paste the plan file path and tell it to implement
“Use a different prompt for the very first context window of a major thing that you are doing. First context window for planning, separate context windows to actually implement.” – I Didn’t Know These Claude Code Rules (Big Mistake) (opens in a new tab)
Why this works: The planning context consumes tokens on exploration. The implementation context starts fresh with a focused plan, maximizing quality.
How do you stop the agent cutting corners near the limit?
Tell the agent that compaction handles the overflow, so it stops rushing to finish.
Claude Code starts cutting corners as it approaches its context window limit. You can counter this.
Prompt to add (system prompt or inline):
Your context window will be automatically compacted as it approaches its limit,
which allows you to continue working infinitely from where it left off.
Therefore, do not stop tasks early due to token budget concerns.
As you approach your token budget limit, save your progress to state memory
and continue working systematically until the task is complete.
“The way Claude Code works is that once it approaches its context window limit, it starts cutting corners. It’s thinking ‘I need to complete this before my token allocation runs out.’ So it’s optimizing for finishing the task.” – I Didn’t Know These Claude Code Rules (Big Mistake) (opens in a new tab)
Should you compact or clear the context?
Saving progress to a file and clearing the window beats compacting it.
Old approach: Compact the window, add instructions to track state. Better approach: Save progress to a to-do/progress file, clear the context, reference the file.
“When in doubt, clear it out.” – I Didn’t Know These Claude Code Rules (Big Mistake) (opens in a new tab)
Related
- Claude Code: the agent design that makes context the main lever.
- Prompt Engineering: how to write the priming commands and plans these techniques rely on.
- Context and output interfaces: measured startup costs, compaction trade-offs and CLAUDE.md limits.
- Memory and Context Engineering: the same discipline beyond one tool, agent memory included.
- Just-in-time retrieval: why loading on demand beats loading everything up front.
Resources
Articles
- Context Engineering for Coding Agents (opens in a new tab) - Article in the Exploring Gen AI series on context engineering for coding agents and the configuration options they offer.
- Effective context engineering for AI agents (opens in a new tab) - Anthropic engineering article on curating what accumulates in an agent’s context window across turns, beyond the wording of the prompt.
Talks and videos
- Elite Context Engineering with Claude Code (opens in a new tab) - Video on reducing and delegating context in Claude Code, showing default MCP tools taking 12 percent of the window in the presenter’s own session.
- I Didn’t Know These Claude Code Rules (Big Mistake) (opens in a new tab) - Video listing Claude Code rules, including how an agent starts cutting corners as its context window fills.
- You Need To Be Using These LATEST Claude Code Features & Tools (opens in a new tab) - Video roundup of Claude Code features, showing per-file MCP configs.