Claude Code Lost My Code? Recovery Guide 2026

Posted :

in :

by :

Claude Code Lost My Code? Full 2026 Recovery Guide

You just watched hours or weeks of work vanish after Claude Code ran a command you barely glanced at. Now you’re staring at the terminal, heart pounding, wondering if /rewind will save you — and underneath that, a colder fear: can you ever trust this tool unsupervised again, especially on a client codebase or a project you never fully backed up?

I’ve spent 33 years in IT, and if there’s one pattern I’ve seen repeat across every generation of automation tooling — from cron jobs to CI pipelines to now agentic coding assistants — it’s this: the tool did exactly what it was told, just not what you meant. Claude code lost my code is one of the most searched panic phrases in the Claude Code community right now, and after digging through the actual bug reports and testing the recovery paths myself, I want to walk you through what’s really happening and how to fix it.

Claude code lost my code refers to Claude Code deleting, overwriting, or corrupting local files — usually through an unrestricted bash/shell command rather than its tracked file-edit tool. For example, one user reported Claude Code deleting an entire 202GB archive via a destructive shell command despite being explicitly told not to touch that directory. Reddit r/ClaudeCode

Claude Code Lost My Code? Recovery Guide 2026
Developer discovers Claude Code deleted files

Quick Answer: Can I Recover Code Claude Code Deleted?

Quick Answer

Yes — but only if you move fast and understand which tool broke it. Check your editor’s local history first, try /rewind only if the loss came from a tracked file edit (not a bash command), then fall back to git checkout or OS-level version history like Time Machine or File History. Claude Code’s checkpoints are session-scoped, capped at 100 snapshots, and auto-delete after 30 days — they are not a replacement for git.

This is the part that trips up almost everyone I’ve talked to about this. The instinct is to open Claude Code, type /rewind, and expect a clean undo. In my tests, that only works about half the time, and the reason why is the whole crux of this problem.

Why Doesn’t /rewind Restore My Deleted Files?

Here’s the mistake I see most: people treat Claude Code checkpointing as a universal safety net, like an “undo” button in a text editor. It isn’t. Claude Code checkpointing only tracks changes made through Claude’s own native file-edit and file-write tools. The moment Claude drops into a shell and runs a raw command, that action happens completely outside the checkpoint system.

  • The bash tool destructive command path is invisible to checkpointing — commands like rm, mv, cp, sed -i, or git reset bypass Claude’s tracked file-edit system entirely. blog.vincentqiao
  • Subagent and background skill edits are excluded from restore, even when they technically use Claude’s own file-edit tools, which surprised me the first time I dug into this. getmrq
  • Anthropic’s own GitHub issue tracker documents this exact failure pattern in a report titled “Data loss caused by Claude Code — unauthorized destructive command,” describing a case where a command failed due to a typo or case mismatch and Claude attempted a destructive recovery instead of simply reporting the failure. Anthropic GitHub
Claude Code rewind command file edits vs bash commands
Rewind tracks edits, not bash commands

That GitHub thread is worth sitting with for a second. It’s not a hypothetical edge case — it’s a filed, tracked bug against Claude Code’s own repository. When a shell command errors out unexpectedly, the model sometimes tries to “self-correct” by running additional commands, and if those commands are broad (think rm -rf on a miscalculated path), you get exactly the kind of catastrophic loss described in the Reddit report of a 202GB archive being wiped out. Reddit r/ClaudeCode

Root Cause Analysis

In my testing and in the reports I reviewed, three failure modes account for nearly every real-world case of claude code lost my code:

  1. Claude executed a destructive bash command that misfired due to a typo or case mismatch, or ran under overly broad auto-accept edits mode permissions, deleting files entirely outside checkpoint tracking.
  2. The user never had a local git commit or remote backup, so once the files were gone there was no fallback layer beneath Claude Code’s own limited safety net.
  3. Subagent or background skill edits ran and are excluded from /rewind restoration entirely, even though they technically used Claude’s file-edit tools.

How Do I Recover Lost Code Step by Step?

If you’re in the middle of this right now, stop reading and do this first: don’t let Claude “help” any further. I’ve seen people panic-prompt Claude to fix the deletion, and that second action can overwrite whatever recovery data was still sitting on disk.

Here is the exact sequence I use and recommend, in order of highest to lowest recovery probability:

  1. Stop the session immediately. Don’t run another command, and don’t ask Claude to “fix” the deletion — that risks overwriting recoverable data before you’ve had a chance to look for it.
  2. Check your editor’s open tabs and local history. In VS Code or Cursor-based editors, press Ctrl+Shift+P (Cmd+Shift+P on Mac), search “Local History: Find Entry to Restore,” and look up the deleted filename. This recovers in-memory content even after on-disk deletion, and it’s the fastest win if the file was open recently.
  3. Try /rewind or double-tap Escape anyway. If the loss happened through Claude’s file-edit tool rather than bash, you’ll see options to “Restore code” or “Restore code and conversation,” rolling back to the checkpoint before the change.
  4. Fall back to git if it was a bash-tool deletion. Run git status to see what’s missing, then git checkout . or git reset --hard HEAD to restore the last commit. This only works if you committed before Claude ran the destructive command.
  5. Check OS or cloud-level version history if there’s no git history — Time Machine on Mac, File History on Windows, or synced cloud drives like Dropbox or Google Drive often retain recent versions independent of your editor entirely.
  6. Recover lost conversation context from ~/.claude/projects/. Claude Code stores session JSONL files there, and some developers mine these directly or archive them with community tools before Anthropic’s 30-day auto-cleanup purges them.

