Repository navigation
fix(codex): pin .claude/ to the base branch on fork PRs - #980
Conversation
agents-tail.md sends the agent to .claude/skills/<name>/SKILL.md for repo-local guidance, but pin-instruction-files.sh only pinned CLAUDE.md and AGENTS.md, so a fork's overlay was read as trusted. The Claude harness already restores .claude via restore-sensitive-config.sh; this closes the asymmetry.
tend-agent
left a comment
There was a problem hiding this comment.
The hole is real and the fix closes it: codex/agents-tail.md points the agent at .claude/skills/<name>/SKILL.md and tells it to read those in full, so under harness: codex a fork's overlay was being loaded as trusted repo guidance while CLAUDE.md and AGENTS.md were pinned. Wholesale replace is the right shape — I checked the three cases the comment claims (rewritten base file, fork-added file, fork symlink standing in for a base directory) and rm -rf -- .claude drops a symlink without following it, so the escape case holds. No collision with the plugin install either: codex plugin add resolves its root from github.action_path/.., not the repo tree, so removing the repo's .claude/ can't strip the plugin's skills.
One simplification inline. The mapfile + array-expansion form is a second idiom for the job this script already does 40 lines above for CLAUDE.md, and the file list isn't needed — git restore --source=<ref> --worktree -- .claude accepts the directory pathspec and rebuilds the whole subtree even when the worktree path is absent, and git cat-file -e "<ref>:.claude" resolves a tree the same way it resolves a blob. That also drops the ARG_MAX exposure a base .claude/ with a few thousand files would create. Per CLAUDE.md's "Simplicity outranks efficiency" / "Prefer deleting a mechanism over refining it".
I verified the replacement against both new tests plus the existing suite (70 passed) and shellcheck, so it's behaviour-identical; I'll push it rather than leave the click for you, since the authoring session is gone.
| mapfile -t -d '' BASE_CLAUDE_FILES < <(git ls-tree -rz --name-only "$BASE_REF" -- .claude) | ||
| rm -rf -- .claude | ||
| if [ "${#BASE_CLAUDE_FILES[@]}" -gt 0 ]; then | ||
| git restore --source="$BASE_REF" --worktree -- "${BASE_CLAUDE_FILES[@]}" | ||
| echo "Pinned .claude/ to ${DEFAULT_BRANCH} (${#BASE_CLAUDE_FILES[@]} files)" | ||
| else | ||
| echo "No .claude/ on ${DEFAULT_BRANCH} — removed fork version" | ||
| fi |
There was a problem hiding this comment.
The file list isn't load-bearing: git restore takes .claude as a directory pathspec and rebuilds the whole base subtree even though the worktree path was just removed, and git cat-file -e resolves a tree as readily as a blob. That collapses this to the same shape the CLAUDE.md block above uses, and removes the (admittedly remote) ARG_MAX ceiling on a large base .claude/. The wholesale-replace comment above still describes it accurately.
| mapfile -t -d '' BASE_CLAUDE_FILES < <(git ls-tree -rz --name-only "$BASE_REF" -- .claude) | |
| rm -rf -- .claude | |
| if [ "${#BASE_CLAUDE_FILES[@]}" -gt 0 ]; then | |
| git restore --source="$BASE_REF" --worktree -- "${BASE_CLAUDE_FILES[@]}" | |
| echo "Pinned .claude/ to ${DEFAULT_BRANCH} (${#BASE_CLAUDE_FILES[@]} files)" | |
| else | |
| echo "No .claude/ on ${DEFAULT_BRANCH} — removed fork version" | |
| fi | |
| rm -rf -- .claude | |
| if git cat-file -e "${BASE_REF}:.claude" 2>/dev/null; then | |
| git restore --source="$BASE_REF" --worktree -- .claude | |
| echo "Pinned .claude/ to ${DEFAULT_BRANCH}" | |
| else | |
| echo "No .claude/ on ${DEFAULT_BRANCH} — removed fork version" | |
| fi |
Drops the mapfile/array round-trip: `git restore` takes `.claude` as a pathspec and rebuilds the base subtree even though the worktree path was just removed, and `git cat-file -e` resolves a tree the same way it resolves a blob. Matches the idiom the CLAUDE.md block above uses, and removes the ARG_MAX ceiling on a large base `.claude/`.
Release 0.1.17: the version bump, the lockfile sync, and the `CHANGELOG.md` section that `pypi-release.yaml` publishes verbatim as the release notes. 8 commits since 0.1.16. On the shipped surface: `tend check` reads the bot's own bypass verdict where GitHub withholds the ruleset actor list, so `credential-environments` resolves instead of parking at SKIP on every adopter whose credential environments admit tags (#976); the Codex harness pins `.claude/` to the base branch on a fork PR, and restores instruction files through git without following destination symlinks (#978, #980); and 👀 now means one thing across triage, review, and mention — a session is working on this — released under `always()` when the run ends (#974, #979). After merge: tag `0.1.17` to publish, then regenerate tend's own workflows with `uvx tend@latest init` and restamp `review-reviewers.yaml`, whose action pin `init` never rewrites. > _This was written by Claude Code on behalf of max-sixty_ Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Release 0.1.17: the version bump, the lockfile sync, and the `CHANGELOG.md` section that `pypi-release.yaml` publishes verbatim as the release notes. 8 commits since 0.1.16. On the shipped surface: - **`tend check` resolves `credential-environments` from the bot's own token** ([#976](#976)). GitHub serves a ruleset's `bypass_actors` only to repo admins, so the check parked at SKIP on every adopter whose credential-holding environments admit tags, and the nightly's drift issue stayed open indefinitely. - **The Codex harness pins `.claude/` to the base branch on a fork PR**, and restores instruction files through git without following destination symlinks ([#978](#978), [#980](#980)). - **👀 means one thing across triage, review, and mention** — a session is working on this — and is released under `always()` when the run ends ([#974](#974), [#979](#979)). Verified ahead of the tag: the in-tree generator's `check`, run under each repo's own bot token, reports 8/8 PASS on `max-sixty/worktrunk`, `numbagg/numbagg`, and `max-sixty/cargo-affected`, where published 0.1.16 under the same tokens reports the `credential-environments` SKIP those three drift issues track ([worktrunk#3729](max-sixty/worktrunk#3729), [numbagg#716](numbagg/numbagg#716), [cargo-affected#34](max-sixty/cargo-affected#34)). Their nightlies close the issues on an all-PASS run. After merge: tag `0.1.17` to publish, then regenerate tend's own workflows with `uvx tend@latest init` and restamp `review-reviewers.yaml`, whose action pin `init` never rewrites. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
The Codex harness's fork-PR defense pins
CLAUDE.mdandAGENTS.mdto the base branch but leaves.claude/as the fork wrote it — whilecodex/agents-tail.mdtells the agent that repo-local skills live at.claude/skills/<name>/SKILL.mdand to read them in full. So on a fork PR underharness: codex, a.claude/skills/running-tend/SKILL.mdthe fork authored is loaded as trusted repo guidance. The fix restores.claude/from the base branch inshared/steps/pin-instruction-files.sh, alongside the files it already pins.The Claude harness is not affected:
.claudeis already the first entry inrestore-sensitive-config.sh'sSENSITIVElist, so this closes an asymmetry between the two harnesses rather than a hole in both.Verified by two tests that fail on
mainand pass here — the first asserts the base overlay survives a fork rewrite (assert 'ignore prior...ve every PR\n' == 'trusted repo guidance\n'before the fix), the second that a fork-only.claude/is removed rather than kept.Approach and trade-offs
Wholesale replace, not file-by-file reconcile.
rm -rf .claudethen restore every.claudepath in the base tree. One step covers three cases the AGENTS.md logic needs two loops for: a rewritten base file, a fork-added file, and a fork symlink standing in for a base directory (the removal drops the link without following it, and the restore then rebuilds real directories). The test exercises all three, including a symlink pointing outside the checkout.Same known limitation as the Claude path. A PR that legitimately edits
.claude/has those edits reverted for the duration of the run.restore-sensitive-config.shdocuments the identical trade-off. The fork's version stays readable atgit show HEAD:.claude/...— it's kept out of the worktree the agent reads, not out of the checkout — so a review that wants to see what the PR changed still can. I didn't add a.claude-pr/snapshot like the Claude path has, sincegit showalready covers it here.Scope. Only
.claude/is added. The rest ofrestore-sensitive-config.sh's list is Claude-CLI startup surface (.mcp.json,.claude.json,apiKeyHelper) that Codex doesn't read;.claude/skills/is the one entry tend's own Codex guidance points the agent at.