Add warn_gh_api PreToolUse hook to defer gh api calls#277
Merged
Conversation
Follows the same first-occurrence-deny, whitespace-normalized-key pattern as warn_scripting_oneliners.py, but targets `gh api` / `gh api graphql` invocations and points at high-level gh subcommands instead. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Wires the new PreToolUse Bash hook in after block_raw_github_fetch.py. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.
Summary
Add a PreToolUse Bash hook that intercepts
gh api/gh api graphql ...and, on the first occurrence per session per normalized command, denies with a message pointing at high-levelghsubcommands (gh pr view,gh pr diff,gh pr checks,gh issue view --comments,gh run view, and thegh pr-reviewextension). Re-running the exact same command lets it through, so the assistant can proceed after confirminggh apiis actually needed.Mechanizes the AIRULES.md rule that high-level
ghsubcommands are preferred andgh apishould be a fallback. State management follows the same pattern asclaude/hooks/warn_scripting_oneliners.py.Detection matches
ghat a shell segment head (after splitting on&&,||,;, newline,|outside quotes) and requires the first non-flag token afterghto be exactlyapi. This keepsgh pr view,github-api,gh api-helper,echo "gh api hi", and commit messages mentioninggh apifrom tripping the hook.Test plan
python3 -m doctest claude/hooks/warn_gh_api.py -v— 22 doctests passgh api ...denies, second run of same command allows,gh pr view/echo "gh api ..."pass throughpre-commit run --all-files— all hooks passpython3 -c "import json; json.load(open('claude/settings.json'))"— parses OK./scripts/deploy.sh, invokegh apiin a real Claude Code session and confirm the deny message appears, then verify the same command succeeds on the second attempt