AIToday
AI Coding AssistantsAI Safety & AlignmentHacker NewsPublished: Jul 26, 2026, 13:01 JST

Rules to stop AI coding agents from breaking working code

Rules to stop AI coding agents from breaking working code

3 Key Points

  1. What happened

    A developer shared a set of rules and prompts designed to prevent AI coding assistants (Claude Code, Cursor, Codex) from introducing bugs or unintended changes. The core recommendation is creating a CLAUDE.md file in the project root with explicit prohibitions—such as "do not modify files I did not ask you to modify" and "do not refactor working code without being asked"—which these tools read automatically at the start of each session.

  2. Why it matters

    As codebases grow, AI assistants begin fixing one problem while breaking another, a structural issue that cannot be solved by better prompting alone. The rules address this by replacing vague directives ("write clean code") with clear prohibitions that have an immediate boundary. The approach also includes safeguards like requiring the model to show a plan before editing, demanding test evidence instead of claims that something works, and saving project state so changes can be rolled back.

  3. What to watch

    The author emphasizes that rules learned from actual breakage are more effective than those imagined in advance—each time the model fails, that specific failure should be appended to the rules file. Starting fresh sessions every 3–5 tasks (with a summary of what was done, what's next, and what was tried and abandoned) prevents context decay. A kill switch—a STOP.txt file that halts all work immediately—lets developers safely leave autonomous work running.

Not sure about something? Ask the AI

Summaries like this, in your inbox every morning.

Context & Analysis

The article addresses a real problem: as AI coding assistants become more capable within a single conversation, they also become more dangerous at scale. The author's observation—that after the first two weeks of apparent magic, the model begins fixing problem A while breaking problem B—reflects the gap between single-task performance and multi-file coherence. The proposed solution does not try to train the model better or prompt it harder; instead, it treats this as a structural problem that requires constraints.

The rules framework is grounded in a specific insight: vague instructions fail because they have no enforcement boundary. "Please be careful" or "write clean code" are aspirational but behaviorally empty. Prohibitions—"do not modify files I did not ask you to modify"—are actionable because they have a clear edge. The same logic extends to the five prompts: each one shifts the burden of verification away from the model's self-review (which inherits its own assumptions) onto external evidence. Requiring a test to pass, or a plan to be stated before execution, creates a checkpoint that the model cannot rationalize around using the same flawed logic that created the bug.

The author also identifies context decay as a practical failure mode. Long sessions accumulate abandoned directions and corrected mistakes, which stay in the context window and corrupt the signal. The solution—starting fresh every 3–5 tasks with a summary of what was tried and abandoned—is a form of state reset that prevents the model from re-proposing failed approaches. Finally, the reversibility principle (saving state before running agents, gating only irreversible actions) is a risk-management insight: it frees the model to iterate in low-stakes areas while maintaining human control over high-stakes decisions like deployment.

FAQ
What file do I create, and where?
Create CLAUDE.md in your project root. Claude Code reads it automatically at the start of every conversation. For Cursor, use .cursorrules; for Codex/Copilot, use AGENTS.md—the content is the same.
What should the rules file contain?
The file should include a one-sentence description of the project, the current state (what works and what doesn't), a "Do not touch" section listing files or folders and why they should not be modified, and explicit rules such as "Do not modify files I did not ask you to modify," "Do not refactor working code without being asked," and "If unsure, say 'I don't know'. Never present a guess as fact."
Why are prohibitions more effective than positive instructions?
Prohibitions have a clear edge and land immediately—there is no threshold to debate. A directive like "write clean code" has no behavioral boundary, so the model cannot change its behavior reliably. A prohibition like "do not modify files I didn't ask about" is unambiguous.

Get the latest AI Coding Assistants news every morning

For example, today's edition would include:

  • llm-keys-ui 0.1 keeps API keys out of agent chatsSimon Willison's Weblog · 14h ago
  • Sony Bank, Fujitsu put generative AI into core banking work, cutting man-hours 40%Top Companies AI · 17h ago
  • High schooler asks for feedback on C++ autograd projectr/MachineLearning · 23h ago

AI-summarized, only the topics you pick — one digest a day via Email, Slack, or Discord.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. Q&As are published on this page for other readers too.

Related Articles

Next articleAlphabet purchase commitments top $811 billion for AI infrastructure