Skip to main content

Mid-refactor, I lost track of which files I'd already changed

PhaseImplementationRolesEngineer · ArchitectSeverityHighApplies toAll coding agentsEvidenceOfficial docs

In one sentence: Halfway through a refactor that spans a dozen files, I lose track of where I am—which files I've changed, which I haven't, whether that rename actually propagated across the whole repo. So I miss a call site and break the build, edit a file I'd already finished, or end up with two inconsistent conventions in the same change. Don't make me use my memory as the to-do list.

Symptom​

You ask me to rename a heavily used function, getUser(), to fetchUser(), and while I'm at it switch its return type from a bare object to Result<User>. This is a textbook cross-file refactor: the call sites are scattered across a dozen files, and every one of them has to change too.

I start working through them one by one. Around the seventh or eighth file, you'll see these symptoms:

  • I miss two more call sites still sitting under legacy/, and the build breaks right there.
  • I open services/auth.ts and edit it again—even though I already changed it ten minutes ago.
  • The first five files use Result<User>; somewhere along the way the last five quietly slid back to User | null—two return conventions inside a single refactor.

Why this happens​

Cross-file refactoring needs checkable state: affected callers, completed changes, remaining verification, and compatibility boundaries. Reporting from conversational impressions can miss sites or repeat edits.

Agents can use checklists, task tools, and persistent files; it is wrong to say I have no stable memory at all. Current Claude Code reloads some rules, plans, memory, and files after compaction, so compaction does not necessarily erase every earlier decision. What survives depends on version and loading mechanism.

External records still need reconciliation with code. Search covers matching forms and can miss aliases, dynamic access, string protocols, generated code, and external callers. Zero hits does not establish a completed behavior migration.

Consequences​

  • Missed edits: a call site doesn't get updated, and the build breaks—or worse, it compiles but the behavior changed, hiding until runtime.
  • Re-edits: I edit a file I'd already finished, possibly turning something correct back into something wrong, wasting your review.
  • Inconsistency: two forms (Result<User> and User | null) end up in the same refactor—fresh technical debt buried inside the cleanup.
  • The check makes it worse: you ask me to "see what's still unchanged," and I answer from memory—but memory is the source of the error, so you get a progress report you can't trust.

What to do instead​

  1. Discover first and maintain a checklist. Find definitions, references, string contracts, and known external callers; record unknown scope. Keep disk/task records reconciled with the actual diff.
  2. Use complete logical steps. A type change may require several files to change together, so do not demand each file compile independently. Verify each coherent step and commit under existing authorization and project rules.
  3. Combine search with behavior verification. Classify remaining old-symbol hits, and inspect aliases, dynamic callers, generated artifacts, and external compatibility. Run checks relevant to the change.
  4. Reconcile current state on resumption. Read the checklist, diff, and real files before proceeding so completed work is not repeated.

Example​

Before: I edit a dozen call sites and report completion from memory, missing legacy/ and dynamic entry points.

After:

Me: Search getUser definitions, calls, and exports; record dynamic/external entry points.
Migrate getUser → fetchUser and Result<User> in coherent logical steps.
Change a group of files together where necessary, then run relevant type/behavior checks.
Finally classify old-name remnants and compatibility entries, reconcile the checklist,
and report actual check output.

Zero search hits are one piece of evidence; success, error, and compatibility behavior of the new return type still require validation.

Version notes​

Applicable versions

Checked current context/compaction and best-practice documentation on 2026-10-29. Retained checklists, logical steps, and residual searches, without requiring a commit per file or treating zero hits as sufficient. Each step should be a coherent verifiable change; choose type checks, behavior regression, and compatibility review according to risk.

Further reading and sources​