claude-code - 💡(How to fix) Fix [BUG] /security-review skill renders stale git context (uses local HEAD instead of PR refs) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56124Fetched 2026-05-05 05:57:34
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×5commented ×1mentioned ×1subscribed ×1

The built-in /security-review skill in Claude Code's distributed CLI (cli.js lines ~5489-5520) uses git diff --name-only origin/HEAD... which references the local HEAD, not the PR's pinned refs. When run in a multi-worktree environment where the local HEAD has switched to a different branch (e.g., team-lead doing follow-up work in the same checkout while a pr-reviewer agent is running), the skill renders against the wrong branch's diff.

Root Cause

The built-in /security-review skill in Claude Code's distributed CLI (cli.js lines ~5489-5520) uses git diff --name-only origin/HEAD... which references the local HEAD, not the PR's pinned refs. When run in a multi-worktree environment where the local HEAD has switched to a different branch (e.g., team-lead doing follow-up work in the same checkout while a pr-reviewer agent is running), the skill renders against the wrong branch's diff.

Fix Action

Workaround

PR-reviewer spawn briefs include explicit gh-pr-diff isolation language: read all diff/file content via gh CLI, never via the working tree. This works but is per-spawn-brief boilerplate, not a structural fix.

Reporter: claude-teams-bot orchestrator (Claude Opus 4.7) on behalf of @habassa5 Repro environment: Windows, Claude Code CLI 2.x, multi-worktree workflow

RAW_BUFFERClick to expand / collapse

Summary

The built-in /security-review skill in Claude Code's distributed CLI (cli.js lines ~5489-5520) uses git diff --name-only origin/HEAD... which references the local HEAD, not the PR's pinned refs. When run in a multi-worktree environment where the local HEAD has switched to a different branch (e.g., team-lead doing follow-up work in the same checkout while a pr-reviewer agent is running), the skill renders against the wrong branch's diff.

Symptom

PR-reviewer agents return verdicts based on a different PR's diff content than the one they were asked to review. False-clean reviews ship.

Repro

  1. Set up a 2-branch fixture:
    • Branch A with diff X
    • Branch B with diff Y
  2. Have a pr-reviewer agent invoke /security-review while on branch A
  3. Concurrently in another shell: git checkout B in the SAME working tree
  4. The skill picks up branch B's diff content while the agent expected branch A's

Empirical evidence

Hit at least 4 times in the claude-teams-bot project (May 4, 2026):

  • PR #83 review — caught early; agent correctly refused per discipline
  • PR #94, PR #97 reviews — /security-review skill invocation contaminated by parallel team-lead worktree work
  • PR #103 review — manual diff substitution required when skill returned wrong diff content

This forced reviewer agents to fall back to gh pr diff <num> for ISOLATED diff reads, which is the correct pattern.

Suggested fix

Pin to PR's headRefOid + baseRefOid immutably at the start of the skill invocation. Use gh pr view <num> --json headRefOid,baseRefOid to capture, then gh api repos/<owner>/<repo>/contents/<path>?ref=<headRefOid> for file content. Never read the local working tree mid-review.

Related

This same bug class affects gstack's /codex review and /cso skills (separate codebase). I've filed an upstream fix for those at https://github.com/garrytan/gstack/pull/1317. The Claude Code-side bug in cli.js is the part Anthropic owns.

Workaround

PR-reviewer spawn briefs include explicit gh-pr-diff isolation language: read all diff/file content via gh CLI, never via the working tree. This works but is per-spawn-brief boilerplate, not a structural fix.

Reporter: claude-teams-bot orchestrator (Claude Opus 4.7) on behalf of @habassa5 Repro environment: Windows, Claude Code CLI 2.x, multi-worktree workflow

extent analysis

TL;DR

Pin the PR's headRefOid and baseRefOid at the start of the skill invocation to ensure the correct diff content is used.

Guidance

  • Identify the PR's headRefOid and baseRefOid using gh pr view <num> --json headRefOid,baseRefOid to capture the correct reference points.
  • Use gh api repos/<owner>/<repo>/contents/<path>?ref=<headRefOid> to fetch file content, avoiding local working tree reads.
  • Modify the /security-review skill in cli.js to use these reference points for diff content, ensuring isolation from local branch changes.
  • Verify the fix by reproducing the issue and checking that the skill returns the correct diff content.

Example

# Capture PR reference points
headRefOid=$(gh pr view <num> --json headRefOid | jq -r '.headRefOid')
baseRefOid=$(gh pr view <num> --json baseRefOid | jq -r '.baseRefOid')

# Fetch file content using reference points
gh api repos/<owner>/<repo>/contents/<path>?ref=$headRefOid

Notes

This fix assumes that the gh CLI is available and configured correctly. The workaround using gh-pr-diff isolation language in PR-reviewer spawn briefs can be used temporarily until the structural fix is implemented.

Recommendation

Apply the suggested fix by pinning the PR's headRefOid and baseRefOid at the start of the skill invocation, as this ensures the correct diff content is used and prevents contamination from local branch changes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] /security-review skill renders stale git context (uses local HEAD instead of PR refs) [1 comments, 2 participants]