Full picture: Estimate what your project costs →
Estimate · Refactors
How much does an AI refactor cost
Refactoring a 50,000-line codebase costs about $92 in tokens on Claude Sonnet 5.5. A 10,000-line project is about $5.49, and 200,000 lines about $413. Most of it is the agent reading your code.
- $5.4910K lines
- $9250K lines
- $413200K lines
- 30%share of code changed
Checked (UTC) Anthropic's API prices ↗
3 codebase sizes, priced per model
Typical case. The estimator assumes a refactor touches 30% of the code. Tap a row to change it.
| Project | Claude Haiku 5.5 | Claude Sonnet 5.5 | GPT-6.2 Sol | Claude Opus 5.5 |
|---|---|---|---|---|
| Small codebase10,000 lines | $0.27 | $5.49 | $4.07 | $11 |
| Medium codebase50,000 lines | $23 | $92 | $68 | $185 |
| Large codebase200,000 lines | $103 | $413 | $306 | $826 |
Cut a refactor's bill
- 1Refactor one module at a time
A smaller working set means less code re-read on every turn.
- 2Point the agent at the files
Name the folders to touch and exclude the rest, so it doesn't explore.
- 3Keep sessions warm
Prompt caching makes re-read code cost a tenth or less of normal input.
- 4Run tests between steps
Catching a break early avoids the expensive retry loops in the High column.
The estimator caps each turn at 150,000 tokens of context. Past that, agents summarise or drop code, and real bills vary more.
Sources: Anthropic API pricing ↗ · Anthropic prompt caching ↗
AI refactor cost FAQ
How much does it cost to refactor code with AI?
In our estimate, an agent that reworks 30% of a 50,000-line codebase uses about $92 of tokens on Claude Sonnet 5.5, from $46 with a careful plan to $206 with lots of retries.
Why is a refactor more expensive than writing new code?
The agent has to read existing code before it can change it, and a big codebase fills the context on every turn. Input tokens, not output, make up most of a refactor's bill.
Is a subscription better than an API key for a big refactor?
At $413 for 200,000 lines on Claude Sonnet 5.5, a refactor that size costs more than most monthly plans. A flat plan such as Claude Max can work out cheaper, but its limits may stretch the job over several 5-hour windows.
Which model is cheapest for a refactor?
Claude Haiku 5.5: about $23 for the 50,000-line job. Check its work closely, since cheaper models can miss cross-file changes.