[BUG] Bash ! pattern in skills/hooks breaks when working directory changes during session
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?
Description
When Claude Code performs file operations (reads, edits, renames) in subdirectories, the shell's working directory (pwd) can
silently change to a subdirectory. Subsequent ! bash patterns in skills/hooks that use relative paths then fail because they resolve
relative to the new pwd instead of the project root.
## Workaround
Manually cd back to the project root before invoking the skill.
## Environment
- macOS (Darwin 25.3.0)
- Claude Code (CLI) 2.1.59
- Node.js v24.4.1
What Should Happen?
Expected behavior
! bash patterns in skills/hooks should always resolve relative to the project root (the git repo root / initial working directory),
regardless of any pwd changes that happened during the session.
The ! pattern executor should cd to the project root before running the command. This is the cleanest fix since skills/hooks are project-level constructs and should always resolve from the project root.
Error Messages/Logs
Steps to Reproduce
## Reproduction
- Have a skill/hook that uses a ! bash pattern with a relative path, e.g.:
!node .claude/fwd/bin/fwd-tools.cjs commit-stage
- During a session, perform file operations in a subdirectory (e.g. rename files in backend/tst/benchmarks/some_dir/)
- After these operations, the pwd has changed to the subdirectory:
$ pwd
/Users/me/my-project/backend/tst/benchmarks/some_dir
- Invoke the skill — the ! pattern tries to resolve .claude/fwd/bin/fwd-tools.cjs relative to the subdirectory and fails:
Error: Cannot find module '/Users/me/my-project/backend/tst/benchmarks/some_dir/.claude/fwd/bin/fwd-tools.cjs'
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.59
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