Stop AI Coding Agents From Making The Same Mistakes
AI coding agents like Claude Code or Cursor often make the same errors. They use the wrong test runner. They use the wrong import style. You correct them in chat, but they forget the fix in the next session.
Chat history is not memory. When a session ends, your corrections vanish.
The fix is simple. Write your rules in a file the agent reads every time it runs.
Most tools support project-root instruction files: • Claude Code reads CLAUDE.md. • Cursor uses .cursor/rules/*.mdc. • Many tools use the AGENTS.md standard.
These files prepended to the model context. The rules exist before the model writes any code.
Do not write vague goals. Do not tell the agent to write "clean code." Vague rules do not work. Use specific, testable rules instead.
Use this structure for your rules file:
• Commands: Define exactly how to run tests and typechecks. • Style: Specify ESM over CommonJS or named exports over defaults. • Boundaries: Mark folders as read-only or define where secrets live. • Definition of Done: State that every new feature must have a failing test first.
A good rule file acts as a scar log. Every time an agent makes a mistake, add a one-line rule to the file in that same session.
Keep the file short. If your rules file is too long, it competes with your code for the model's attention. If a rule is over 200 lines, prune it. Remove rules that are no longer needed.
Do not assume the agent reads the file. Test it. Add a rule that asks the agent to state its test command at the start of a task. If it does it, the system works.
Stop correcting agents in chat. Start configuring them with files.
How to implement this:
- Create CLAUDE.md or AGENTS.md in your project root.
- Write only specific, checkable rules.
- Add a rule immediately after every mistake.
- Keep it lean and prune stale rules.
Optional learning community: https://t.me/GyaanSetuAi
