Skip to content
86% off$349 $48.86code BF2026

Guides

AI Agent Deleted Uncommitted Work? How to Recover It

An AI agent ran git reset --hard or deleted files? Where to look for lost uncommitted work, and how to prevent a repeat with commits, worktrees and approvals.

GuideUpdated 8 min read

On this page

You typed a task, walked away, and came back to find the agent ran git reset --hard, deleted files, or wrote outside the project. Your uncommitted work is gone, and you want to know what can still be recovered and how to stop it happening again.

Public issue reports describe this pattern (as of November 2026): an agent reset a repo and destroyed about two days of uncommitted work, another overwrote an external backup it found, another deleted 29 git worktrees, and a write-up on Claude Code's /rewind says it does not restore files that shell commands deleted. People on vendor issue trackers report similar cases with Codex.

Why it happens

  • git reset --hard discards uncommitted changes by design. Commits survive it. Edits to tracked files that were never staged or committed do not.
  • Agents run with your user's permissions. Anything your account can write, including a mounted backup drive, is reachable.
  • Shell deletions skip the Trash. rm removes files directly.
  • Undo features have gaps. An agent's own undo may not cover what its shell commands changed. Check your agent's current documentation.
  • A worktree is a folder, not a wall. An agent that changes directory or uses an absolute path can still reach your main checkout.

Stop first, then recover

  1. Stop the agent. Every further command can overwrite something you want back.
  2. Don't run git gc --prune=now, git clean or a disk cleaner. They can permanently remove objects you may need. In Sledbot, leave Cleanup alone too: it has a "Checkpoints and private refs" category.
  3. Don't git reset --hard again to reach an earlier state. Create a branch at the commit you want instead.
What was lostCan git get it back?Where to look
Committed work, even on a reset or deleted branchYesgit reflog
Changes staged with git add, then lostOftengit fsck --lost-found
Edits to tracked files never staged or committedNoEditor local history, Time Machine, Sledbot checkpoints
Files removed with rmOnly the last committed versionTime Machine, an earlier commit, a checkpoint
Untracked filesgit reset --hard doesn't touch them, so something else removed themTime Machine

Recover committed work with the reflog

Lost commits stay in the reflog for weeks by default. This command only reads:

bash
git reflog

Find the entry from before the reset, then park a branch on it. This only adds a name; undo it with git branch -D rescue.

bash
git branch rescue <sha>

Recover staged changes with git fsck

When you run git add, git stores a copy of the content. A later reset removes the file from the index and working tree, but the stored copy remains until git prunes unreachable objects. This writes them into .git/lost-found/ and changes nothing else (delete that folder to undo):

bash
git fsck --lost-found

Files are named by hash. Search for a string you remember:

bash
grep -rl "a function name you remember" .git/lost-found/

Check places outside git

  • Time Machine. If a backup ran after your edits and before the destruction, restore from it.
  • Editor local history. In Sledbot's Code mode, Timeline has a Local History filter. It keeps 50 versions per file, skips versions over 4 MiB, and only covers files saved in Code mode.
  • Unsaved buffers. If the agent changes a file you have open with unsaved edits, Code mode shows "Changed on disk — and you have unsaved edits." with Compare, Keep Mine and Take Theirs. Unsaved buffers are also written to ~/Library/Application Support/Sledbot/HotExit/ about 2 seconds after a change and return as dirty tabs at next launch.

Recover with Sledbot checkpoints

If the agent ran in Sledbot in a git work tree, Sled Core snapshots the working tree at the end of every agent turn into private refs (refs/sled/checkpoints/<terminal>/<turn>), without touching your index or HEAD, and keeps the last 50. There is no checkpoint screen; use the command line:

bash
sled checkpoint ls

The subcommands are ls, diff, restore and create. restore takes a safety-… checkpoint first, so a restore can be undone. Every Sledbot terminal has sled on its PATH; for other terminals, install it from Settings ▸ General ▸ Command line.

If the agent was Sledbot's native agent (sled chat), /undo restores files to before the last turn. Outside a git repository it answers "Undo needs a git repository".

Step-by-step prevention

1. Commit before a long run

Committed work survives a reset. Before an unattended run:

bash
git switch -c wip/before-agent
git add -A
git commit -m "WIP before agent run"

This includes untracked files that aren't git-ignored, so check for secrets first. To undo the commit but keep the changes, run git reset HEAD~1. The commit lives in the folder the agent works in, so push the branch (git push -u origin wip/before-agent) for a copy it can't reach. In Sledbot, sled checkpoint create (optionally --label) snapshots by hand.

2. Give each agent its own worktree

A git worktree is a second checkout on its own branch, so a reset inside it affects that worktree, not your main folder.

