Skip to content

fix(hooks): resolve gate.sh via $CLAUDE_PROJECT_DIR so hooks work from any cwd - #44

Merged
robercano-ghbot merged 1 commit into
mainfrom
fix/hook-gate-path-project-dir
Jul 3, 2026
Merged

fix(hooks): resolve gate.sh via $CLAUDE_PROJECT_DIR so hooks work from any cwd#44
robercano-ghbot merged 1 commit into
mainfrom
fix/hook-gate-path-project-dir

Conversation

@robercano-ghbot

Copy link
Copy Markdown
Collaborator

Problem

The PostToolUse (lint) and Stop (test_affected) hooks in .claude/settings.json invoke gate.sh by a relative path:

bash .claude/scripts/gate.sh lint
bash .claude/scripts/gate.sh test_affected

Hooks run with whatever cwd is current. From a git worktree, a subdirectory, or a reset shell, .claude/scripts/gate.sh doesn't resolve and the hook dies with:

bash: .claude/scripts/gate.sh: No such file or directory

(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):

bash "$CLAUDE_PROJECT_DIR/.claude/scripts/gate.sh" lint
bash "$CLAUDE_PROJECT_DIR/.claude/scripts/gate.sh" test_affected

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

…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-ghbot
robercano-ghbot merged commit 181d4ed into main Jul 3, 2026
9 checks passed
@robercano-ghbot
robercano-ghbot deleted the fix/hook-gate-path-project-dir branch July 3, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants