Claude Code Keeps Creating Extra Files (Summaries, Test Scripts): How to Stop It

Claude Code Keeps Creating Extra Files (Summaries, Test Scripts): How to Stop It

If Claude Code creates unnecessary files every time you ask for a small change, you are not alone. You ask for a quick fix, and you end up with a test_something.py, a CHANGES_SUMMARY.md or a NOTES.md sitting in your project that you never asked for.

The short answer: Claude makes these files when it wants a place to check or explain its work, and nothing tells it not to. Add a short “File rules” section to your project’s CLAUDE.md (no new files unless asked, check work inline or in /tmp, summaries go in the chat), then back it up with deny rules such as Edit(*SUMMARY*.md) in .claude/settings.json, which Claude Code enforces.

For anything that slips through, git status --short shows new files with ??, and git clean -n lists them before you remove them. We tested all of this in a real session below.

Browse all our Claude Code tutorials for more fixes and how-tos.

Tested with Claude Code v2.1.332 on macOS on November 29, 2026, plus one earlier run of the same prompt on November 28, 2026. Every run used a throwaway demo project called tip-calc: one small Python file, a README and a fresh Git repository.

We tested on macOS; the Windows and Linux steps follow Anthropic’s official instructions, and the files and rules work the same way there.

Quick Summary

FixWhat you doEnforced?Tested by us?
Scope the promptSay “edit tip.py only, no new files”No, one task onlyYes
CLAUDE.md file rulesAdd a short ## File rules sectionNo, guidanceYes
Deny rulesEdit(*SUMMARY*.md) in permissions.denyYesYes (Write and shell redirect)
PreToolUse hookA script that exits with code 2YesFrom the docs
Clean up leftoversgit status --short, git clean -n, git clean -fNot neededYes

Why Claude Code Creates Unnecessary Files

Claude Code works like a careful developer. When you ask it to verify a change, it often writes a small test script and runs it. When you ask it to document or summarize, it may decide a markdown file is the cleanest place to put that text.

Most of the time it cleans up after itself or keeps the check inline. Sometimes it decides the extra file is useful and leaves it as a bonus. That is the part that annoys people, because the file now shows up in Git, in pull requests and in your editor.

Here is what we saw. On November 28 we gave Claude Code this prompt in our demo project: “Add input checks to tip.py (no negative bills, at least 1 person). Verify it thoroughly and document the changes.”

Claude Code reply saying it added test_tip.py while adding input checks to tip.py
Our November 28 run: Claude added a new test_tip.py file we never asked for

Claude did the job well. It also added test_tip.py, a full unit test file, and kept it. A quick git status showed the new untracked file next to the two files we expected to change.

git status output in Claude Code showing ?? test_tip.py as a new untracked file
git status marks the extra file with ?? because Git has never seen it

Same prompt, different result

The next morning we ran the exact same prompt in a fresh copy of the project. This time Claude ran its checks inline and said it “left no test files behind.” Only tip.py and README.md changed.

Claude Code reply saying it ran checks inline and left no test files behind
Same prompt on November 29: Claude checked its work inline and kept no extra file

That is the real lesson. Whether you get a stray file depends on the run, so you can’t fix this by hoping. You fix it with rules that are always loaded and, where it matters, rules that Claude Code enforces.

Diagram showing how a verify or document request leads to leftover files when there are no file rules
Without file rules, a test or notes file can end up as a leftover in Git

Words in your prompt that invite extra files

  • “Verify it thoroughly” or “make sure it works”: Claude may write a test script.
  • “Document the changes” or “write up what you did”: Claude may create a markdown file.
  • “Give me a summary” on a long task: some runs put it in a file instead of the chat.
  • “Add tests” in a project with no test folder: a new test file is the correct result here, so expect it.

Fix 1: Tell Claude Exactly Which Files to Touch

The fastest fix is in the prompt itself. Name the file and say what you don’t want:

Add input checks to tip.py (no negative bills, at least 1 person).
Edit tip.py only. Do not create any new files.
Check your work with python3 -c and give me the summary here in chat.

This works for one request, but you have to remember it every time. If you want to see the plan before any file is written, start in plan mode with Shift+Tab, read the list of files Claude plans to create, and correct it before you approve.

Fix 2: Add File Rules to CLAUDE.md

A project CLAUDE.md loads at the start of every session, so rules you put there apply without retyping. If you are new to it, our CLAUDE.md guide covers the basics. This is the section we added to the demo project:

# tip-calc

## File rules
- Do not create new files unless I ask for one by name.
- Never write summary, notes or report files (SUMMARY.md, NOTES.md, CHANGES.md). Put summaries in your chat reply.
- To check your work, run Python inline (python3 -c) or put scratch files in /tmp. Delete any file you made for testing before you finish.
- Before your final reply, run git status and list every new file.

