fix(hooks): resolve gate.sh via $CLAUDE_PROJECT_DIR so hooks work from any cwd - #44
Merged
Merged
Conversation
…m any cwd The PostToolUse (lint) and Stop (test_affected) hooks invoked gate.sh by a relative path (bash .claude/scripts/gate.sh ...). Hooks run with whatever cwd is current, so from a worktree/subdir/reset shell the path doesn't resolve and the hook dies with 'bash: .claude/scripts/gate.sh: No such file or directory'. Resolve it via $CLAUDE_PROJECT_DIR (always the project root) instead. gate.sh already computes its own repo root, so it runs correctly once found. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0193Wc7aqPQvNqVZjcndBaf6
robercano
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
PostToolUse(lint) andStop(test_affected) hooks in.claude/settings.jsoninvoke gate.sh by a relative path:Hooks run with whatever cwd is current. From a git worktree, a subdirectory, or a reset shell,
.claude/scripts/gate.shdoesn't resolve and the hook dies with:(Hit in practice on a downstream project's Stop hook.)
Fix
Resolve the script via
$CLAUDE_PROJECT_DIR(which Claude Code always sets to the project root):gate.sh already computes its own repo root from
BASH_SOURCE, so it runs correctly once found by an absolute path. Verified the new form resolves from a non-root cwd where the relative form failed.🤖 Generated with Claude Code