Estimate · Refactors

How much does an AI refactor cost

Quick answer

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.

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.

ProjectClaude Haiku 5.5Claude Sonnet 5.5GPT-6.2 SolClaude Opus 5.5Claude Sonnet 5.5 range
Small codebase10,000 lines$0.27$5.49$4.07$11$2.75 to $12
Medium codebase50,000 lines$23$92$68$185$46 to $206
Large codebase200,000 lines$103$413$306$826$207 to $923

Cut a refactor's bill

  1. 1
    Refactor one module at a time

    A smaller working set means less code re-read on every turn.

  2. 2
    Point the agent at the files

    Name the folders to touch and exclude the rest, so it doesn't explore.

  3. 3
    Keep sessions warm

    Prompt caching makes re-read code cost a tenth or less of normal input.

  4. 4
    Run tests between steps

    Catching a break early avoids the expensive retry loops in the High column.

Big codebases hit the context ceiling

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.