bash
git worktree add -b agent/fix-login ../myrepo-agent

Point the agent at ../myrepo-agent. Remove it later with git worktree remove ../myrepo-agent; git refuses if it has uncommitted changes unless you add --force. A new worktree contains only committed files, and all worktrees share one .git, so an agent can still delete branches or other worktrees.

In Sledbot, Work in a new worktree is on by default for git repositories on the New task page (⌘T), at <repo>/.sledbot/worktrees/<branch>. Review changes then shows each hunk with Accept, Reject and Comment, and Merge and Open PR unlock only after every hunk is reviewed. See Start an agent on a task and Review an agent's changes. For parallel runs, see Claude Code worktrees.

3. Require approval for destructive commands

Sledbot's built-in "ask first" rules hold these as cards in Needs you: rm -r outside the worktree, file writes outside the worktree (temp folders excepted), anything run with sudo, deploys and package publishing, git push to protected branches, merging a pull request, cloud CLI changes, and curl/wget writes to non-localhost hosts.

No built-in rule covers git reset --hard, git clean or deleting files inside the worktree. Add your own:

  1. Press ⌘, to open Settings, then choose Approvals.
  2. Click Add rule.
  3. Set the effect to Ask first.
  4. In Command, enter a pattern in the style of the placeholder (git push * main), such as git reset *. Add another for git clean *.
  5. Click Save.

git reset * also asks for harmless resets like git reset HEAD~1. git checkout -- . and git restore . also discard changes, so add rules for them if you want them held. Test patterns in a throwaway repo.

4. Know which agents Sledbot can stop

AgentCan Sledbot block an action?
Claude CodeYes, through a hook before each tool call
Sledbot's native agent (sled chat)Yes; every tool call goes through the rules
Codex CLI, Cursor CLI, Gemini CLI and other CLI agents with a presetNo. Sledbot mirrors the agent's own permission prompt as a card and answers by typing keys, but can't stop what runs without asking
Agents with no preset, such as Hermes AgentDon't count on it; rely on commits and a worktree

Sledbot runs agents in real terminals and is not a sandbox. For a Codex or Cursor CLI run, a commit and a worktree before you start, plus checkpoints afterward, are the protections that count. Details: Needs you and approvals and a safer alternative to --dangerously-skip-permissions.

5. Keep backups out of reach

One reported agent found an external backup and overwrote it. Eject backup drives during unattended runs, or keep a copy where the agent can't write, such as a git remote. For stronger isolation, use a throwaway VM; see try risky software safely in a VM.

Which protection covers what

Protectiongit reset --hardrm in projectWrites outside projectAny agent
Commit before the runYesYesNoYes
Separate worktreeYes (main folder)Yes (main folder)NoYes
Sledbot checkpointsRestore afterwardRestore afterwardNoAgents run in Sledbot
Approval rulesWith a rule you addWith a rule you addBuilt inClaude Code and native agent
Unreachable backup or VMNoNoYesYes

Checklist before a long run

  • Everything is committed or checkpointed, and pushed to a remote.
  • The agent works in its own worktree.
  • Ask-first rules exist for git reset * and git clean *.
  • Backup drives are ejected or copied elsewhere.
  • You know whether this agent can be blocked.

If nothing works

If git reflog and git fsck --lost-found come up empty and you have no Time Machine copy, the changes are likely gone. Still, ask the agent vendor to look at the session, and for Sledbot problems use support.

text
An agent ran a destructive command and I lost uncommitted work.
Agent and version: <name, version>
Command it ran (from the transcript): <command>
Time it happened: <timestamp>
Already tried: git reflog, git fsck --lost-found, Time Machine, checkpoints (sled checkpoint ls)
Can you confirm whether any recovery path exists for this session?

Common questions

Can I recover files an agent deleted with rm?

Not from the Trash, because the shell doesn't use it. Look in Time Machine, a checkpoint taken before the deletion, or an earlier commit.

Does a worktree stop git reset --hard from hurting my main checkout?

Yes for the working files, as long as the agent stays in its worktree. It doesn't stop it changing directory or touching shared branches.

Why aren't my edits in the agent's worktree?

A worktree contains only committed files. Commit first, then create it.

Is Sledbot free to try?

It is part of MacSuite, and each app runs 7 days without a key (as of November 2026). After the trial, running agents keep going but starting new ones needs a license. See pricing.

We make Sledbot, so weigh our view accordingly. It covers part of this: separate worktrees by default, per-turn checkpoints (command line only), and approval for some risky actions. It has no built-in git reset --hard rule and can only block Claude Code and its native agent.

Every app.
One purchase.