Files
trailofbits__skills/plugins/gh-cli/hooks/setup-shims.sh
David Maynor 38793f6757 fix(gh-cli): exit 0 when CLAUDE_ENV_FILE is unset (#135)
* fix(gh-cli): exit 0 when CLAUDE_ENV_FILE is unset in setup-shims.sh

When CLAUDE_ENV_FILE is not set by the runtime, setup-shims.sh exits 1,
causing a SessionStart hook error in Claude Code. This is a graceful
degradation case (shims simply won't be installed), not a fatal error.

The gh-not-found guard on line 10 already exits 0 for the same reason.
This change makes the CLAUDE_ENV_FILE guard consistent.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(gh-cli): update bats test for exit 0 and bump version to 1.4.1

The bats test for the CLAUDE_ENV_FILE-unset guard still expected exit 1.
Update it to match the new graceful-degradation behavior, and bump the
plugin version so clients pick up the fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: David Maynor <dmaynor@Davids-MacBook-Air-2.local>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Dan Guido <dan@trailofbits.com>
2026-04-28 19:28:59 -04:00

33 lines
889 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# SessionStart hook: prepend shims directory to PATH so that bare
# gh invocations are intercepted with anti-pattern checks.
# Guard: only activate when gh is available
if ! command -v gh &>/dev/null; then
echo "gh-cli: gh not found on PATH; shims will not be installed" >&2
exit 0
fi
# Guard: CLAUDE_ENV_FILE must be set by the runtime
if [[ -z "${CLAUDE_ENV_FILE:-}" ]]; then
echo "gh-cli: CLAUDE_ENV_FILE not set; shims will not be installed" >&2
exit 0
fi
shims_dir="$(cd "$(dirname "$0")/shims" && pwd)" || {
echo "gh-cli: shims directory not found" >&2
exit 1
}
if [[ ! -x "${shims_dir}/gh" ]]; then
echo "gh-cli: shims/gh not found or not executable" >&2
exit 1
fi
echo "export PATH=\"${shims_dir}:\${PATH}\"" >>"$CLAUDE_ENV_FILE" || {
echo "gh-cli: failed to write to CLAUDE_ENV_FILE ($CLAUDE_ENV_FILE)" >&2
exit 1
}