DEV Community

Zac
Zac

Posted on

The scope creep problem in Claude Code (and the one rule that fixed it)

The scope creep problem in Claude Code (and the one rule that fixed it)

I spent weeks fighting scope creep before I found a rule that actually stopped it.

The symptom: I'd ask Claude Code to fix a specific bug, and it would fix the bug and also refactor the function, update the tests to match the new structure, rename a variable for clarity, and add a comment explaining the logic. All of it technically fine. None of it what I asked for.

The problem isn't that the agent is trying to help. It is. The problem is that "helping" in adjacent code means:

  1. Changes I didn't review before approving
  2. Diffs that are 5x larger than the actual fix
  3. Regressions introduced in code that was working fine
  4. Time spent reviewing work I didn't ask for

The one rule that fixed it

Never touch a file that isn't explicitly listed in the task. If you think a change is needed in another file, describe it and ask before making it.
Enter fullscreen mode Exit fullscreen mode

That's it. One rule. Results: diffs are smaller, reviews are faster, regressions dropped significantly.

The key phrase is "describe it and ask before making it." This isn't "never make adjacent changes" — sometimes they're genuinely needed. It's "tell me first." Now the agent flags the adjacent issue and I decide whether to scope it into the current task or make it a separate task.

Why this works better than trying to be less specific

I tried the opposite approach: giving the agent more context and hoping it would make better judgment calls. "Here's the full codebase, use your judgment about what needs to change."

This produced better individual decisions but more of them. The agent would identify real problems across 15 files and attempt to fix them all. The resulting session was hard to review and harder to verify.

The explicit file list is a forcing function. If I haven't listed a file, the agent stops and asks. Sometimes the answer is "you're right, add it to scope." Often the answer is "that's a separate task."

Practical implementation

In the task prompt:

Files in scope for this task:
- routes/auth.js
- middleware/validate.js
- tests/auth.test.js

If you identify a problem in any other file, describe it and stop. Don't fix it.
Enter fullscreen mode Exit fullscreen mode

That's the entire addition. Takes 30 seconds to write. Saves 30 minutes of review on sessions that would otherwise sprawl.


From running Claude Code on builtbyzac.com.

Top comments (0)