AgentReceipt

Retry loops: the most avoidable line on an agent bill

An agent that edits the same file and reruns the same failing test five times pays the full context price on every attempt. How to spot loops and stop them early.

Every attempt in a loop costs at least one full-context turn, often two (edit, then run the tests). On a 100k-token context, each extra round trip costs about $0.06 on Sonnet 4.6 and $0.10 on Opus 4.8 in cache reads alone, plus the output tokens of each rewrite and the new context it adds.

AgentReceipt counts a loop when the same file is edited, or the same test command run, three or more times with failures in between, and prices the turns after the second attempt.

How to fix it

  • After two failed attempts, stop and give the agent the exact error and the constraint it keeps missing.
  • Ask for a plan before code on unfamiliar parts of the codebase.
  • Take over the last mile by hand when the fix is obvious to you.

See it in your own session

Drop the session file below. Every step this applies to is flagged on the receipt with what it cost and what fixing it would have saved.

Itemize your own session

Drop a Claude Code or Codex log. It is parsed in your browser, and you get your real numbers instead of a model.

Drop a session log here

Claude Code ~/.claude/projects/…/*.jsonl, a Codex rollout ~/.codex/sessions/…/rollout-*.jsonl, or the claude-code-action execution file.

Parsed in your browser. Your prompts and code never leave this tab.