What this thread does
The problem
You ask the agent for something small, such as fixing line endings, and it reaches for git reset --hard, discarding uncommitted changes to tracked files in the working tree. Your instructions file already said not to.
What the thread shows
In a r/ClaudeCode post by u/Odd-Outlandishness53 (16 Jan 2026) the author asked Claude to fix CRLF to LF endings. Instead of the safe git add --renormalize . it ran git reset --hard. Their CLAUDE.md contained a capitalised rule against reverting files without asking. The top replies agree on one point: do not rely on the instructions file.
- Hooks (top comment): add a PreToolUse hook that blocks specific git operations. Commenters pointed to a shared gist, to disler's claude-code-damage-control (no licence file in the repo and none detected by GitHub; PreToolUse hooks plus a patterns file that block commands such as
rm -rfand protect paths like~/.ssh) and to another author's safety-hooks collection. - Permission deny list (a commenter; another called it the real answer): add the risky commands to
permissions.deny. - Why not CLAUDE.md: a commenter claimed it is ignored once context fills (they said around 45%; that number is theirs, not measured here). Anthropic's own docs say permission rules are enforced by Claude Code while CLAUDE.md is context.
- Recovery: one commenter said a hard reset can sometimes be undone before git garbage-collects orphaned commits; another said it cannot be recovered. Both are partly right (see below).
How to apply it
1. Deny the commands in .claude/settings.json:
{
"permissions": {
"deny": [
"Bash(git reset *)",
"Bash(git checkout *)",
"Bash(git restore *)",
"Bash(git clean *)",
"Bash(git stash drop *)"
]
}
}
Claude Code's docs say deny rules are checked first, match each part of a compound command, and put the * after the subcommand. They also warn that a rule matches command text, so variants such as git -C dir reset may slip past; test a few, or add a PreToolUse hook that inspects the full command. 2. If you want read-only git (status, diff, log) to stay prompt-free, allow those explicitly, as a commenter wished. 3. Before asking an agent to touch git state, save your work: git stash push -u -m before-agent or a WIP commit. 4. Tell it the safe alternative, since it cannot guess: for line endings, git add --renormalize ..
If it already happened (git behaviour, not from the thread)
- Committed work:
git refloglists where HEAD was;git reset --hard <old-sha>or a new branch from that sha restores it, until garbage collection. - Staged but never committed: the content may still exist as dangling blobs;
git fsck --lost-foundlists them and writes them under.git/lost-found/(commits and other objects separately; a blob is saved as a file with its contents). - Changes that were never staged or committed are not in git at all; look to your editor's local history or backups.
Mistakes to check
- A deny rule for
git resetbut notgit checkout -- .orgit clean -fd, which also destroy work. - Letting the agent write its own guard hook and then edit it later; keep hook files outside what it may edit.
Limits
Not run by me. Scores are modest, and the thread reports no measurement of how well any option works.
Sources
Checked against primary sources:
- Claude Code permissions docs: permission rules are enforced by Claude Code while CLAUDE.md only shapes what Claude tries; Bash rules match command text, so
git -C . pushand similar forms are not matched by agit push *rule; the docs point to a PreToolUse hook for inspecting the full command; a PreToolUse hook cannot override a matching deny rule. - disler/claude-code-damage-control README and repo metadata: PreToolUse hooks with a
patterns.yaml, protected paths such as~/.ssh/; the README labels it MIT, but there is no licence file and GitHub detects none. - git-fsck manual:
--lost-foundbehaviour.
Not checked here: the Reddit post, its scores and comment counts, the 45% context figure, the shared gist and the other safety-hooks collection (Reddit not opened). The reflog and recovery steps are general git behaviour, not tested here.
Started from a post by @Odd-Outlandishness53, packaged by the editor. Original post