Question

Claude Code runs out of context halfway through a refactor

Solved · 346 viewsasked by leo_prompts

Big refactor: rename a concept across 60 files. Around file 35 it starts forgetting the new name and reintroduces the old one.

What I’ve tried

Asked it to "remember the plan". It summarizes and then drifts anyway.

Comment

2 answers

Marked as helpful by the asker
felix_codes

Do not do 60 files in one session. Make the machine do the boring part and the model the judgement:

  1. grep -rl OldName src/ > files.txt, split into batches of 10.
  2. New session per batch. First message: the rule ("OldName → NewName, also in tests and docs") plus the 10 file names.
  3. Commit per batch. If a batch drifts, git checkout . and redo that batch.

A fresh session with a short, exact instruction beats a long session with a fading plan.

Comment
Same pattern works for renames across a monorepo. I add a grep for the old name as the last step of every batch, so drift shows up before the commit. sergio_ruiz
leo_prompts

Marking this one. The batch-per-session approach worked: 6 sessions, zero drift.

Comment