Skip to content

fix(agents): prefer-github-mcp hook can be bypassed by global flags or separators #138

Open

Description

@jvcorredor

Problem

.claude/hooks/prefer-github-mcp.sh matches (^|\s)gh\s+(pr|issue|search)(\s|$). That pattern misses several equivalent invocations:

  • a global flag before the subcommand, such as gh -R owner/repo pr view 1 or gh --repo x issue list;
  • a separator with no space before gh, such as true;gh pr view 1, x&&gh issue list or (gh pr checks);
  • an absolute path or wrapper, such as /opt/homebrew/bin/gh pr view or env gh pr view.

So the repo's "prefer GitHub MCP" policy is advisory, not enforced. The #137 review surfaced this. #137's hook test only certifies the hook as written.

Proposed fix

  • Tokenise the command, splitting on ;, &&, ||, |, ( and newlines. For each segment, find a gh executable (bare name or a path ending in /gh), skip global flags (-R/--repo <x> and --hostname <x>), and check the subcommand.
  • Extend scripts/test-agent-hooks.sh with negative cases for each bypass above.

Acceptance

  • Each listed form is denied, and gh run … and gh api … are still allowed.

Refs: #88
Refs: #90

Activity

  1. added
    bug
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions