Skip to content

Commit af75182

Browse files
committed
Add PreToolUse hook blocking direct glab discussion/notes API access
Redirects agents to the glab-discussion CLI when they attempt to call glab api .../merge_requests/*/discussions|notes or glab mr view --comments, keeping thread IDs, resolve state, and inline diff positions in scope.
1 parent e6d6543 commit af75182

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ uv tool install glab-discussion
1414

1515
### Claude Code plugin
1616

17-
The repo includes a Claude Code plugin with a skill that teaches AI agents how to use `glab-discussion`.
17+
The repo includes a Claude Code plugin with:
18+
19+
- a **skill** that teaches AI agents how to use `glab-discussion`
20+
- a **PreToolUse hook** that blocks `glab api .../discussions|notes` calls and `glab mr view --comments`, redirecting the agent to use `glab-discussion` instead. This keeps thread IDs, resolve state, and inline diff positions in scope rather than letting the agent wrangle raw API JSON.
1821

1922
```bash
2023
claude plugin marketplace add fprochazka/glab-discussion
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CMD=$(jq -r '.tool_input.command // empty')
5+
6+
if [ -z "$CMD" ]; then
7+
exit 0
8+
fi
9+
10+
REASON="Reading or writing MR discussions/notes via \`glab\` is blocked (matched: \`glab api .../discussions|notes\` or \`glab mr view --comments\`). Use the \`glab-discussion\` CLI instead: \`glab-discussion read|write|diff|resolve|edit|delete\`. Run \`glab-discussion --help\` for usage, or load the \`glab-discussion\` skill."
11+
12+
if printf '%s' "$CMD" | grep -qE 'glab[[:space:]]+api\b.*merge_requests[^"'"'"']*/(discussions|notes)' \
13+
|| printf '%s' "$CMD" | grep -qE 'glab[[:space:]]+mr[[:space:]]+view\b.*--comments\b'; then
14+
jq -n --arg reason "$REASON" '{
15+
hookSpecificOutput: {
16+
hookEventName: "PreToolUse",
17+
permissionDecision: "deny",
18+
permissionDecisionReason: $reason
19+
}
20+
}'
21+
fi
22+
23+
exit 0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"hooks": {
3+
"PreToolUse": [
4+
{
5+
"matcher": "Bash",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/block-glab-api-discussions.sh",
10+
"timeout": 10
11+
}
12+
]
13+
}
14+
]
15+
}
16+
}

0 commit comments

Comments
 (0)