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

  1. Ask Claude to write a Python script in tools/generate_something.py that outputs a file to the repo root
  2. Claude calculates REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) — three levels up instead of two
  3. The script is at tools/script.py (two levels from root), so three dirname() calls resolves to the parent of the repo
  4. 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

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