Fix: Hallucinated File Paths
Error Message:
"ENOENT: no such file or directory" "Cannot write to src/utils/helper.ts (directory does not exist)"
The Cause
Large Context Drift. After a long conversation, Claude might "remember" a file structure from a previous project, or it might assume a standard structure (like src/components) that your project doesn't use (maybe you use app/components).
The Fix
1. The "List First" Rule
Before asking for an edit, force Claude to look.
"Run
ls -R src/to see the current file structure, then moveheader.tsxto the correct location."
2. Create the Missing Directory
If Claude is trying to create a new file in a non-existent folder:
"The directory
src/utilsdoes not exist. Please runmkdir -p src/utilsfirst, then create the file."
3. Provide a Map
If working on a large codebase, verify the map:
"Generate a tree map of my project structure so you stop hallucinating paths." (Claude will run
treeorfindand update its context).
Prevention
- Project Context: Add a
.cowork/structure.txtfile that lists key paths, and ask Claude to read it at the start of a session.