Claude Code Meltdowns: Moments That Drove Me Crazy
After a few months of daily work with Claude Code, I have hit six recurring failure modes: deleting the wrong files, editing the wrong files, leaking secrets, getting stuck in infinite loops, breaking batch jobs mid-flight, and working in the wrong repository. None of these were one-off flukes—they happen over and over unless you put guardrails in place.
This post walks through each incident, explains why it happened, and gives you copy-pasteable configurations to block it. Drop these safeguards into your repo and you will dodge half the pitfalls up front.
1. File Operations: Wrong File Deleted & Wrong Project Modified
Meltdown 1: Claude Deleted Something It Shouldn’t Have
I asked Claude to clean up “unused files” in a project. It ran rm -rf on a config directory whose name included deprecated—assuming it was safe to remove—and wiped out a local override file I maintained by hand.
Recovery: Luckily it had been committed earlier, so a single command brought it back:
1 | # Restore a deleted file or directory |
Prevention: Intercept dangerous commands with a PreToolUse Hook. Add this to .claude/settings.json:
1 | { |
Now any rm -rf attempt hits a hard block via exit 2. (Note: only exit code 2 blocks tool execution and sends stderr back to Claude; exit 1 is treated as a non-blocking warning and will not stop the command.)
Pair it with a hard rule in CLAUDE.md:
1 | # Add to CLAUDE.md: |
Meltdown 2: Working in the Wrong Project Directory
I had two terminals open—one in my blog repo, one in a work repo. I launched Claude in the wrong window, and it obediently created blog files inside the work project.
Prevention: Put the project name and path at the top of CLAUDE.md so Claude reads and anchors on it right at startup:
1 | # Top of CLAUDE.md: |
Also build the habit of checking your working directory before launching Claude:
1 | # Verify the current directory before launching claude |
2. Session Management: Context Overflow & Infinite Loops
Meltdown 3: Context Overflow Causing “Ghost Edits”
Deep into a long session, I asked Claude to update config file A. It wrote the changes into file B instead. After dozens of turns, it had lost track of which file we were supposed to touch.
How to spot context filling up: The Claude Code status line displays context usage as a percentage. Once it crosses 70%, compact or start a fresh session.
Key commands:
1 | # Context at 50-70%: compact to retain key state |
Another habit that pays off immediately: always include full file paths in your prompt. Compare the two:
1 | # Error-prone: vague reference to "the config file" |
Meltdown 4: Claude Stuck in an Infinite Loop
I asked Claude to fix a failing test. It went: search → edit → test → fail → search → edit somewhere else → test → fail again—for 8 rounds straight, patching minor side issues each time without ever touching the root cause.
Prevention: Set a turn cap when launching non-interactive runs:
1 | # Cap a single non-interactive task at 10 turns (--max-turns requires -p) |
And steer the prompt so it diagnoses before editing:
1 | Fix the failing tests in src/auth.test.ts. Rules: |
3. Security: Leaking Secrets to GitHub
Meltdown 5: Pushing Secrets to GitHub
I asked Claude to write a Feishu notification script. It hardcoded the webhook URL straight into the source file and ran git push. .gitignore only covered .env—it could not catch a secret sitting inside a .js file.
Bad vs. good:
1 | // Bad: hardcoded webhook URL |
**Security rules in CLAUDE.md**—writing them down explicitly is far more reliable than hoping Claude remembers:
1 | ## Security Rules |
Pre-push check:
1 | # Check the latest commit diff for potential secrets before pushing |
4. Orchestration: Subagent Batch Jobs Going Half-Baked
Meltdown 6: Inconsistent Batch Job State
I used Subagents to rewrite 20 articles in parallel. Several agents hit API rate limits (429), the orchestrator failed to handle partial errors cleanly, and the repo ended up half old, half new.
Safeguard 1: A progress file. Track each subtask’s state in JSON:
1 | { |
Safeguard 2: Spell out the failure policy in the orchestration prompt:
1 | Run the batch article rewrite. Rules: |
Safeguard 3: Run in small batches:
1 | # Run in batches of 3 to avoid rate limits |
5. Cheat Sheet: Failure Modes & Safeguards
| Failure Mode | Root Cause | Recovery Command | Prevention Setup |
|---|---|---|---|
| 1. Wrong file deleted | Shallow judgment on “unused” files | git restore <path> |
PreToolUse Hook blocking rm -rf |
| 2. Wrong project modified | Mixed-up working directories | Delete the stray files | Project name in CLAUDE.md + pwd check |
| 3. Ghost edits | Context overflow | Fix the wrong file manually | /compact + full paths in prompts |
| 4. Infinite loop | Patching symptoms instead of root cause | Press Esc to interrupt |
Prompt requiring root-cause analysis |
| 5. Secret leaked | Missing security guardrails | Rotate the secret immediately | Environment variables + git diff check |
| 6. Broken batch job | Missing failure handling | Roll back via progress file | Batches of 3 + JSON progress file |
All six meltdowns share the same takeaway: the problem wasn’t Claude—it was missing constraints. The next post dives into context management for long-running tasks, showing how to prevent ghost edits and forgotten rules.




