Fixed the deprecated twin, not the live file
改了废弃的“双胞胎”文件,线上那个没动
Two files share a name (a v1 copy, a legacy folder). The agent edits the dead one, and the bug you care about stays open.
Applies to: Claude Code · Cursor · Codex · Copilot agent
Symptom
The diff looks right and the agent says it's fixed, but the behavior in the app hasn't changed. The edited file isn't imported by anything that runs.
Why it happens
Retrieval ranks lookalike names, and a deprecated copy can match the query better than the live one. Night Forge describes this "legacy / wrong-path edit" as one of three recurring Cursor patterns, and notes Claude Code hits the same class of failure.
Example
From the Night Forge write-up.
textYou meant: src/components/UserAvatar.tsx
Agent edited: src/v1/UserAvatar.tsx (deprecated, not imported anywhere live)
Copy-paste fixes
Pick the files for the agents you use. Snippets are in English so they work in any repo.
Rules
Claude Code: add to 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.
Rules
Codex, Copilot coding agent and others: add to 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 rule
Cursor: project rule
.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.
Settings
Keep dead paths out of reach (.cursorignore and Claude Code deny)
.cursorignore / .claude/settings.json# .cursorignore
src/v1/
legacy/
# .claude/settings.json -> "permissions": { "deny": ["Edit(./src/v1/**)", "Edit(./legacy/**)"] }