Guard .claude hooks against exit-127 under non-Claude harnesses - #1875
Open
jokim1 wants to merge 1 commit into
Open
Guard .claude hooks against exit-127 under non-Claude harnesses#1875jokim1 wants to merge 1 commit into
jokim1 wants to merge 1 commit into
Conversation
Prepend a CLAUDE_PROJECT_DIR presence guard to PreToolUse and Stop hook commands so codex/kimi (which load Claude-compatible settings without that env var) no-op cleanly instead of resolving to /bin/fm-*.sh and exiting 127. Real Claude Code still runs the guards unchanged; GROK_AGENT skips remain.
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
.claude/settings.jsonhook commands are written as"$CLAUDE_PROJECT_DIR"/bin/fm-*.sh. Codex and Kimi also load Claude-compatible project settings, but they do not set$CLAUDE_PROJECT_DIR, so the command resolves to/bin/fm-*.sh(nonexistent) and exits 127 on everyPreToolUse/Stophook. Any firstmate home running a non-Claude harness (a common secondmate/crewmate configuration) then prints a 127 error on every tool call.Reproduced: with
CLAUDE_PROJECT_DIRunset the hook command exits 127; with it set it exits 0. TheStophooks already skip underGROK_AGENT, but thePreToolUsehooks have no guard, and codex/kimi have no skip at all.This is cosmetic — those harnesses still get the equivalent guards via their own
.codex/hooks.json— but it is noisy on every action.Fix
Prepend
[ -n "${CLAUDE_PROJECT_DIR:-}" ] || exit 0;to each hook command that references$CLAUDE_PROJECT_DIR, so a foreign harness loading these Claude-compatible settings no-ops cleanly instead of hitting a missing/bin/...path. Real Claude Code is unchanged (the variable is always set there), and the existingGROK_AGENTskips remain.Verified:
CLAUDE_PROJECT_DIRunset → hook exits 0 (was 127).CLAUDE_PROJECT_DIRset → hook runs the guard as before (exit 0).5-line change,
.claude/settings.jsononly.