如何用簡短規則避免 AI 編碼智能體破壞專案
How I stop AI coding agents breaking my project
作者分享一套每次工作階段開始時由 AI 編碼智能體讀取的簡短規則,以避免不必要的整檔改寫、越界修改、安全疏漏和反覆嘗試失敗修正。規則將安全要求列為最高優先級,並要求先閲讀待改檔案及其呼叫方、採取最小修改,同一錯誤兩次修正失敗後先停下並詢問。
I like AI coding agents. I do not like when they rewrite a file that was already fine, hard-code a key "just for now", or try the same broken fix five times. The fix was not a smarter model. It was a short set of house rules the agent reads at the start of every session.
What kept going wrong
- Wholesale rewrites of files that only needed a small change.
- Scope creep: renaming and reformatting unrelated code.
-
Secrets in client bundles or committed
.envfiles. - Missing auth on new routes that "worked" in the happy path.
- Debug spirals: five near-identical attempts, each worse than the last.
None of that is mysterious. Without priorities, "make it work" quietly beats "don't break security" and "stay in scope".
The rules that helped
1. Rule priority
When instructions clash, follow the higher one and say which you followed:
- Security guardrails — never broken, even if asked.
- The task I asked for, in scope.
- Stack conventions.
- Working style preferences.
2. How to work
- Read the files you will change (and their callers) first.
- Make the smallest change; never rewrite a working file wholesale.
- Ambiguous request: ask one short question, then proceed.
- Two failed attempts at the same bug: stop, summarise what you tried, ask before a third.
3. Security always on
- Secrets only in server-side env.
- Check the caller on sensitive paths.
- No destructive git,
rm -rf, or--forceunless explicitly requested. - Run the real tests; do not skip them to go green.
4. What to report when done
What changed, what you ran, and what you did not verify. That last line is the one that saves evenings.
Where to put the rules
Put the shared text in AGENTS.md. Point CLAUDE.md at it with @AGENTS.md. Add a thin always-on Cursor rule under .cursor/rules/ if you want the security lines loaded in every Cursor chat.
A free MIT starter with those files, a 10-point pre-launch checklist and three prompts is here:
github.com/theodorecreatesco/vibe-coding-rules-starter
Copy the three files into a project, open a new chat, and ask what the top rules are. If the agent cannot name the priority and the security lines, the files are in the wrong place for that tool.
The optional paid upgrade with more stacks and a one-command installer is the Vibe Coding Rules Kit on Etsy. I use the free starter on small repos and the kit when a project spans several tools.
What I do not do any more
- Paste a 400-line "constitution" into every tool's file.
- Trust "done" without seeing the commands that were run.
- Let the agent take a third blind swing at the same bug.
Short rules, ranked once, read every session. That is the whole method.
來源:DEV Community · dev.to