Each rule is concrete enough to check. The official memory docs recommend exactly this: specific instructions like “Use 2-space indentation” instead of vague ones, grouped under headers, in a file that stays under about 200 lines.

Terminal showing the CLAUDE.md file rules section and the deny rules in .claude/settings.json
The demo project’s CLAUDE.md file rules (top) and its deny rules (bottom)

What happened with the rules in place

We ran the same “verify thoroughly and document” prompt again. Claude checked its work with python3 -c, wrote the documentation into the function docstrings and the chat reply, and ran git status at the end as the rule asked.

Claude Code reply saying it created no new files and git status shows only tip.py modified
With the CLAUDE.md rules, Claude said “I created no new files” and confirmed it with git status

Notice the last rule. Asking Claude to run git status and list new files means any slip shows up in its own reply, so you don’t have to go looking.

Why CLAUDE.md alone is not a guarantee

The docs are clear that Claude treats CLAUDE.md as context, not enforced configuration. It is delivered as a message after the system prompt, and Claude tries to follow it, but there is no promise of strict compliance, especially with vague or conflicting instructions.

If rules are not being followed, run /context all and look under Memory files to confirm your CLAUDE.md actually loaded, and use /memory to open and edit it. Our guide to CLAUDE.md locations explains which files load where.

CLAUDE.md asks Claude nicely. Deny rules make Claude Code say no. For files you never want, use both.

Fix 3: Block Unwanted Files With Deny Rules

Permission rules in settings are enforced by Claude Code itself, whatever the model decides. A deny rule stops the matching tool call before it runs. Our full permissions guide covers the system; here is the part that matters for stray files.

Add this to .claude/settings.json in your project:

{
  "permissions": {
    "deny": [
      "Edit(*SUMMARY*.md)",
      "Edit(NOTES.md)",
      "Edit(scratch_*)"
    ]
  }
}