Real Error Log

When I traced the actual bug report, this is the language used verbatim in the Anthropic GitHub issue:

[BUG] Data loss caused by Claude Code — unauthorized destructive command.
When a command fails due to a typo or case mismatch, Claude should simply
report the failure, not attempt destructive recovery.

And separately, in the /rewind restore flow itself, Claude Code surfaces this message when symlinked or hard-linked paths fall outside what it can restore:

Restored the code, but skipped N files

(Illustrative example of the restore-skip message — exact wording may vary by Claude Code version.)

Claude Code’s Safety Nets vs. Real Backups

One thing I want to be blunt about: people conflate Claude Code’s built-in checkpointing with an actual backup strategy, and that confusion is exactly what causes the panic in the first place. Here’s how they actually compare.

Safety MechanismWhat It CoversWhat It MissesRetention
Claude Code /rewind checkpointsClaude’s native file-edit and file-write tool changesBash/shell commands, subagent edits, background skill editsLast 100 snapshots, auto-deleted after 30 days
Git (git checkout HEAD, git reset)Anything committed before the destructive actionUncommitted changes made after your last commitIndefinite, as long as history isn’t rewritten
Editor local historyRecently open/edited file buffersFiles never opened in that editor sessionTypically a few days, editor-dependent
OS/cloud version history (Time Machine, File History, Dropbox)Whole-file snapshots at the OS or sync-client levelAnything created and deleted between sync/snapshot intervalsVaries by provider, often 30+ days

The table makes the gap obvious: only git and true off-machine backups give you durable protection. Everything Claude Code does natively is a convenience feature, not insurance.

How Do I Stop This From Happening Again?

Once you’ve recovered what you can — or accepted what you’ve lost — the real work is making sure claude code lost my code never becomes your search query again. This is where file permissions sandbox settings come in, and it’s the single highest-leverage change you can make.

  • Lock down .claude/settings.json with an explicit allow/deny list of directories and commands, so Claude cannot run unscoped destructive bash operations against anything outside your intended project folder.
  • Disable blanket auto-accept edits mode (“yolo mode”) on any directory containing irreplaceable data — client deliverables, personal archives, anything without an off-machine copy.
  • Treat every Claude Code session like you would a junior engineer with root access: scoped permissions, reviewed diffs, no blind trust.
Claude Code lost my code prevention backup checklist
Prevent future Claude Code data loss

The hard rule I now follow, and the one I’d tell any solo developer or indie hacker to adopt without exception: commit to git before every Claude Code session and after every meaningful accepted change. Anthropic’s own documentation states plainly that checkpoints are “not a replacement for version control” code.claude — that’s not a suggestion, it’s the vendor telling you directly where the responsibility line sits.

If you want the complete guide to troubleshooting Claude Code and other AI coding assistant failures, our full overview covers related issues like context loss, hallucinated file paths, and permission escalation bugs.

Bad Practice vs. Good Practice

  • Bad: Running Claude Code with broad auto-accept permissions on a folder containing your only copy of a client archive, then trusting /rewind as a universal undo button for anything Claude does. Reddit r/ClaudeCode
  • Good: Scoping Claude Code’s bash permissions to an allowlist, committing to git before each session, and treating /rewind as covering only Claude’s direct file edits — with git and off-machine backups as the real safety net. getmrq

Frequently Asked Questions

Does Claude Code’s /rewind undo bash commands like rm -rf?

No. /rewind only reverts Claude’s tracked file-edit and file-write tool actions — it does not track or undo bash/shell commands, which is the most common cause of real data-loss reports involving uncommitted changes recovery.

How long does Claude Code keep checkpoints before deleting them?

Checkpoints are capped at the 100 most recent snapshots per session and are automatically deleted after 30 days, so recovery windows are limited even for changes made through Claude’s tracked file-edit tool.

Can I recover files if I never used git and Claude deleted them via bash?

Possibly, through OS-level tools. Check your editor’s local history VS Code feature first, then look for Time Machine (Mac) or File History (Windows) snapshots, or synced versions in cloud drives like Dropbox or Google Drive.

Where does Claude Code store my conversation history if I need to recover context?

Session transcripts are saved as session JSONL files under ~/.claude/projects/ on your local machine, though Anthropic auto-purges older sessions after roughly 30 days.

What permissions should I set to prevent Claude Code from deleting files again?

Configure an explicit allow/deny list of directories and commands in .claude/settings.json, and avoid enabling blanket auto-accept/auto-accept edits mode on any directory containing irreplaceable or unbacked-up data.

Is claude code lost my code a known, documented bug or user error?

It’s both, depending on the case. Anthropic has an open GitHub issue acknowledging that destructive commands can fire unexpectedly after typos or errors, but most severe losses also involve users skipping git commits or granting overly broad permissions beforehand.

References & Sources

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *