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

TaskModelReasoning
Renames, formatting, mechanical editsSmall / fastPattern following; no judgement needed
Feature work in a known codebaseMidThe everyday default
Unfamiliar code, tricky debuggingLargeNeeds to hold more of the system at once
Search and audit subagentsSmallHigh volume, low value per token
Code reviewMid to largeJudgement 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 /cost per 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. /clear and 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 /hooks and 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
SymptomLikely causeFirst move
Agent ignores a ruleInstruction file edited mid-sessionRestart, or restate the rule
Fabricated function namesModel has not read the modulePoint it at the exact file
Edit reverted on next turnConflicting rules or a formatting hookCheck hooks and settings overlap
Everything is slowLarge model plus long historySmaller model, /clear, smaller reads
Cost spikedMCP tool definitions or long sessionRemove 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.

Managing the context window and session hygiene A typical editing workflow

Last refreshed 2026-09-18.