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 move header.tsx to 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/utils does not exist. Please run mkdir -p src/utils first, 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 tree or find and update its context).

Prevention

  • Project Context: Add a .cowork/structure.txt file that lists key paths, and ask Claude to read it at the start of a session.