Skip to content

Elite Context Engineering

Agentic Handbook

Central thesis: A focused agent is a performant agent — context engineering is the disciplined practice of measuring and managing the precious, limited context window so your agents hit their performance sweet spot at scale.

Overview

Context is the single most important in-agent leverage point. Every agent has a sweet spot — a range of context where it performs to its maximum capability for the task at hand. As you scale from a handful of runs to hundreds or thousands of agent executions, hitting that sweet spot consistently is what separates real agentic engineering from vibe coding.

Adding the right context is the easy part. The real skill is search and destroy: finding context agentically, then removing and delegating it so it never rots or bloats the window. Boiled all the way down, there are only two ways to manage a context window — R and D: Reduce and Delegate. Every technique in this lesson fits into one or both buckets.

The context window is a precious, renewable, but temporal resource. It's ephemeral — it resets. Whatever determines your success must be measured so it can be improved, which is why measuring context is the foundation everything else builds on. If you aren't actively watching the state of your agent's context, you're only able to grab the lowest-hanging (and most saturated) fruit.

This lesson walks 12 concrete techniques across four levels — beginner, intermediate, advanced, and agentic — each one an application of R&D. Pick one, pick a few; every technique you adopt buys back tokens, time, and the accuracy of your out-of-loop agents.

Key concepts

The R&D Framework (Reduce / Delegate)

There are exactly two moves for managing a context window. Reduce keeps unnecessary context out of your primary agent (delete the .mcp.json, shrink CLAUDE.md, control output styles, clear-and-prime). Delegate pushes context off your primary agent onto sub-agents or other primary agents (sub-agent delegation, planner/builder split, background agents, agent experts). Every technique below is one or both.

flowchart TD
    A[Context Window Problem] --> B{R&D Framework}
    B -->|Reduce| C[Keep context OUT of primary agent]
    B -->|Delegate| D[Push context to other agents]
    C --> C1[Prune MCP servers]
    C --> C2[Shrink CLAUDE.md / prime instead]
    C --> C3[Output styles]
    C --> C4[Clear + prime, not compact]
    D --> D1[Sub-agents]
    D --> D2[Planner / builder split]
    D --> D3[Background primary agents]
    D --> D4[Agent experts]

The 12 techniques across 4 levels

Beginner (measure & reduce)

  1. Measure your context — use /context and an in-IDE tokenizer so you always know what's in the window and what a file will cost.
  2. Prune MCP servers — don't preload a default .mcp.json; MCP tools alone can eat 24K tokens (~10% of a 200K window). Load servers by hand only when needed.
  3. Context priming over CLAUDE.md — replace a bloated always-on memory file with task-specific prime commands.

Intermediate (control output & delegate) 4. Output styles — hot-swap the output-style block in the system prompt to cap response tokens (output tokens cost 3–5× input). 5. Sub-agents — partially fork the context window; sub-agents run on system prompts and report back to the primary, keeping their token load off it. 6. Planner / builder split — one agent plans, a second builds from the plan with a clean window.

Advanced (own the window) 7. Clear + prime, not compact — avoid /compact (you never know what survived); /clear then re-prime so you always know your state. 8. Context bundles — an append-only log of reads/writes (via hooks) used to remount a fresh agent after the window explodes. 9. One agent, one purpose — the ultimate reduction; design a pipeline of single-purpose agents.

Agentic (build the system that builds the system) 10. System prompt control--append-system-prompt (or full override via SDK) to steer behavior at the foundational level; runs in print mode. 11. Primary multi-agent delegation — fire off top-level primary agents (background CLI instances) from your in-loop agent. 12. Agent experts — specialized plan→build→improve agents that own an area of the codebase and auto-update their own knowledge.

Context priming vs CLAUDE.md

CLAUDE.md is a reusable memory file that's always loaded — its strength and its curse. It only grows, eventually filling the window with irrelevant or even contradictory context. Context priming uses a dedicated reusable prompt (a custom slash command like /prime) to set up the initial window for the task type at hand. Priming is dynamic and controllable; you can build prime-bug, prime-feature, prime-cc, and stack them. Keep CLAUDE.md to only the absolute universal essentials you are 100% sure you want loaded 100% of the time.

Output styles

