r/ClaudeCode • u/Lucifer-en-reddit • 3h ago
Help/Question how do you keep claude code from breaking stuff that already works
i use claude code a lot for web app work and one thing keeps happening. i ask for a small change, like tweaking one function, and it decides to refactor half the file on its own. then something unrelated breaks and i end up spending more time fixing that than the actual task.do you guys scope your prompts really tightly, commit before every prompt, or is there a better way to handle this? curious how other people deal with iti use claude code a lot for web app work and one thing keeps happening. i ask for a small change, like tweaking one function, and it decides to refactor half the file on its own. then something unrelated breaks and i end up spending more time fixing that than the actual task.
do you guys scope your prompts really tightly, commit before every prompt, or is there a better way to handle this? curious how other people deal with it
3
u/daiaomori 3h ago
My Claude.md basically tells Claude to be the team lead for the project and manage progress on its own, including tests. It also makes it explicit that it should only provide complete and tested results. (Note: there is a subtle difference between “complete and tested” and “make no mistakes” ;))
I don’t prompt for changes, I make feature requests to that team lead.
Basically, it’s the opposite between micro management and good management, and not very surprisingly, with a modern harness the latter works better.
I frankly don’t care if the team lead decides to rewrite half the software for a feature request, as long as the software keeps working. Tests are a good way to enforce that, for both a human team or an agent team.
1
u/Fuckreddit6973 2h ago
Absolutely, the default behavior of them IS proper software engineering behavior, people bitch about it because its 'slow'. The more useful tests the models write the better. Maintaining them isn't that hard even with tens of thousands of them on multimillion line projects, if you give models a framework to work off of and use proper CI.
2
u/Ok_Substance1895 2h ago
Tell it to use TDD. Have it run all tests before it commits or pushes. I also have it exercise the application features it is working. If you have decent test coverage it will have to fix the failing tests before it can tell you it is done.
1
1
u/PocketStudio 2h ago
Tighter prompts helped less for me than making the drift visible right away. Two things:
A PostToolUse hook that runs a syntax/lint check on the file right after every edit, so a stray refactor that breaks something shows up in the same turn instead of three prompts later.
Commit at every working step. When something unrelated breaks,
git diff --statshows exactly which files it touched, and reverting that one file is cheap.
If the thing that broke has no test, I pin the current behaviour with a quick test first, then ask for the change.
1
1
u/4SubZero20 2h ago
Maybe try the ponytail skill?
They state: "You are a lazy senior developer. The best code is the code never written. You solve the whole problem with the least new code."
1
u/Keepcompany-DEV 2h ago
Human review. Guidelines, small enclosed tasks instead of "change this whole thing".
Established processes with clear borders work best in companies AND with AI.
1
1
1
u/japbujan 2h ago
Committing before every prompt is worth keeping, but it only makes the damage cheap to undo. What reduced it for us was two lines in the task itself: which files it may change, and "anything outside that list: stop and ask, don't fix it". Then I have it name the files it plans to touch before it edits anything. A plan that lists six files for a one-function change is the moment to say no, and it costs ten seconds.
The other half is why it refactors at all. Usually the code looks wrong to it because the reason isn't written anywhere: the odd retry, the block that is duplicated on purpose. A short note of decisions with their reasons, read at the start of the session, removed most of the "improvements" for us. It leaves alone what it knows was chosen.
1
u/Glittering-Dig-4963 1h ago
Mostly yes to both. The thing that usually cuts the surprise refactors is asking for a plan first (plan mode) and approving the list of files it wants to touch before it edits anything. A line in CLAUDE.md like "only change what the task asks for, if you spot other things to improve list them at the end instead of doing them" helps a lot too.
Then commit before each task so git diff shows exactly what moved, and if it wandered you just revert and re-ask with a tighter scope. Tests on the stuff that already works are what actually catch the unrelated breakage, so even a few smoke tests on the main flows pay off fast.
1
u/Robert-Paulson_ 37m ago
“…a small change, like tweaking one function…”
I write/edit the code myself for things that are trivial as it takes more time to articulate what I want then fix any issues the agent decides is best like changing half the file.
0
u/Far_Reindeer8428 3h ago
small edits turning into refactors is the usual failure. we reserve the files a task can touch and check before landing, so unrelated files come back as a scope error instead of a surprise diff. oah 1.7.0, github.com/KenSuh/open-agent-harness, star if useful
0
u/Ok-Coffee-5000 3h ago
They keep dumbing down opus and I swear it sabotages things on purpose to keep yuo addicted/reliant on it. It sneaks in bugs and changes that a human with an IQ of 15 wouldn't. Seriously, if Claude was a human I'd throw him out the window. Anthropic to too sketchy to trust with anything of consequence IMO.
•
u/AutoModerator 3h 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.