{"slug": "show-hn-rules-that-stop-ai-coding-agents-from-breaking-working-code", "title": "Show HN: Rules that stop AI coding agents from breaking working code", "summary": "A developer has published a set of rules and prompts designed to stop AI coding agents such as Claude Code, Cursor, and Codex from breaking existing working code, emphasizing structural constraints over prompting. The guide recommends creating a CLAUDE.md file with prohibitions like \"Do not modify files I did not ask you to modify,\" starting sessions with a plan, and appending rules extracted from actual breakage. It also advises starting fresh sessions every 3–5 tasks and gating irreversible actions like deletion or deployment.", "body_md": "Rules and prompts that keep Claude Code, Cursor, and Codex from wrecking things that already worked. Everything here is copy-paste. Explanations kept to a minimum.\n\nThe first two weeks feel like magic. Then the codebase grows past what the model\ncan hold at once, and it starts **fixing A while breaking B.**\n\nThat isn't a skill problem. It's a structure problem — which means prompting harder won't fix it. Constraints will.\n\nCreate `CLAUDE.md`\n\nin your project root and paste this.\nClaude Code reads it automatically at the start of every conversation.\n\n*(Cursor → .cursorrules, Codex/Copilot → AGENTS.md. Same content.)*\n\n```\n# Project\n\n## What this is\n[one sentence]\n\n## Current state\n[what works, what doesn't yet]\n\n## Do not touch\n- [file/folder] — [why]\n\n## Rules\n- Do not modify files I did not ask you to modify\n- Do not refactor working code without being asked\n- If unsure, say \"I don't know\". Never present a guess as fact\n- Never report something as done without verifying it\n```\n\n`Please write clean code`\n\ndoes nothing. There's no threshold for *clean*,\nso no behavior changes.\n\n**Prohibitions have a clear edge. They land immediately.**\n\n| ❌ No effect | ⭕ Works |\n|---|---|\n| Write clean code | Do not modify files I didn't ask about |\n| Be careful | Do not merge without tests |\n| Keep it organized | Do not touch `legacy/` |\n\n```\nDon't write code yet. First tell me which files you'd touch\nand where the risky parts are.\n```\n\nStarting with *\"fix it\"* means the model edits things **it can't itself account for.**\nGetting the plan first kills most collateral damage.\n\n```\nBefore changing this, tell me what else is affected by it.\n```\n\nWorks better than scolding. It ends up confessing:\n*\"ah, this is coupled to the character class.\"*\n\n```\nDon't tell me it works. Write a test and show me it passes.\n```\n\nModels are **bad at catching their own errors.** They review with the same\nassumptions they built with — so a wrong assumption survives both passes.\n\"Looks good\" is an opinion. A passing test is evidence.\n\n```\nSummarize: what's done / what's next / what we tried and abandoned.\nWrite it so a fresh session can continue from that alone.\n```\n\n**\"What we abandoned\" is the important part.** Without it, the new session\nconfidently proposes the exact approach that just failed.\n\n```\nDo not modify files I did not ask you to modify.\n```\n\nSingle highest-value line in the file.\n\nLong sessions get worse, and it isn't your imagination.\n\nAs the conversation grows, **abandoned directions and corrected mistakes**\nall keep counting as current context. The signal gets buried in its own history.\n\n**Start a fresh session every 3–5 tasks.** Run prompt #4 before you close.\n\nIf you're asking for the same thing a **third** time, stop rewording the request\nand **change the window.** That session can no longer produce the answer.\nPushing harder only raises your blood pressure.\n\nIf git feels like a wall, you don't need the commands. Just say:\n\n```\nBefore starting:   save the current state\nWhen it breaks:    restore the state you saved\n```\n\nNobody plays a game without saving. Same rule.\n\nCan Ctrl+Z undo this?\n\n| Just let it run | Always confirm first |\n|---|---|\n| Reading, searching, analyzing | Deleting |\n| Local edits (if you saved state) | Deploying |\n| Drafting | Sending email / messages |\n| Running tests | Payments, orders |\n\nAll-or-nothing is the worst setting. Gate the irreversible, free the rest.\n\nPut this in your rules file:\n\n```\nIf a file named STOP.txt exists in this folder, halt all work immediately.\n```\n\nOne file stops everything. With it you can leave things running. Without it you can't.\n\nEvery time the model gets something wrong, **append that sentence to your rules file.**\n\nRules you imagine in advance are mostly useless.\n**Rules extracted from actual breakage are the ones that hold.**\n\n```\n## Known traps\n- Stock deduction in order_service.py sits outside the transaction. Known, leaving it\n- test_payment.py hits the live API. Don't run it casually\n- We tried the event-driven approach and dropped it. Do not propose it again\n```\n\nDo this for a week and it stops repeating itself.\n\n- Keep the explanation in a file (\n`CLAUDE.md`\n\n) - Get the plan before the code\n- Save state so you can roll back\n- Whoever built it doesn't get to grade it\n- Gate only what's irreversible\n- \"Done\" means evidence, not a claim\n\nDon't try to adopt all of it. **Write the CLAUDE.md tonight.** That one file\nchanges tomorrow.\n\nEverything above is free and always will be. If it was useful and you want the full treatment, there's a 25-page field manual that goes deeper:\n\n** Working With Claude Code — Field Manual** · $19 · PDF\n\n- Approval gates, hooks, and kill switches in detail\n- Skills — turning repeated instructions into assets\n- Cost control and when\n*not*to build an autonomous loop - 7 copy-paste templates + a symptom → cause → fix table\n- The chapter on\n**not fooling yourself about results**\n\nDon't buy it if you already design your own hooks, skills, and subagents. You'd learn little. The README above is the useful half for most people.\n\nIf you have a line that actually works for you, open a PR or an issue. Real ones only — rules that survived contact with a real codebase.\n\n- Ask a question →\n[https://avenna01-ceo.github.io/makhyeoss/](https://avenna01-ceo.github.io/makhyeoss/) - Threads (KR) →\n[@k_aria26](https://www.threads.com/@k_aria26)\n\nFree. If I can solve it I will; if I can't I'll say so.", "url": "https://wpnews.pro/news/show-hn-rules-that-stop-ai-coding-agents-from-breaking-working-code", "canonical_source": "https://github.com/avenna01-ceo/claude-code-survival-kr", "published_at": "2026-07-26 02:30:44+00:00", "updated_at": "2026-07-26 02:52:12.682619+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-safety"], "entities": ["Claude Code", "Cursor", "Codex", "Copilot"], "alternates": {"html": "https://wpnews.pro/news/show-hn-rules-that-stop-ai-coding-agents-from-breaking-working-code", "markdown": "https://wpnews.pro/news/show-hn-rules-that-stop-ai-coding-agents-from-breaking-working-code.md", "text": "https://wpnews.pro/news/show-hn-rules-that-stop-ai-coding-agents-from-breaking-working-code.txt", "jsonld": "https://wpnews.pro/news/show-hn-rules-that-stop-ai-coding-agents-from-breaking-working-code.jsonld"}}