Measuring agent context cost, and cutting it.

Guides

Every session starts with a fixed cost before you type anything, and that cost is paid again on every turn. Measuring it turns "the agent feels forgetful" into numbers you can cut.

What loads before your first prompt

  • Instruction files. CLAUDE.md files (personal, project and parent folders) for Claude Code, AGENTS.md files for Codex.
  • Auto memory. Claude Code loads the start of its memory index each session (the first 200 lines or 25KB).
  • Skill descriptions. Names and descriptions, not bodies.
  • Tool names. MCP tools add to the list the model carries.

Then the session itself grows: file reads, command output, your messages and the agent's replies.

Measure it

  • Live. Run /context in Claude Code for a breakdown by category, including which instruction and memory files loaded. /memory opens them.
  • Estimate the files. Characters divided by four is a workable token estimate for English text. The CommonRig scorer uses exactly this, summed per engine across the personal and project files that engine loads.
  • Score it. Paste a file into the free scorer or run rig doctor --lite from the free sample. Beyond size, it counts dated lines, retired markers, repeated lines, secret-shaped values and absolute home paths. Counts of memory and SKILL.md files are reported, but their contents are not scored.

Set a budget

A reasonable ceiling is about 3,500 estimated tokens per engine, roughly 14,000 characters. Claude Code's own memory guidance is to target under 200 lines per CLAUDE.md. Codex stops reading project files at 32 KiB by default, which is a limit, not a goal. The footprint score deducts one point per 250 estimated tokens past the budget, up to 30.

The cuts that pay most

  1. History and incident stories. Keep the lasting rule, move the story and date to a work log.
  2. Retired and repeated rules. Delete anything marked superseded or deprecated, and merge near-duplicates. The kit's fictional before-and-after example fell from about 2,067 estimated tokens to 350 this way.
  3. Procedures. Move release steps and recipes into skills that load on demand.
  4. Path-scoped rules. In Claude Code, rules in .claude/rules/ can be limited to matching files so they load only when relevant.
  5. Secrets and machine paths. They add size, risk and nothing the agent needs.

Keep the session small too

  • Run /clear between unrelated tasks; old conversation crowds out what you need next.
  • Run /compact with a focus before a long new task, so the summary keeps what you choose.
  • Send large reads and searches to a subagent. It uses its own context window and returns a summary.

Cutting is not the same as deleting rules that matter. Re-measure after each pass, keep the verify command and hard boundaries, and enforce the critical few with hooks so they do not depend on the model reading a long file. Why a long file gets ignored covers the symptoms.

Check your own files

Paste your CLAUDE.md or AGENTS.md into the free footprint scorer, or get the free sample and run rig doctor --lite locally. The hosted doctor check is A$0.50 a run and scores the whole setup, hooks included. The kit (A$10 once) has the rule source, generator, hooks and protocols these guides describe.

More guides