Repository navigation
Description
Summary
An autonomous Claude Code PR-review loop posted a stray comment to a stranger's
repository under the account owner's identity, caused by a fabricated (hallucinated)
GitHub GraphQL node id. This issue documents the incident, the root cause, and a set of
hardened agent rules that should be folded into the standard AGENTS.md (expanding the
existing "PR Review Etiquette" section) so every project inherits them.
What happened
While an agent was autonomously driving a Copilot PR-review cycle on the owner's own repo
(ptr727/PlexCleaner PR #869 — commit → push → reply → resolve → re-request → poll), it
emitted a throwaway GraphQL mutation with a hand-fabricated thread node id and a literal
body of placeholder, with output suppressed:
gh api graphql -f query='mutation($t: ID!, $b: String!){
addPullRequestReviewThreadReply(input:{pullRequestReviewThreadId:$t, body:$b}){ comment{ id } } }' \
-F t="PRRT_kwDODvuuzM6SFvx0" -F b="placeholder" >/dev/null 2>&1 || trueThe id was never returned by any query in the session — the model invented it. GitHub
resolves node ids globally, so the fabricated id resolved to a real CodeRabbit review
thread on an unrelated third-party repo (mankatcheung/job-finder PR #15). The mutation
succeeded, posting placeholder as the owner. Because the call's output was suppressed
with >/dev/null 2>&1 || true, the agent assumed it had "failed harmlessly" and moved on —
the failure was only ever in the agent's assumption, never in the API call.
The stray comment has since been deleted, and an audit (GitHub event feed + full local
session-log grep) confirmed it was a single, isolated occurrence.
Root cause
- Fabricated GitHub id. The agent hand-typed a
PRRT_…literal instead of capturing it
from a live query. Node ids resolve globally, so a guessed id can silently land on a real
object in a completely different repo/owner. - Suppressed write output.
>/dev/null 2>&1 || trueon a mutation hid the result, so a
"success" was misread as a harmless failure. - No repo-scoping guardrail. Nothing constrained the agent to the project's own repo, so
a cross-repo write was possible at all.
Proposed rules (added to the owner's global ~/.claude/CLAUDE.md, proposed for AGENTS.md)
These were added verbatim to global guidance and are proposed as an expansion of the standard
AGENTS.md:
🚫 Never interact with a repo other than the current project's own repo.
The only repo an agent may write to is the repo of the project it is working in (its
configuredorigin). "Write" = anything that mutates GitHub or acts as the user: PR/issue/
review comments and replies, thread resolves, review requests,gh pr/gh issue
create/merge/close, pushes,gh apimutations, or any-X POST/PUT/PATCH/DELETE. Reading
public data from other repos is fine. Touching any other repo — even another repo owned
by the same user — requires explicit, per-repo permission from the human first, in the
current conversation. No "harmless" test calls, no exceptions.Never fabricate or guess a GitHub id. Every node id / numeric id passed to a write
(PRRT_…thread ids,PR_…, comment/review ids,BOT_…) MUST come from a live query in
the same session, captured into a variable and used directly. Never hand-type a literal
id, never pattern-guess one, never reuse one from memory or an example. GitHub resolves ids
globally, so a guessed id can silently land on a real object in a different repo.Never suppress the output of a write. Do not append
>/dev/null 2>&1,|| true, or
|| echo …to a mutation/gh apiwrite. Show and confirm its result. A write that appears
to fail must be verified, never assumed to have failed harmlessly — the failure may be
on the agent's end while the call actually succeeded remotely.
The runbook's own reply-thread example was also corrected: it previously modeled the footgun
(-F t="PRRT_..." literal) and now demonstrates capturing $TID from a live
reviewThreads(first:100) query instead.
Ask
Fold these three rules into the standard AGENTS.md (as an expansion of the "PR Review
Etiquette" section) so all downstream projects inherit the repo-scoping guardrail, the
never-fabricate-ids rule, and the never-suppress-write-output rule.
Activity
ptr727 commentedon Jul 20, 2026
Follow-up: credential-layer defense-in-depth (token scoping)
The agent rule above is the primary control. This note captures the optional
credential-layer hardening discussed after the incident, so it can be referenced from
AGENTS.mdas defense-in-depth. None of this replaces the rule — it only caps what a futurerule violation could physically reach.
Why the credential mattered here
The incident write succeeded because the account's active token is an OAuth token
(
gho_…, fromgh auth login) carrying the classicreposcope. Classicrepoisall-or-nothing: it can write to every repo the account can reach, including arbitrary
public third-party repos. That is what let a fabricated node id land on a stranger's repo.
Key constraint: no GitHub token can be scoped to "only the current project." The tightest
a token expresses is a specific list of repositories. So token scoping complements, never
replaces, the repo-scoping agent rule.
Option 1 — fine-grained PAT limited to owned repos
Replace/augment the classic-scope token with a fine-grained PAT (
github_pat_…) whoserepository access is "All repositories owned by ". It then structurally cannot
write to a repo you don't own (hard
403), while still covering the full multi-repoworkflow across your own repos. Grant only the permissions the runbook uses: Metadata (RO,
mandatory), Contents (RW, pushes), Pull requests (RW, review comments/threads/requests),
Issues (RW), plus Actions (RW) / Workflows (RW) / Administration (RW) only if the project
dispatches workflows, edits
.github/workflows/*, or manages rulesets.Trade-offs: fine-grained PATs expire (~1 yr, must renew); org repos need the org to enable +
approve fine-grained PATs; occasional API-coverage gaps vs classic — validate the review
runbook once before trusting it.
Option 2 — directory-scoped active token (for people who work on own + 3rd-party repos on one machine)
ghhas no native per-directory auth (its stored token is global), butghhonorsGH_TOKEN/GITHUB_TOKENover the stored token, so "which token is active" can be made todepend on the working directory:
direnv— a per-directory.envrcthatexport GH_TOKEN=…. Scopes your interactiveshell. Caveat: direnv hooks interactive shells; an agent's non-interactive Bash
subshell may not trigger the auto-load, so this protects the human but not necessarily the
agent.
env(recommended for the agent) — because Claude Code settingsare per-project, a git-ignored
.claude/settings.local.jsoncan inject a repo-scoped tokenfor that directory's sessions:
{ "env": { "GH_TOKEN": "github_pat_scoped_to_this_projects_repos..." } }token can reach. Own-repo checkouts get an owned-repos PAT; a third-party checkout gets a
PAT scoped to just that repo (or a read-only token). This directly neutralizes the incident:
a fabricated id in one project's session would
403on any repo outside that token's scope.Secret hygiene: both approaches put a token in a file — keep it in
.claude/settings.local.json/
.envrc(git-ignored), never in committedsettings.json; a keyring/pass-backed fetch iscleaner if plaintext-on-disk is unacceptable.
Suggested
AGENTS.mdphrasingAgent write-safety: repo-scope + never-fabricate-id + never-suppress-…
ptr727 commentedon Jul 20, 2026
Addressed on
developvia #367 (8cef2f6). All three root causes now have a behavioral rule, and the first three also have a mechanical guard in the PreToolUse hook:PR_/PRRT_/BOT_…node id in a-Fvalue instead of a$variable.ghwrite whose output is discarded or forced to success (>/dev/null,2>/dev/null,&>/dev/null,|| true,|| :,|| echo).ghwrite with an explicit-R/repos/<owner>/<repo>target outside the checkout'sorigin.Three layers, by design: the carried
AGENTS.mdsection (fleet), the per-machine~/.claude/CLAUDE.mdsection (every session, including pre-sync and ad-hoc work, tracked in #365), and the PreToolUse hook (mechanical, and it fires even in autonomous / bypass-permissions sessions — the incident's exact condition). Prose is paired with the hook deliberately: prose is the layer that already failed here (the incident happened under a Verification Discipline section).The hook is precision-leaning — it denies the specific dangerous shapes with high confidence rather than gating every write, and it does not false-deny a suppression token merely quoted inside a
--body/--title. It was driven through an adversarial review that caught two real enforcement gaps before merge (a|| :tail that never matched, and a quoted-R "owner/repo"that bypassed the cross-origin check); both are fixed and covered by self-tests.Remaining optional defense-in-depth: a fine-grained PAT scoped to owned repos (a hard
403on any non-owned repo). Kept out-of-band as per-machine credential setup, not a carried rule.Holding open until the
develop → mainpromotion and first downstream propagation.ptr727 commentedon Jul 23, 2026
Resolved. The three-layer defense shipped in #367 - the carried
AGENTS.mdrules, the per-machine~/.claude/CLAUDE.mdsection, and the PreToolUsegh-write-guardhook - is onmainand propagated to the first downstream repo (Financial-Modeling). The optional fine-grained-PAT credential hardening remains out-of-band per the decision. Per-box installer rollout continues in #365. Closing.Declare Python and Codecov on Blog's Registry Entry (#2263)