Skip to content

Guard .claude hooks against exit-127 under non-Claude harnesses - #1875

Open
jokim1 wants to merge 1 commit into
kunchenguid:mainfrom
jokim1:fm/fm-hook-foreign-harness-guard
Open

Guard .claude hooks against exit-127 under non-Claude harnesses#1875
jokim1 wants to merge 1 commit into
kunchenguid:mainfrom
jokim1:fm/fm-hook-foreign-harness-guard

Conversation

@jokim1

@jokim1 jokim1 commented Aug 7, 2026

Copy link
Copy Markdown

Problem

.claude/settings.json hook 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 every PreToolUse / Stop hook. 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_DIR unset the hook command exits 127; with it set it exits 0. The Stop hooks already skip under GROK_AGENT, but the PreToolUse hooks 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 existing GROK_AGENT skips remain.

Verified:

  • CLAUDE_PROJECT_DIR unset → hook exits 0 (was 127).
  • CLAUDE_PROJECT_DIR set → hook runs the guard as before (exit 0).

5-line change, .claude/settings.json only.

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.
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.

1 participant