Repository navigation
Check the repo gh pr create runs in, in the pre-PR hook - #1531
sergiopaniego wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a137690. Configure here.
| # Only a command that runs gh pr create, not one that mentions it (a commit message, a grep) | ||
| RUNS_PR_CREATE='(^|[;&|(])[[:space:]]*gh[[:space:]]+pr[[:space:]]+create' | ||
| if ! [[ "$FLAGS" =~ $RUNS_PR_CREATE ]]; then | ||
| exit 0 |
There was a problem hiding this comment.
Heredoc erases later create command
Medium Severity
Flattening the full command and then cutting FLAGS at << also deletes a later gh pr create. RUNS_PR_CREATE then fails and the hook exits 0, so a heredoc-then-create sequence never gets a freshness check.
Reviewed by Cursor Bugbot for commit a137690. Configure here.
| # Only a command that runs gh pr create, not one that mentions it (a commit message, a grep) | ||
| RUNS_PR_CREATE='(^|[;&|(])[[:space:]]*gh[[:space:]]+pr[[:space:]]+create' | ||
| if ! [[ "$FLAGS" =~ $RUNS_PR_CREATE ]]; then | ||
| exit 0 |
There was a problem hiding this comment.
Create-command regex misses valid invocations
Medium Severity
RUNS_PR_CREATE only accepts gh at the start of FLAGS or after [;&|(]. An env assignment, a full path to gh, or a newline-separated command (flattened to spaces) leaves gh after other tokens, so the hook skips the check.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit a137690. Configure here.
|
Closing this: handling every way a command can be written turned the hook into a shell parser, which is more complexity than a freshness warning is worth. |


Summary
.claude/hooks/pre-pr-check.shalways checks the repository the Claude Code session runs in, so it blocksgh pr createfor other repositories with the freshness of the OpenEnv checkout. Opening a TRL PR from a TRL worktree (cd ~/trl/... && gh pr create -R huggingface/trl ...) was blocked as "755 commit(s) behind main", which was the state of the OpenEnv branch, not of the TRL one. This PR makes the hook check the repo the command actually runs in, and fixes two smaller issues:cd, else the sessioncwdfrom the hook input, and runs every git command withgit -C.--baseparsing: usedgrep -P, which macOS grep does not support (grep: invalid option -- Pon everygh pr create), so--basewas never read. Nowsed -E.--head: the freshness and "not from main" checks used the checked-out branch even when the PR is opened for another one with--head. They now use the--headbranch when given.Type of Change
Alignment Checklist
Before submitting, verify:
.claude/docs/PRINCIPLES.mdand this PR aligns with our principles.claude/docs/INVARIANTS.mdand no invariants are violated/pre-submit-pr(orbash .claude/hooks/lint.shand tests) and addressed all issuesRFC Status
Test Plan
Fed the hook the same JSON Claude Code sends, on macOS:
cd <trl worktree> && gh pr create -R huggingface/trl --base main --head async-kernels-install-docs ...withcwd= the OpenEnv checkout: the hook now checks the TRL worktree and reports the TRL branch's real state (checked in .../trl/.claude/worktrees/kernels-docs), instead of the OpenEnv branch.gh pr create --base main ...from an OpenEnv branch 755 commits behind main: still blocked, as before.grep: invalid option -- Panymore.Claude Code Review
N/A
Note
Low Risk
Changes only affect a local Claude Code bash hook for PR creation; no runtime, auth, or data-path impact.
Overview
Fixes
.claude/hooks/pre-pr-check.shso stale-branch and “no PR from main” rules apply to the repo and branchesgh pr createactually uses, not always the Claude session checkout.The hook now resolves
REPO_DIRfrom the lastcdbeforegh pr create(relative paths against sessioncwd) and runsgit -C "$REPO_DIR"for fetch and rev-list. Freshness compares$HEAD_BRANCH..origin/$BASEinstead ofHEAD, and block messages name the head branch and directory checked.Command parsing is tightened: backslash continuations are merged, quoted
--title/--bodyand heredocs are stripped before reading flags, and only lines that executegh pr create(not strings that merely mention it) are gated.--base/--headare read withgrep -oE/sed -Einstead ofgrep -Pso--baseworks on macOS;--head(includingowner:branch) drives head-branch checks when set. If parsed base/head look like options (**-*), the hook skips the check rather than passing bad args to git.Reviewed by Cursor Bugbot for commit 58a0d0e. Bugbot is set up for automated code reviews on this repo. Configure here.