Claude generates incorrect file paths when writing scripts with relative REPO_ROOT calculations
Resolved 💬 2 comments Opened Apr 13, 2026 by ckanemotopl Closed May 23, 2026
Description
When Claude writes Python scripts that calculate REPO_ROOT using os.path.dirname(), it miscounts the directory depth, resulting in files being written to the wrong directory.
Reproduction
- Ask Claude to write a Python script in
tools/generate_something.pythat outputs a file to the repo root - Claude calculates
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))— three levels up instead of two - The script is at
tools/script.py(two levels from root), so threedirname()calls resolves to the parent of the repo - Output file lands in the wrong directory
Expected behavior
Claude should verify resolved paths before using them — e.g., assert a known file exists at the calculated root, or print the path before writing.
Impact
Generated a .docx file one directory above the intended location. User had to manually find and move it.
Environment
- Claude Code CLI
- claude-opus-4-6 model
- macOS Darwin 25.2.0
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