Cost, model choice and troubleshooting
Pick the right model per task, see where tokens actually go, and diagnose the two failure modes that waste the most time: loops and confident bad edits.
Model choice and effort
| Task | Model | Reasoning |
|---|---|---|
| Renames, formatting, mechanical edits | Small / fast | Pattern following; no judgement needed |
| Feature work in a known codebase | Mid | The everyday default |
| Unfamiliar code, tricky debugging | Large | Needs to hold more of the system at once |
| Search and audit subagents | Small | High volume, low value per token |
| Code review | Mid to large | Judgement about correctness is the whole job |
# per session
/model # switch interactively
/cost # usage for this session
# per invocation
claude -p "rename getUser to fetchUser everywhere" --model haiku
claude --model opus
# from the environment
export ANTHROPIC_MODEL=claude-sonnet-4-5- Thinking budget is triggered by phrasing - words like 'think', 'think hard', 'ultrathink' request progressively more internal reasoning. They are useful for planning and expensive to leave on for edits.
- Report usage with
/costper model, not in aggregate; a small model used everywhere usually beats a large model used everywhere except for genuinely hard tasks. - Cache-friendly sessions re-send a stable prefix, so avoid churning instruction files between turns.
Diagnosing loops and thrashing
- Repeated identical tool calls. The agent is not getting new information. Give it the missing fact directly instead of asking again.
- Re-reading the same files. Context pressure.
/clearand restate the goal with the specific paths. - Tests failing the same way after three fixes. The session is anchored to a wrong diagnosis. Start fresh with the failing output pasted in.
- Edits that break unrelated tests. The task was too broad. Split it and give one file or one module per session.
- Silent no-ops. Often a permission prompt was declined or a hook exited non-zero. Check
/hooksand the transcript before blaming the model.
# give evidence, not opinions
npm test 2>&1 | tail -60 > /tmp/fail.txt
claude -p "Here is the real failure output. Read /tmp/fail.txt and the handler it names, then state the root cause before changing anything."
# cap the blast radius of an experiment
claude -p "make the failing test in src/cart.test.ts pass without touching any other file" \
--max-turns 12💡
The single highest-value habit is to make the agent state its diagnosis before it edits. Asking 'what do you think is wrong, and what evidence supports it?' turns a silent wrong fix into a visible wrong assumption you can correct for a fraction of the cost.
Health checks and bad edits
claude doctor # installation, auth and environment health
claude --version
/status # account, model and workspace in a session
/doctor # same checks from inside a session| Symptom | Likely cause | First move |
|---|---|---|
| Agent ignores a rule | Instruction file edited mid-session | Restart, or restate the rule |
| Fabricated function names | Model has not read the module | Point it at the exact file |
| Edit reverted on next turn | Conflicting rules or a formatting hook | Check hooks and settings overlap |
| Everything is slow | Large model plus long history | Smaller model, /clear, smaller reads |
| Cost spiked | MCP tool definitions or long session | Remove unused servers, start a fresh session |
Keep the source of truth in version control. Before each session, commit or stash, so the worst case is git checkout -- . rather than an afternoon reconstructing what the agent changed.
FAQ
How do I know what a task will cost before running it?
You cannot know exactly, but you can bound it: cap
--max-turns, restrict tools, pick the smallest model that plausibly works, and check /cost after comparable tasks. Over a week you get a useful per-task estimate and a clear picture of the outliers.The agent keeps making the same wrong edit. What now?
Clear the session and restart with the failure output and the exact file pasted in, plus a statement of what must not change. A session that has already committed to a wrong explanation rarely recovers from it.
Related
Managing the context window and session hygiene A typical editing workflow
Last refreshed 2026-09-18.