Output styles hot-swap the output-style block in Claude Code's system prompt. A one-word "done" style can drop a routine success response from ~150 output tokens to ~2 — a ~99% reduction on that element. You still can't avoid tokens spent writing files, but you control the chatter Claude sends back to you. Keep a sensible middle ground for questions and errors.

Context bundles

Using Claude Code hooks, you log a trail of tool calls (reads, writes, prompts) into an append-only bundle keyed by day, hour, and session ID. When an agent's window explodes, a fresh agent runs /load-bundle <path>, deduplicates the reads, and reconstructs ~70% of the prior agent's understanding without replaying every detail. Use selectively so you don't overflow the next agent.

Agent experts

The capstone pattern. You build a specialized three-step expert — plan → build → improve — that is an expert at one part of the codebase. The planner produces a spec then discards its window; the builder implements from the spec; the improve/meta step reads the git diff and updates the plan and build prompts with what it learned. The result is a self-documenting, self-improving expert that remembers areas of the codebase you no longer will.

How to apply it

  1. Measure first. Run /context on boot. Install an IDE tokenizer. Know your startup cost before you prompt.
  2. Delete the default .mcp.json. Load MCP servers explicitly with --mcp-config (plus --strict-mcp-config to ignore globals) only when a task needs them.
  3. Shrink CLAUDE.md to universal essentials, and build /prime commands per area of focus instead.
  4. Set a concise output style via a settings file for out-of-loop and success-only runs.
  5. Delegate scrapes and fan-out work to sub-agents so heavy token loads never touch the primary window.
  6. Split planning from building — plan with a strong model, then hand the spec to a fresh builder.
  7. Stop using /compact. When the window fills, /clear and re-prime; if a single agent overflows 200K, chop the task up.
  8. Add context-bundle hooks so you can remount agents after a blowup.
  9. Design pipelines of single-purpose agents — plan the problem first (no tech), then plan the agent delegation (the ADW).
  10. When nothing else works, modify the system prompt (--append-system-prompt, print mode) or build agent experts for your domain.

Commands & conventions

Command / flagPurpose
/contextInspect everything in the agent's context window; your #1 measurement tool
claude --mcp-config <file>Load only the MCP servers you actually need
--strict-mcp-configIgnore global MCP config, use only what you pass
/prime, /prime-ccReusable context-priming commands per area of focus
/build, /quick-planBuilder and planner reusable prompts (planner→builder split)
/clear then /primeReset and re-prime instead of /compact
/load-ai-docsKick off sub-agents to scrape docs off the primary window
/load-bundle <path>Remount a fresh agent from a context bundle
/backgroundFire a background primary Claude Code instance
/expertsInvoke a plan→build→improve agent expert

System-prompt steering (print / programmatic mode only):

bash
# Append instructions to Claude Code's system prompt (out-of-loop, -p print mode)
claude --dangerously-skip-permissions -p \
  --append-system-prompt "IMPORTANT: When using the Read tool, always read in \
increments of 100 lines. If you have enough to accomplish the request, stop \
reading and proceed. Prefix your final message with ✓ for success or ✗ for failure." \
  "What is CLAUDE.large.md for?"

Directory conventions: /.claude/commands/ for reusable prompts (with an experts/ subdir for expert prompts), /agents/ as an agentic-layer output directory holding context-bundles/, background/, and hook-logs/ keyed by session ID.

Key takeaways

  • There are only two ways to manage a context window: Reduce and Delegate. Everything else is a variation.
  • What gets measured gets managed/context and a tokenizer are non-negotiable.
  • MCP servers and a bloated CLAUDE.md are the two most common silent token drains; prune both.
  • Prefer context priming (dynamic, task-specific) over an always-on memory file.
  • Output tokens cost 3–5× input tokens; control them with output styles.
  • Own your context window — avoid /compact; clear, prime, and rebuild so you always know your state.
  • The endgame is one agent, one purpose, composed into pipelines (ADWs) and specialized agent experts.
  • It's not about saving tokens, it's about spending them properly — so you don't waste time correcting agent mistakes.

Notable quotes

"A focused engineer is a performant engineer and a focused agent is a performant agent."

"Search and destroy is the real skill in context engineering."

"When you get to advanced agentic coding, it's time to stop guessing and start knowing."

"It's not necessarily about saving tokens. It's about spending them properly."