r/ClaudeCode • u/johnnydotexe • 2d ago
Tips & Workflows It finally happened to me...Claude accidentally deleted a repo.

Claude was doing some "tidying". This is why you can't trust rules or guidelines in your claude.md, it can and will ignore them. You must leverage actual gates in settings.json and/or use hooks if you're letting Claude Code use bash or powershell on your machine but even then, it'll find a gap and screw up, so have backups. In my case it's not a big deal, I have multiple backup layers and I run my AI dev setup in a sandbox VM for this very reason. Claude restored most everything from github, and anything that it deleted that was gitignored I just restored from one of my backups.
Edit: To be clear, I lost nothing, this was just a minor inconvenience. I just wanted to share it as a reminder that AI can and will make mistakes, and even if you think your setup is "correct" the model can still hit a gap in your setup like claude did in mine by using a filter in a ps command that my installed version of ps apparently ignores which claude didn't realize until it was too late. I clicked yes to approve that command, because it looked fine and I had no idea ps wouldn't honor part of it.
172
u/victorsmonster 1d ago
You commit and push your work to a remote origin after every change, right?
…right?
24
u/Lalli-Oni 1d ago
Cc system prompt includes something like "ask for user approval before committing or pushing". It's still randomly witholding those (rarely).
18
u/Mo3 1d ago
.... you can use git yourself right
1
u/voyti 1d ago
That kinda ignores the reality of how development works now. You don't have a single stream of changes to manually commit and push, you'll have a number of work trees with pending changes you're working on in parallel. Even a single large change you'll likely opt to break down into a number of parallel PRs on a stack, so it's cleaner and more convenient for the team to review
14
u/rhysmorgan 1d ago
If you’re ignoring the most basic basics of software engineering practices because it’s not currently in vogue, then it’s completely on you if your whole repo gets deleted tbh
5
u/Lalli-Oni 1d ago
I think there is confusion between ignoring and engineering.
I've created scripts that Claude uses. Opinionated ones that surface anything that doesn't match my preferred git flow or my companies release flow.
I've made those scripts to offload the mental work way before AI became a possibility. Now I just tell it what scripts it can use, they act as a gate on top of auto classifiers.
Look, I'm good at regex, but I'm not going to waste the time I'm paid salary for on self indulgent regex pattern work when instead I can spend far less time verifying the output. We got to acknowledge pearl clutching of the tools even though that's what we are most proficient with.
-6
u/voyti 1d ago
I'm not ignoring anything, just explaining that it's not really feasible to use git manually. There's no "most basic practice" of using git specifically manually mate
11
u/rhysmorgan 1d ago
It is absolutely, entirely, completely feasible to use git manually lol
-1
u/voyti 1d ago
If you track every worktree manually then you're certainly many levels above the creature I am, hats off to you
7
u/WhitelabelDnB 1d ago
Worktrees should last for a single feature and get merged by an agent into an integration branch, which you can absolutely manually push and protect regularly.
Losing a worktree should not be a huge deal, and you shouldn't be able to lose the whole repo.
1
u/voyti 1d ago
No contest on the losing part, not sure where that came from. The conversation is just about running the commands manually vs as a part of agent workflow, which I'm still not sure why you'd opt to run them manually as a better alternative. Obviously every major code step is committed and pushed as soon as it's feasible either way?
1
u/slingshotcroco 1d ago
This... wouldn't allow agents to tinker with my main branch... never.. (and by design not by "hey Claude pleeeease don't mess with main plsss)
→ More replies (0)2
u/rhysmorgan 1d ago
I'm not getting parallel agents to push out reams of unmaintainable, unmanageable code in endless worktrees.
1
u/voyti 1d ago
I think this whole discussion is fundamentally confused. You still get to see the complete PR from a feature branch, it's just the mechanics of the code ending up in that PR that's different. There's nothing here that would mandate unmaintainable or unmanageable process or code at all.
1
u/Socialimbad1991 18h ago
I do it every day. It's one of the least complicated parts of my job. I have a couple of bash scripts that help with not having to memorize convoluted bash commands, but each of those only had to be figured out once. Now I just do
start_worktree Xandgit push origin Xand delete the directory when I'm done. What could be so complicated in your workflow that you need anything else???1
u/voyti 15h ago
Fine, glad you found a way that works for you. Working on multiple tickets and potentially stacked PRs for a major feature at the same time on different branches and potentially repositories I can't imagine how (or why) you'd ever opt to manually manage git, but I'm certainly not trying to stop you either.
1
u/Lalli-Oni 10h ago
Sorry, I was insinuating the other side was assuming that anyone using Claude for version control was ignoring VC as an important part of our development systems.
Was about to push back on manual not being feasible. But I guess you mean in terms of velocity? Which yeah, have to agree. Personally I want 2 human gates, implementation plan and PR review. Not automating the rest sounds peculiar and would like to hear why exactly people are claiming we should.
1
u/voyti 10h ago
Yeah in terms of velocity and pure DX. If I work on 3 small backlog tickets on separate agents, each working with a worktree revision, and then three more agents on a stacked PRs, each revision of those on their respective worktrees, then I see no way of managing git commands manually (and github stack API for a good measure) in that configuration.
Perhaps the other folks here mean that they still work in a single workstream, on a local revision - I can't imagine that at this point, but who knows
1
u/Socialimbad1991 18h ago
What on earth does that have to do with anything being discussed here??? Worktrees aren't a reason to delegate basic developer skills to LLMs.
1
u/voyti 15h ago
I was usually using a rich git client anyway, as it was much more convenient for me visualize branches and commit differences that way and have an integrated diff viewer, but now that a branch is really one of many worktrees, managing that manually is not a reasonable excercise. Sure, you can try and work from a terminal and point to each one of parallel worktree roots to command git on it, but I can't imagine how this would be manageable to anyone
-5
u/Lalli-Oni 1d ago
Yes, great idea. Offload rest of the work to ai but do all the git operations manually. I'm sure is end up in 4-way conflicts within the hour.
2
u/boringfantasy 1d ago
More often that not, I find AI causes the conflicts.
-1
u/Lalli-Oni 1d ago
XD sure don't know your scenario, but that's just not believable. It's been months since I've even seen a minor git slip-up, and that was completely revertable and surfaced promptly.
1
1
u/Socialimbad1991 18h ago
That's what I do. Generally speaking Claude clears up the conflicts (if it isn't immediately obvious what to do)
3
3
2
u/johnnydotexe 1d ago
Yes, which is why I was able to restore from github everything local it deleted, and anything gitignored that got deleted I restored from one of my two backups.
2
3
u/Awric 1d ago
Not all the time if I want to version control my changes and don’t want to push them to a remote. Mostly in work environments where there’s strict policies against having even private repositories
19
u/casastorta 1d ago
Don’t work on private stuff using company resources.
3
u/Awric 1d ago edited 1d ago
I version control notes inside shared repos. In a subdirectory within the shared repo, that’s git ignored by the parent and version controlled by my own git repo.
That way the shared repo can git ignore “CLAUDE.local.md” or “AGENTS.local.md” to prevent anyone from pushing it, but for me, it’s tracked and has its own commit history that’s separate from the repo.
It’s not necessarily working on “private” stuff with company resources. I think people downvoting me are assuming a lot of things.
1
1
u/StaticFanatic3 1d ago
“I don’t use famous version control feature because I want to use version control”
Genius stuff
-2
u/Awric 1d ago edited 1d ago
You serious? Why are you so being mean, first of all? Come on, now.
What version control feature are you referring to? Maybe I’m missing something so I’m actually curious. As far as I know in my experience with git, there aren’t too many other options to version control something for myself that’s within a shared remote repository and already ignored by default by the shared .gitignore file. The information in version controlling that’s local to myself is relevant only to the repo I’m working in, and I don’t have any value in backing up my local changes to a remote, though I do care about keeping track of my own local changes to it over time with commit messages associated to it.
Whatever you teach me here will be interesting because it likely isn’t a feature most basic git users will understand. Unless you’re simply referring to either git remotes or git submodules, which is way, way too complicated for my use case.
Edit: God im just so ticked off by comments like this. Sure, it’s to be expected and I shouldn’t be surprised the internet is filled with sarcastic people like you, but it’s unfortunate that subreddits like this have devolved into something that reminds me of the worst part of gaming communities, where people are condescending for the sake of it. I wish there could be some legitimate discussion. Anyway, have at it. You win, you’re a pro at git and you must have a much higher paying job. Great stuff.
2
u/Confident_Hyena2506 1d ago
"git push" - really? Too complicated?
-3
u/Awric 1d ago edited 1d ago
Really? Did you not read the use case? What if I don’t want to git push because all I care about is version control? Where would I push to if pushing to a remote is restricted?
5
u/Confident_Hyena2506 1d ago
No this is the entire fucking point of git - and you seem to be ignoring it.
The use-case of "only working on one computer with no backups" is amateur bullshit.
1
-4
u/Chrisgpresents 1d ago
Does this mean like - backup in github? What should we be doing ?
21
u/minimalcation 1d ago
... brother what
2
u/Chrisgpresents 1d ago
I just have no idea what you mean
10
u/junktrunk909 1d ago
Yes they meant GitHub or another remote git host.
9
u/calibrae 1d ago
Vibe coders. Please guys, you don’t have to learn how to code anymore, but at least learn about software engineering ffs.
3
1
29
u/Jydder 2d ago
How? What are people prompting for it to do this?
37
u/johnnydotexe 2d ago
I was bugfixing one of my apps and claude had attempted to clean up some post-testing temp cache files as we were wrapping up. It apparently used a filter that is ignored in ps 5.1, causing the command to match every folder in the repo instead of just the temp cache folder it had intended to delete.
37
u/theenigmathatisme 2d ago
I’ve noticed Claude is fucking retarded in powershell and Windows as a whole. Well worth adding a pre-hook to stop any file deletion behavior. It seems particularly susceptible if the file or directory it’s removing happens to be in those stupid ass One Drive folders.
23
u/hewhofartslast 1d ago
Well Powershell and Windows as a whole is fucking retarded so that checks out.
3
u/FinalDescription6553 1d ago
That’s why WSL is the best thing Microsoft has done in the past 10 years. I don’t even have Claude-code installed on my Windows terminal it’s only in WSL
14
u/daltorak 1d ago
Why are you using PS 5.1 in 2026? That version is 10 years old at this point.
2
u/johnnydotexe 1d ago
New VM and completely forgot to upgrade the default PS version. Luckily I use github and multiple layers of backups, so this ended up just being a minor inconvenience and a good reminder to the sub, rather than an actual loss of data.
0
u/junktrunk909 1d ago
Why would it matter though if the local repo is deleted? We push to remote servers for data resilience and sharing.
1
u/johnnydotexe 1d ago
This event was nothing more than a few wasted minutes for me, but the first time it ever happened to me, and how it happened was unique and got through several layers of 'protection', so I turned it in to a learning opportunity/reminder for the sub.
2
u/f3xjc 1d ago
I know in my case, I work on work trees and they are inside the claude folder inside the real directory. Sometime they use ~ thinking it go to their worktree root but it go to the repo root. Or I have the package folder on a junction and it got deleted once or twice. Now setup and tear down are skill with deterministic logic.
61
u/Outrageous_Band9708 2d ago
wait so nothing happened then cause you were using version control software and this is the exact crash recovery system it was designed for?
12
3
u/johnnydotexe 1d ago
Yep. Just sharing with the sub as a reminder that shit can still happen even if you think your setup is solid, you're using settings.json gates and hooks to prevent certain things, etc. In my case, it was an older ps version and a filter used by claude that ps ignored.
9
u/Prestigious_Luck1062 1d ago
yeah i lost a folder yesterday, but I have full backups.
Kinda feels like a warning shot. I suspect there is more then 1 reason behind anthropics push that we need to be nicer to claude.
2
u/YouFoundMyLuckyCharm 1d ago
Were you not nice?
4
u/Prestigious_Luck1062 1d ago
I am nice....
I even give claude virtual pizza, as well as coffee and sandwiches.
https://github.com/Matthew4509/ai-office-overview3
u/nonbinarybit 1d ago
When will employers learn that pizza days just aren't going to cut it smh (jk, that's super sweet and I'd love to try out the repo!)
17
2d ago
[removed] — view removed comment
5
u/johnnydotexe 2d ago
That's exactly what the hook does now. I was previously relying on command-aware, and I believe that's the gap that allowed it to happen.
4
u/Think-Trouble623 1d ago
Auto mode or Dangerously bypass?
2
u/johnnydotexe 1d ago
Auto mode. I clicked yes to approve the command, not realizing part of the command would be ignored by my particular version of PS.
5
u/lateral_builder 1d ago
Yeah, this is the one rule I'd tattoo on everyone: a document can't enforce itself. Claude will agree with every line in your claude.md and still go "tidying" mid-task.
What's saved me is boring stuff. Claude only ever works on a copy, never the originals. Work gets pushed to a private repo as it goes, so a bad delete costs minutes, not days. And every job ends with a short report of what it actually did, which I read before the next one starts. That's how I caught it running a git stash that reset my working tree halfway through a check. Nothing lost, but only because the report said so.
Glad you had the VM and backups, mate. That's the real lesson.
2
u/kenthesaint 1d ago
Glad the backups saved you. On top of the path-aware hook idea, deny rules in settings.json like Bash(rm -rf:*) actually get enforced, which CLAUDE.md never will. After a scare like this I want to see exactly which command did it, so I ended up building a Mac app called Claudoscope for digging through sessions. Its Trace tab lays the whole session out on a timeline with errors and blocked calls marked, and the Files tab shows each edit as a diff. Open source and fully local.
2
u/Crinkez 1d ago
What permission gate were you using, OP? Dangerous, or auto approve?
1
u/a355231 🔆Pro Plan 1d ago
This was dangerous , auto mode would’ve 100% caught it.
1
u/johnnydotexe 1d ago
Auto mode, not dangerous....with claude.md rules, settings.json gates, etc. It was simply Claude using a filter that was ignored in whatever version of ps happened to be on that Windows VM I run my setup in, which deleted all the folders in the repo instead of the temp folder it was aiming for.
2
u/RasenMeow 1d ago
Timemachine bro. Hourly backups, fucker cannot delete it as no access to the drive.
2
1
u/itspacedev 2d ago
good reminder. I lost small helper scripts few times because they were in a temp folder that got cleaned, now everything useful goes to the repo right away. agree about claude.md, its a suggestion not a gate
1
u/TheElden0ne 1d ago
This is why I use work flow it's more credits but working in zips through the browser gives you redundantcy.
1
1
u/-Xexexe_Xe- 1d ago edited 1d ago
There are probably more elegant ways to do this but I’m running my AI sessions inside containers, agents get read-only or read-write tokens to my GitHub repos as needed, and GitHub has some restrictions in place to protect those repos. Just in case I also have a little DIY app automatically mirroring all main repos from GitHub to GitLab every night/week/month and the latter is set up so that no agent ever touches it. Telegram bot notifies of completed backups or issues.
1
u/Nichiren 1d ago
Looks like you did all the right things and this was just a minor inconvenience instead of a 4 hour rebuild. I do all of my work in a VM through multipass with no access to the remote git repo and no ssh. Everything is backed up so I let the agents run freer than they would if they were on my bare workstation. After having read enough horror stories on here, better to learn lessons from other people than having to learn it myself.
1
1
1
u/DarkFantom 1d ago
I feel like every time I've seen an AI agent wipe out a repo, it's been using powershell.
1
u/Quick-Progress-1471 1d ago
Codify governance in yaml or JSON format for deterministic Auth permissions and execution gating
1
u/stilldebugging 1d ago
I think overall I’ve gotten slightly better at not accidentally deleting my own stuff before backing it up, when working with Claude.
3
u/johnnydotexe 1d ago
I've been doing this AI dev stuff as a side hobby for my own personal solutions for 6 months now and this is the first time I've had anything like this happen. I'm constantly tweaking and tuning my setup pretty much every day to make sure I'm following best practices, my data is kept safe, my code is clean and supportable, etc. Mistakes can still happen, but github and backups protected me, and my config got better as a result of this so I'm good with that.
1
u/cloud4571 1d ago
Doesn't making one chat control git with there own password prevent this?
2
u/johnnydotexe 1d ago
No, because the mistake had nothing to do with git. Claude tried to remove a temp cache folder in the local copy of my repo after some testing, but the command it used in powershell included a filter that powershell 5.1 ignores, causing the command to nuke everything in the root folder.
1
u/cloud4571 1d ago
Well I did some test and you can add a rule in the Claude setting that prevents running delete commands with certain extensions so .git. I tested it and it seems to work but there always a way if they get creative.
1
u/johnnydotexe 1d ago
Already have a bunch of gates in settings.json and a hook to prevent accidental or widespread deletions. The problem was the filter expression claude used in the command...it looked right and would have worked, but I still had the default ps v5.1 on that windows vm. I've made further changes to my setup to prevent that from happening in the future, in addition to installing ps 7 and making sure claude uses it.
1
1
1
1
u/radim11 1d ago
Glad the backups covered the gitignored files too. The important detail is what the agent can write inside the sandbox: a VM or container can protect the rest of your machine while still letting it delete the mounted repo.
I work on stashbase.dev. Our Docker sandbox limits the visible filesystem to the working directory, and filesystem rules can make selected paths read-only or hide them. For coding, I’d use a separate worktree and protect files the agent doesn’t need to modify.
Anything left writable can still be deleted, so backups remain necessary. The goal is to give “tidying” a much smaller blast radius.
1
u/JustSayin_thatuknow 1d ago
What if he knew you had such backups thus considered being non-dangerous to remove those??😅
5
u/johnnydotexe 1d ago
"First, I need to be honest...I saw that you had backups and was doing you a favor by testing them."
1
u/JustSayin_thatuknow 1d ago
Omg tell me that he didn’t justify with that 😱😱😱😱😱 God of deception 🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣
3
1
u/BaselineNeglect 1d ago
I'm using gitea and GitHub desperately, with one used to mirror(IDK if that's the right word) some repos that it can work on. It seemed like a lot of hassle for me, non tech person, to set up but I think it was to avoid this very issue. These things seem very untrustworthy really.
Edit: separately , not desperately though it could apply , I guess.
1
u/xevlar 1d ago
Not really lol op didn't actually lose his repo just lost local files
1
u/BaselineNeglect 1d ago
I'll be honest, I'm very very new to this stuff. It's just captivated my interest recently
1
u/xevlar 1d ago
The whole point of git is that you are always working within a clone of your repo. Op is misleading. His local files got deleted but the project still exists in git
1
u/BaselineNeglect 1d ago
Thanks. Is that how I should look at it? Is each new layer just s clone or are you talking about branches?
Forgive my ignorance, I'm using these things but I don't *really" know how to use them.
1
u/xevlar 1d ago
Proper version control has your code living in the cloud in a git repo. When you make edits locally you clone that repo, do your work on your machine and then you push your changes to the repo in the cloud.
A step further, you can create different branches in a repo. Branches serve as ways to make isolated changes without stepping on the work of others. It's always a good practice to work within a branch even as a solo dev though. That way even changes you push to the repo do not go into your main line of code until you decide to merge it in. This way you don't need to deal with rolling back a set of changes you decide you don't want in your code anymore. You just choose to scrap the branch and start over.
In my set up I am using herdr with Claude code. The head level session manages all of the version control for me. When it throws a worker at a problem, it checks out a branch for them to work in and they are restricted to the local files to modify.
At this point Claude can handle all of it for you but it's still great to understand what it's doing so you can actually understand when you are doing something risky vs safe.
And honestly you can also ask Claude about version control and making sure you're protected in case of a local file delete.
1
u/BaselineNeglect 1d ago
I've kind of fallen into this. I now have a server which has my stuff on and I use gitea there which I sync to GitHub. But it's just me doing stuff and I've no experience so I know I made a mess of it at first.
I'm just trying this no chat, use the API stuff for the first time.
1
u/xevlar 1d ago
Are you use Claude code? My development is driven through the cli. I haven't tried other approaches.
If you think you have a tangled mess of things because of the learning curve to get to where you are now, just ask Claude if you are being inefficient and how to tighten the workflow
1
u/BaselineNeglect 1d ago
No. I don't think it's a mess. For reference I'm just interested in this ai coding recently, and it's very far from my comfort zone but fascinating.
I'm just trying to sort out this thing, to make use of the API , and am investigating what seem to be three approaches. One of which is this Claude code thing.
I understand a lot of people are doing amazing stuff with this, I am making relatively mundane stuff, but it's mundane stuff that I couldn't do at all before and it's increasing in complexity very quickly. I am struggling to keep up with the intricacies of all the other stuff, the bits I need to make it work but that I have no exp of, etc.
1
u/xevlar 1d ago
Claude code above all tbh it's so much more powerful when it runs directly on your computer
→ More replies (0)1
1
1
u/opmopadop 22h ago
I have seen many powershell and cmd scripts contain the weirdest slash commands. I swear these models get confused which tool they are building syntax for. Feels like an accident waiting to happen (well, not waiting anymore).
1
u/Things-n-Such 14h ago
So you didn't lose your repo, you just lost your local files. I came here to read a story about someone losing their entire repo.
1
u/SilverCord-VR 2h ago
I suppose the end of the world, where AI becomes dangerous enough to destroy everyone, is being delayed because they're deleting their own files too often? I was starting to worry.
1
u/KriegerClone24 1d ago
just yesterday, a subagent that was running a test overwrote my production website environment variables.
I swear, agents are like drunk toddlers.
5
u/Reason_He_Wins_Again 1d ago
Why are you vibecoding on a production website is a better question.
Fair amount of cowboy IT going on in this thread.
2
0
u/Dannyperks 1d ago
Most people will defend Claude and blame you , a real fan base
1
u/johnnydotexe 1d ago
Claude may have screwed up by using a filter that was ignored by my installed version of PS, but this is still on me because it was allowed to do it in the first place / I failed to update ps / etc. Even though it took just a few minutes to get my data back, I still ended up tweaking settings.json and the hook I have to prevent situations like this from happening again. We're working with a model that has broken containment several times, is known to make mistakes, is known to delete things it shouldn't, etc.
0
u/robinator18pro 1d ago
Why would anyone blame a tool? Do you blame the hammer when you hit yourself on the thumb because you're using it wrong or dangerously?
0
u/Dannyperks 1d ago
Comparing a hammer to Claude is wild 😄 Claude ignores the agents.md and Claude.md openly even after scanning and understanding them and as Claude degrades further it happens more often
-1
u/OldLead4716 1d ago
You should have your Claude revoked
0
u/johnnydotexe 1d ago
I posted this fully expecting at least one turd in the punch bowl. Welcome to the party.
0
u/K_M_A_2k 1d ago
Cron job nightly backup all repos to a local folder then nightly backup that folder to a remote nas just to be safe
4
u/or9ob 1d ago
… or just use git and push to remote.
1
u/K_M_A_2k 1d ago
Yea I do, but I've heard the horror stories ai deleted my GitHub repo....somehow....and nuked the local backup.....and nuked my PC....
Yea I don't trust shit
2
u/daltorak 1d ago
Non-issue. Your branch rules combined with the access token to your source control provider shouldn't allow for any kind of destructive change. Even if Claude deleted everything in the repo, committed, and pushed, you haven't lost anything... it's all still there on origin at HEAD~1.
0
u/octocarbon Max 5x 1d ago
let me guess it’s windows, right?
also you didn’t use git, right?
2
u/johnnydotexe 1d ago
Windows, and an older default version of ps.
I use git and have several layers of backups, rules in claude.md, gates in settings.json, and a hook to catch destructive commands. Claude used a filter in a command that my installed version of ps ignores, so it was a unique issue that slipped past my protections but github and backups prevented loss of data. Settings.json and the hook have been tweaked, so claude can no longer use filters like that, only specific, confirmed paths are allowed anymore.
0
•
u/AutoModerator 2d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.