It is natural to assume a coding agent gets expensive when the model thinks hard. In our experience it gets expensive, and slow, when the same large pile of context is loaded again on every turn. The reasoning is the smaller part. The reloading is the bulk of it.
That changes what a good setup looks like. Most of it is about what gets read, which model reads it, and how often it is read again. Below are seven steps in the order we would build them, each with a short reason and the config for both tools. Every number here comes from our own work and our own cost model. It is one team's measurement, not a benchmark.
1. Pick a Model per Role
01 · Prices · October 2026 list
Cheap model to read, stronger model to judge
Reading is the largest share of an agent's day: searching files, scanning logs, summarising what it found. None of it needs the strongest model. Judgement does, such as design calls, security reasoning and the final integration check. So assign models by role instead of running everything on one.
The price gap that makes this worth doing
- ~1/20Haiku 5.5 input cost relative to Sonnet 5.5 inputList prices, October 2026
- ~1/40Haiku 5.5 input cost relative to Opus 5.5 inputList prices, October 2026
Set a sensible default in each tool, then pin specific roles in step 3. The model names below are the ones in this note; swap in your own as the lineup changes.
Claude Code
// ~/.claude/settings.json
{
"model": "sonnet"
}Codex
# ~/.codex/config.toml model = "your-default-model"
2. Keep the Always-Loaded Instructions Small
02 · The file every session pays for
Whatever is always loaded is paid for on every turn
The instruction file is read at the start of every session and carried along after that. Each extra line is a small, permanent tax. We trimmed ours from 273 lines to about 100. Before the trim, our own instruction layer made up about 22,000 of roughly 50,000 starting tokens in a session. That is close to half the context gone before any work began.
Both tools give you a ceiling to work within, and the sensible target sits well under it.
- Codex. It stops reading AGENTS.md at 32 KiB by default. The limit is the
project_doc_max_bytessetting. - Claude Code. Its docs advise keeping each CLAUDE.md under 200 lines.
- Skills. Move step-by-step procedures out of the always-loaded file and into skills, which load when needed. The skill list itself is capped at about 2% of the context window by default in both tools.
Claude Code
# CLAUDE.md (short on purpose) - Read before editing. Re-read after a compaction. - Run the tests and show the output before saying done. - Procedures live in skills; load one when the task needs it. - Ask before anything that touches production.
Codex
# AGENTS.md (same rules, same size) - Read before editing. Re-read after a compaction. - Run the tests and show the output before saying done. - Procedures live in skills; load one when the task needs it. - Ask before anything that touches production.
What the trim looked like
- 273 → ~100lines in the always-loaded fileAuthor's own setup
- ~22,000of roughly 50,000 starting tokens were instructions, before the trimAuthor's own measurement
3. Add Role Agents, Each Pinned to a Model
03 · A few roles, one writer
Pin the model in the agent, not in your head
Keep the roster short. A few role agents is enough, each pinned to a single model, with exactly one of them allowed to write. A reader that searches and summarises runs on the cheap model. Planning and hard design go to the strongest. Because only one role writes, you are never untangling two agents that edited the same file.
Claude Code
# .claude/agents/reader.md --- name: reader description: Search, read and summarise. Never edits files. model: haiku tools: Read, Grep, Glob --- Find what was asked for and return a short summary with file paths. Do not change anything.
Codex
# .codex/agents/reader.toml name = "reader" description = "Search, read and summarise. Never edits files." model = "your-cheap-model" sandbox_mode = "read-only" developer_instructions = "Find what was asked for and return a short summary with file paths. Do not change anything."
4. Route Work by Lanes
04 · Fast by default, gated when it matters
Most work should take the short road
Not every task deserves the same ceremony. We use three lanes. The Fast lane is the default: read, edit, test, one review, done. The Heavy lane is gated and opens only for work with real blast radius, such as a database migration, auth or payments. The Planning lane is for design questions the code cannot answer, before anything is built.
The temptation is to push everything through the heaviest path to be safe. We tried it. Forcing every task through a mandatory agent chain made delivery about ten times slower and raised compactions from about 10 a week to 251. Safety that costs that much stops being safety and becomes a tax on everything.
What forcing every task through the chain did
- ~10×slower deliveryAuthor's own measurement
- 10 → 251compactions per weekAuthor's own measurement
5. Add Only the Hooks That Pay
05 · An audit of our own guards
Every guard you add is one more thing to maintain
Hooks are tempting because each one feels like free protection. They are not free. An audit of our own setup tied an over-built guard layer to 31% of the quality problems we measured. That layer had 21 guard hooks, and we have since removed it.
The one hook we would add early is a compaction hand-off: when the context is about to be compacted, write down where the work stands so the next stretch can pick it up. Beyond that, be sparing, and add a hook only after a specific failure justifies it.
Claude Code
// .claude/settings.json
{
"hooks": {
"PreCompact": [
{
"hooks": [
{ "type": "command", "command": ".claude/hooks/save-state.sh" }
]
}
]
}
}The hook calls a small script that appends the state to a file.
# .claude/hooks/save-state.sh #!/bin/sh # Append the current state to a file the next stretch will read. printf 'Compaction at %s\n' "$(date -u +%FT%TZ)" >> .claude/state.md
Codex
Codex has its own hooks mechanism, covered in the Codex hooks reference in the sources. Wire the same hand-off script to its compaction event, and keep the script itself identical across both tools.
The cost of an over-built guard layer
- 31%of measured quality problems tied to the guard layerAuthor's own audit; 21 guard hooks, later removed
6. Control Context and Compaction
06 · Where the waiting is decided
Clear between tasks, compact on purpose, hold the model steady
- Clear between unrelated tasks. A new task should not drag the last one's history along.
- Use targeted compaction. Tell the tool what to keep, so the summary holds what matters instead of whatever fit.
- Avoid mid-task model switches. Changing model partway through a task disrupts the steady run of cheap cache reads the task had built up.
Each tool has one setting for when automatic compaction fires: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE in Claude Code and model_auto_compact_token_limit in Codex. The values below are illustrations; tune them to your own sessions.
Claude Code
// ~/.claude/settings.json
{
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "70"
}
}Codex
# ~/.codex/config.toml model_auto_compact_token_limit = 150000 project_doc_max_bytes = 32768
One timing detail shapes how you work. The prompt cache lasts one hour on a Claude subscription, within plan usage, and five minutes on an API key. Plan your breaks around that window.
7. Check Cost Once a Week
07 · Author's own work · Anthropic pricing, checked 2026-10-11
Cache reads dominate the volume, not the whole bill
Look at the numbers once a week, not every day. In one week of our own work, about 97.6% of all tokens were cache reads. That sounds like the whole story, but it is not, because a cache read is cheap per token. Volume and cost are different things.
One week of the author's own work
- 97.6%of that week's tokens were cache readsAuthor's own measurement
- 0.05×cache read price relative to uncached inputSonnet 5.5 list ratio, checked 2026-10-11
Our cost model uses the Sonnet 5.5 list-price ratios, relative to uncached input: cache read 0.05×, cache write 1.25×, output 5×. Run three presets through it and you get a cost index. The index is relative, so only the shape matters.
Read it as a ranking of habits. Loading heavy instructions adds about a third. Letting one session run long costs more than four times the lean baseline, because the context keeps growing and every later turn re-reads all of it.
Cache reads dominate token volume, but not all of the cost.Lovenish Singh
The Setup in Seven Lines
- 1. Match the model to the role: cheap to read, strong to judge.
- 2. Keep the always-loaded file short and move procedures into skills.
- 3. Add a few role agents, each pinned to one model, with one writer.
- 4. Default to the Fast lane; gate Heavy and Planning.
- 5. Add a compaction hand-off hook and little else.
- 6. Clear between tasks, compact on purpose, keep the model steady.
- 7. Check cost once a week.
Design what gets read. The thinking takes care of itself.
Sources
- https://code.claude.com/docs/en/model-config,Claude Code: model configuration
- https://code.claude.com/docs/en/memory,Claude Code: memory (CLAUDE.md)
- https://code.claude.com/docs/en/skills,Claude Code: skills
- https://code.claude.com/docs/en/sub-agents,Claude Code: subagents
- https://code.claude.com/docs/en/hooks,Claude Code: hooks
- https://code.claude.com/docs/en/costs,Claude Code: costs
- https://learn.chatgpt.com/docs/config,Codex: config reference
- https://learn.chatgpt.com/codex/hooks,Codex: hooks
- https://www.anthropic.com/pricing,Anthropic pricing (checked 2026-10-11)
Context is the cost. Design what gets read.
The same idea runs through how we build piMonk: agents do the work against context that people keep tight and current. Read the engineering view, or see the apps this thinking produced.