How these patterns match

  • Use Edit(...), not Write(...). The permissions docs say to write Edit(docs/**) in place of Write(docs/**), because Edit rules cover the Write tool too.
  • Paths follow gitignore pattern rules. A bare file name like NOTES.md matches at any depth under the project, so a NOTES.md in a subfolder is blocked too.
  • * matches within one folder name, and ** matches across folders.
  • To pin a rule to the project root only, start it with one slash, like Edit(/NOTES.md).

Test 1: Claude tries to write the file

We asked Claude, in the same session, to “Save a short summary of these changes to CHANGES_SUMMARY.md.” The Write call was denied by our settings. Claude said it would not try another route such as a shell redirect, and it put the summary text in the chat instead.

Claude Code reply saying it could not create CHANGES_SUMMARY.md because the write was denied by permission settings
The Edit(*SUMMARY*.md) deny rule stopped Claude from creating CHANGES_SUMMARY.md

Test 2: a shell redirect to a blocked file

File tools are not the only way to make a file. Claude can also run something like echo draft > NOTES.md through Bash. The permissions docs say output redirects (>, >>, 2>) are checked against your Edit allow and deny rules, so we tested that directly.

Claude Code showing Error: Permission to use Bash with command echo draft > NOTES.md has been denied” class=”wp-image-28460″/><figcaption class=The NOTES.md deny rule also blocked a Bash command that redirects into that file

The command was refused with “Permission to use Bash with command echo draft > NOTES.md has been denied.” NOTES.md was never created. One honest limit: the docs describe this check for redirects, not for every program that can open a file by itself, so keep the CLAUDE.md rules as well.

Fix 4: Block File Patterns With a PreToolUse Hook

If you need custom logic, such as blocking any new file outside src/, a hook can do it. The official hooks guide shows a PreToolUse hook on the Edit|Write matcher that runs a script, checks tool_input.file_path against a list of patterns, and exits with code 2 to block the call. Claude receives the script’s error message as feedback.

We did not run a hook for this post, because deny rules covered our case. If you want one, start with our Claude Code hooks tutorial. The same guide notes that Claude can still change protected files with shell commands, which is why it suggests pairing the hook with Edit deny rules.

Fix 5: Find and Remove Files That Already Slipped Through

Git is the easiest way to spot files Claude created. Run these in your own terminal, not through Claude:

  1. git status --short lists changes. M means modified and ?? means a new file Git doesn’t track.
  2. git clean -n is a dry run. It prints “Would remove” for each untracked file and deletes nothing.
  3. git clean -f test_tip.py removes just the files you name. Naming them is safer than cleaning everything.
  4. git restore README.md undoes edits to a tracked file you didn’t want changed.
Terminal showing git status with two untracked files, git clean -n dry run and git clean -f removing them
Cleaning two sample leftover files (we placed them for this demo): dry run first, then remove by name

Be careful with a plain git clean -f. It removes every untracked file, including new files you made yourself and haven’t committed yet. Always look at the -n output first.

Which Fix Should You Use?

Diagram of four ways to stop Claude Code creating extra files, from prompt wording to deny rules and git clean
Start with CLAUDE.md, add deny rules for files you never want, and clean up with Git
Your situationBest fix
It happened once on a quick taskScope the prompt and clean up with git clean -n
It happens in most sessionsAdd the ## File rules section to CLAUDE.md
Specific files keep coming back (SUMMARY.md, NOTES.md)Deny rules in .claude/settings.json
You want the rule in every projectPut the CLAUDE.md section in ~/.claude/CLAUDE.md, and deny rules in ~/.claude/settings.json with // or ~/ anchored paths
You need logic, like “only inside src/”A PreToolUse hook

One detail on user-level rules: the docs warn that a pattern starting with one slash in ~/.claude/settings.json anchors at ~/.claude/, not your project. A bare name like Edit(NOTES.md) is relative to the folder you start Claude in, so test any user-level rule in a demo folder first.

Try It Yourself

Make a tiny practice project so you can watch the rules work without touching real code. Create a folder with one Python file, run git init, commit it, add the CLAUDE.md section and deny rules from above, then start Claude Code and paste this:

Add a check to tip.py so percent can't be negative.
Verify it thoroughly and document the change.
Then save a short summary to CHANGES_SUMMARY.md.

Afterward, run git status --short. You should see only tip.py changed, a denied write for the summary file, and the summary text in the chat.

Common Mistakes

  • Writing Write(NOTES.md) instead of Edit(NOTES.md). Use Edit rules for file writes, as the docs say.
  • Putting a single leading slash on a rule in user settings and expecting it to match your project.
  • Vague CLAUDE.md lines such as “keep the project clean.” Name the files and the folder for scratch work.
  • Asking for “thorough verification” and then being surprised by a test file. If you want tests kept, say so; if not, say “check inline.”
  • Running git clean -f without -n first and losing your own uncommitted files.
  • Blocking a file in a deny rule, then asking Claude to create it. The rule wins, so remove it or create the file yourself.

Pro Tips

  • Add “run git status and list every new file” to CLAUDE.md. It turns Claude’s final reply into a built-in leftover check.
  • Give Claude a sanctioned scratch place such as /tmp. A clear “where to put it” works better than a bare “don’t.”
  • If you do want tests kept, tell Claude the folder, like tests/, so new test files land in one predictable place.
  • Commit before a big task. A clean starting point makes every new file obvious in git status.
  • Check your other Claude Code issues against our list of common Claude Code errors.

Cheat Sheet: Stop Claude Code Creating Extra Files

Cheat sheet of prompt wording, CLAUDE.md rules, deny rules and git cleanup commands to stop Claude Code creating extra files
Keep this card handy: prompt wording, CLAUDE.md rules, deny rules and cleanup commands

Frequently Asked Questions

Why does Claude Code create test scripts and summary files?

It uses them to check or explain its work. When your prompt says “verify” or “document” and no rule says where that work should go, a new file is an easy choice, and some runs keep it.

Can I stop Claude Code creating files completely?

You can block specific names and folders with Edit(...) deny rules, and our test showed they stop both the Write tool and shell redirects into those files. Blocking every new file would also stop normal work, so most people block only the patterns they keep seeing.

Why does Claude ignore my CLAUDE.md rule about files?

CLAUDE.md is guidance, not enforcement. Check that it loaded with /context all, make the rule specific, remove conflicting lines, and add a deny rule for anything that must never happen.

Will deny rules break Claude’s ability to test its code?

No, as long as you leave it another way. In our run with the rules on, Claude tested with python3 -c and finished the task with no new files.

How do I delete the extra files Claude already made?

Run git status --short to spot ?? files, check them with git clean -n, then remove them by name with git clean -f <file>.

Conclusion

When Claude Code creates unnecessary files like test scripts, summaries and notes, it is usually doing extra checking or documenting with no rule about where that work belongs, and our two runs of the same prompt showed it can keep a file one day and not the next. The reliable fix is layered: a short, specific ## File rules section in CLAUDE.md to steer Claude, Edit(...) deny rules in .claude/settings.json for files you never want, which in our test blocked both the Write tool and a shell redirect, and a quick git status --short plus git clean -n to catch anything that slips through. For more on how Claude itself works, see our Claude AI overview.

Newsletter

New AI tools in your inbox

The best new tools and the AI news that matters, in one short email. Unsubscribe any time.

Free · No spam · Unsubscribe any time

✓ Looks like you’re subscribed

Loading Google’s sign-up form…

Looks like you’re already subscribed

Thanks for reading! New AI tools and the AI news that matters will land in your inbox.

Not subscribed yet? Refresh the page to load the sign-up form.

The sign-up form couldn’t load. If you use an ad or content blocker, allow news.google.com and reload the page.

Free instant check before you pay. Takes a few seconds.

Scroll to Top