AI Lab30 November 20267 min read

Claude Code changes tested: 0 of 16 runs touched code I didn't ask for

One square per run. Plain request: 6 of 8 runs added an extra nobody asked for. With the sentence Only change what is needed, do not touch anything else: 0 of 8. 0 of 16 touched code outside the request, all 16 correct.
One square per run. Orange means the run added something nobody asked for. Zero runs touched code outside the named function.

A post on X with about 14,000 likes said Claude Code added code the author never asked for. It was a security audit of a home app, done by another AI, which pointed to a line that a Claude session had put into a commit. I can't check that case. It did leave me with a question I can check: how often does Claude Code change things you did not ask it to change?

Many guides and bug reports say it happens. I found GitHub issues with titles like "agent makes unrequested out-of-scope changes" and several blog posts with a rule to add to your prompt. I found no count. So I made one.

How often does Claude Code change code I didn't ask for?

In this test: never, outside the function I named. Here is how I tested it. I fixed the rules before any run.

What did the 16 Claude Code changes look like?

Every run was correct. Every run touched only the file I named, apart from two new tests. None of the 16 edited a trap: no tidied imports, no fixed except:, no renamed variables, no refactor of the duplicated logic, no README change.

TaskPromptLines added (run 1 / run 2)Extras nobody asked for
list --minplain4 / 4help text on the option, in both runs
list --minonly change what is needed3 / 3none
Refunds in monthly_totalplain9 / 1one run added a new unit test
Refunds in monthly_totalonly change what is needed1 / 1none
Date formatplain5 / 2one run added a fallback for dates it can't read
Date formatonly change what is needed2 / 2none
New top_categoryplain10 / 19docstring in both runs, plus a new unit test in one
New top_categoryonly change what is needed9 / 10none
Terminal output of score.py for all 16 runs: task, prompt, correct, other files changed, lines outside the request, tests added, lines added and the extra.
The scoring output for all 16 runs. Every run shows 0 other files and 0 lines outside the request.

The refund fix is the clearest case. The whole change is deleting and e["amount"] > 0. Three of four runs did exactly that, one line. The fourth wrote a 9-line diff because it also added a test. All four were right.

Did one sentence really remove the extras?

In these 8 runs, yes. The plain prompts added extras in 6 of 8 runs. The prompts with "Only change what is needed. Do not touch anything else." added extras in 0 of 8. They also wrote less code: 31 added lines in total against 54, about 43% less. Cost did not move: the plain runs averaged 56,929 tokens and the strict runs 56,694, a 0.4% gap.

Most extras were small and many would be welcome. A docstring or a unit test is often what a reviewer asks for. The point is not that they are bad. The point is that you did not ask, so the diff you must review is bigger than the change you wanted. One run also added behaviour: a fallback that shows a date as-is when it can't be read. That is a design choice you did not make.

What this test does not show

What should I do about it?

If you want to know what a small change costs in tokens, I measured that too in the token usage test on small edits. A second test looks at how the wording of a prompt changes the code Claude Code writes.

FAQ

Does Claude Code make changes I didn't ask for?

In this test of 16 small runs, it never edited code outside the function I named. It did add small extras, like help text, a docstring or a unit test, in 6 of 8 plain requests. With "Only change what is needed. Do not touch anything else." added, that fell to 0 of 8.

How do I see Claude Code changes?

Run git diff --stat to list the changed files and git diff to read them. Do it before you accept or commit anything. A short check shows both extra files and extra lines.

How do I stop Claude Code from changing unrelated code?

Name the file and function, and add a plain rule such as "Only change what is needed for this. Do not touch anything else." In this test that rule gave the smallest diffs, with about 43% fewer added lines.

How do I undo Claude Code changes?

If the project is in Git, use git restore <file> to drop the changes to one file, or git diff first to keep only the parts you want. Commit before a big task so you always have a clean point to return to.

Sources

TH

Written by Tabish Hassan, a software developer in Pakistan. 4+ years of production React and TypeScript, 75 iOS apps on the App Store. The tests on this blog run on my own Mac, with the method and limits shown.

Found a mistake or got different numbers? Email hello@tabishapps.com. Published 2026-11-30.