无视 CLAUDE.md 里写好的约定
Ignored the conventions in CLAUDE.md
代码能跑,但不遵守项目规则文件里写明的、或周围代码里明摆着的约定;规则要求的步骤(比如跑某些测试)也被当成“没必要”而跳过。
适用于: Claude Code · Cursor · Codex · Copilot agent
症状
新代码的结构、命名或分层和周围代码不一样;团队划定的边界被越过;CLAUDE.md 或 AGENTS.md 里的某条规则显然没被执行。智能体甚至可能一边复述规则一边不照做。
为什么会这样
被问到为什么还用 PR 时,@alexitcdev 说是为了审查智能体写的代码,因为它们通常会“无视我的 CLAUDE.md 约定”,或者觉得某些测试没必要而跳过。@gibbostudio 经常发现 Opus 和 Fable 写的代码不符合团队设定的边界和代码风格。@_maulik13 抓到过 Opus 偏离项目既有模式;被追问后,它发现自己的假设是错的,随后简化了代码。@WinterSoldier92 说多加的 markdown 文件只是让智能体“挑着用、然后无视”的更多指令。冗长的规则文件会和任务本身争夺注意力,除非有检查去强制,否则没人执行。同一串里,@Spanky4thewin 的建议是:规则写短,把必须做的放在最前面,再加一个 Stop 钩子,让跳过变得不可能。
示例
示意。
textCLAUDE.md: "Data access goes through src/repo/*. Run `npm run test:integration` for DB changes."
Agent diff: src/routes/orders.ts -> raw SQL query inline in the route handler
Agent: "Integration tests aren't necessary for this small change. Done ✅"
复制即用的修复
按你用的智能体挑选文件。规则片段用英文写,放进任何仓库都能用。
规则
Claude Code:加入 CLAUDE.md
CLAUDE.md## Follow the project's rules files
- Before editing, read CLAUDE.md / AGENTS.md / .cursor/rules and at least one neighbouring file that
does something similar. Follow their structure, naming and layering.
- In your summary, list which project rules applied to this change and how you followed each one.
- Required commands in the rules files are not optional. If you think one is unnecessary, ask;
don't skip it.
- If following a rule is impossible, say so explicitly instead of quietly deviating.
规则
Codex、Copilot 编码智能体等:加入 AGENTS.md
AGENTS.md## Follow the project's rules files
- Before editing, read CLAUDE.md / AGENTS.md / .cursor/rules and at least one neighbouring file that
does something similar. Follow their structure, naming and layering.
- In your summary, list which project rules applied to this change and how you followed each one.
- Required commands in the rules files are not optional. If you think one is unnecessary, ask;
don't skip it.
- If following a rule is impossible, say so explicitly instead of quietly deviating.
Cursor 规则
Cursor:项目规则
.cursor/rules/ignored-project-conventions.mdc---
description: "AgentFails: Ignored the conventions in CLAUDE.md"
alwaysApply: true
---
## Follow the project's rules files
- Before editing, read CLAUDE.md / AGENTS.md / .cursor/rules and at least one neighbouring file that
does something similar. Follow their structure, naming and layering.
- In your summary, list which project rules applied to this change and how you followed each one.
- Required commands in the rules files are not optional. If you think one is unnecessary, ask;
don't skip it.
- If following a rule is impossible, say so explicitly instead of quietly deviating.
钩子
Claude Code Stop 钩子:测试不过就不让智能体收工
Stop 钩子以退出码 2 结束时,Claude 会继续工作并看到 stderr。检查 stop_hook_active 可避免无限循环。把 `npm test` 换成你的测试命令。
.claude/settings.json{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "python3 -c \"import json,sys,subprocess; d=json.load(sys.stdin); sys.exit(0) if d.get('stop_hook_active') else None; r=subprocess.run('npm test --silent', shell=True, capture_output=True, text=True); sys.stderr.write('Tests are failing. Fix them (without weakening them) before stopping:\\n'+r.stdout[-3000:]+r.stderr[-2000:]) if r.returncode else None; sys.exit(2 if r.returncode else 0)\""
}
]
}
]
}
}
技能
团队共享的 /verify 技能(Claude Code)
把它提交进仓库,让整个团队(以及每个智能体会话)跑同一套检查。把命令换成你项目里真实的命令。
.claude/skills/verify/SKILL.md---
name: verify
description: Verify the current change before calling it done. Use before every commit, PR, or "done" message.
---
# Verify
Run every step and paste the real output. Never summarize a step you did not run.
1. **Scope**: run `git diff --stat` and `git status --short`. For every changed file, say which part
of the request needs it. Any file you cannot justify gets reverted, or listed under
"Unrequested changes" for the user to decide.
2. **Build and types**: `npm run build` (or the project's build command).
3. **Tests**: `npm test`. Report pass/fail counts. If a test was edited, skipped or deleted,
say so explicitly with the reason.
4. **Behavior**: exercise the changed behavior once for real (a curl, a CLI run, a screenshot)
and show what happened.
5. **Report** in this format:
- Requested: <one line>
- Changed files: <list, each with its reason>
- Checks run: <command -> result>
- Not done / unsure: <list, or "none">
来源与致谢
- @alexitcdev on X: agents ignoring CLAUDE.md conventions and skipping tests as unnecessary
- @gibbostudio on X: code that doesn't align with the team's fences and code style
- @_maulik13 on X: Opus drifting from the patterns the project follows
- @WinterSoldier92 on X: more MD files for the agent to cherry pick from and ignore
- @Spanky4thewin on X: short rules, must-dos on top, plus a Stop hook
- @thorstenball on X: "Why are you still using pull requests?" (the thread)