改了废弃的“双胞胎”文件,线上那个没动
Fixed the deprecated twin, not the live file
两个文件同名(v1 副本、legacy 目录)。智能体改了没在用的那个,你关心的 bug 依然存在。
适用于: Claude Code · Cursor · Codex · Copilot agent
症状
diff 看起来没问题,智能体也说修好了,但应用里的行为没变。被改的文件根本没被运行中的代码引用。
为什么会这样
检索会按名字相似度排序,废弃副本可能比线上文件更匹配查询。Night Forge 把这种“遗留/错误路径编辑”列为 Cursor 用户反复遇到的三种模式之一,并指出 Claude Code 也有同类问题。
示例
摘自 Night Forge 的文章。
textYou meant: src/components/UserAvatar.tsx
Agent edited: src/v1/UserAvatar.tsx (deprecated, not imported anywhere live)
复制即用的修复
按你用的智能体挑选文件。规则片段用英文写,放进任何仓库都能用。
规则
Claude Code:加入 CLAUDE.md
CLAUDE.md## Make sure you are editing the live file
- Before editing, confirm the file is actually used: find who imports it (`rg -n "UserAvatar" src`)
and trace it to a route, entry point or test that runs.
- Never edit files under `legacy/`, `deprecated/`, `v1/`, `old/` or `*.bak` unless the user names them.
- If two files have the same name, list both and say which one you will change and why.
规则
Codex、Copilot 编码智能体等:加入 AGENTS.md
AGENTS.md## Make sure you are editing the live file
- Before editing, confirm the file is actually used: find who imports it (`rg -n "UserAvatar" src`)
and trace it to a route, entry point or test that runs.
- Never edit files under `legacy/`, `deprecated/`, `v1/`, `old/` or `*.bak` unless the user names them.
- If two files have the same name, list both and say which one you will change and why.
Cursor 规则
Cursor:项目规则
.cursor/rules/edited-the-wrong-twin.mdc---
description: "AgentFails: Fixed the deprecated twin, not the live file"
globs: **/*
alwaysApply: false
---
## Make sure you are editing the live file
- Before editing, confirm the file is actually used: find who imports it (`rg -n "UserAvatar" src`)
and trace it to a route, entry point or test that runs.
- Never edit files under `legacy/`, `deprecated/`, `v1/`, `old/` or `*.bak` unless the user names them.
- If two files have the same name, list both and say which one you will change and why.
配置
让废弃路径够不着(.cursorignore 和 Claude Code deny)
.cursorignore / .claude/settings.json# .cursorignore
src/v1/
legacy/
# .claude/settings.json -> "permissions": { "deny": ["Edit(./src/v1/**)", "Edit(./legacy/**)"] }