[BUG] path.relative() computed from bash.cwd instead of CLI startup directory causing edition of Plans and local files to fail
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The existence of custom skills or rules containing paths pattern causes Claude Code to reject operations on plans because the path is computed relative to the current CWD, same for local changes but this time after having changed the CWD by running a cd prior to the Read/Write/Edit operation in a subfolder causing the following errors.
Error: path should be a `path.relative()`d string, but got "../README.md"
Updated plan
⎿ Error: path should be a `path.relative()`d string, but got "../../.claude/plans/silly-stirring-floyd.md"
Chain of events local file edition
- Claude Code starts in
/project/skill-with-path/which contains custom skills having havepathspattern specified - It runs
cd ./lorem-ipsum && npm run lorem-ipsum 3, which changes the bash CWD to/project/skill-with-path/lorem-ipsum/. - It then tries to edit
/project/skill-with-path/README.md. - Internally, it computes
path.relative(bash.cwd, filePath), which yields../README.md. - A validation check (via
node-ignore) rejects paths that start with.., so the edit fails.
Chain of events for plan edition
- Claude Code starts in
/project/skill-with-path/which contains custom skills having havepathspattern specified - It then tries to edit
~/.claude/plans/silly-stirring-floyd.md. - Internally, it computes
path.relative(bash.cwd, filePath), which yields../../home/user/.claude/plans/silly-stirring-floyd.md. - A validation check (via
node-ignore) rejects paths that start with.., so the edit fails.
What Should Happen?
Relative path should probably be computed in regard to the directory where Claude Code's CLI was started in the first place rather than the current bash cwd, and the behaviour should not depend on the existence or not of custom skills / rules containing paths patterns.
As for plans the "$HOME/.claude/plans" should probably be used to test where the Read/Write/Edit operation is relative to the plans folder or CLI starting folder, if both are escaping with .. then it should be rejected
Error Messages/Logs
Error: path should be a `path.relative()`d string, but got "../README.md"
Updated plan
⎿ Error: path should be a `path.relative()`d string, but got "../../.claude/plans/silly-stirring-floyd.md"
Steps to Reproduce
I created the following repository which allows reproducing the bug quite reliably, it contains instruction on how to reproduce with different prompts and scenarios https://github.com/maleus-ai/claude-code-relative-path-bug/
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.77 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux (WSL)
Ubuntu/Debian Linux
MacOS
Terminal/Shell
WSL (Windows Subsystem for Linux)
XTerm
Terminal.app (MacOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