Use the base branch's AGENTS.md on pull requests (#2059)

Claude Code can load AGENTS.md as project instructions, as it does CLAUDE.md.
On pull requests the root AGENTS.md now comes from the base branch too. The
pull request's version is kept under .claude-pr/.

Co-authored-by: Claude <[email protected]>
This commit is contained in:
Mohamed Hegazy
2026-11-16 11:02:42 -08:00
committed by GitHub
co-authored by Claude
parent fe99289f39
commit 4413d301da
3 changed files with 31 additions and 1 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ This is general guidance for these event types — see [GitHub's documentation](
### Which files come from the base branch on pull requests
When the action runs against a pull request, it restores a fixed list of Claude configuration paths from the PR base branch before starting Claude: `.claude/`, `.mcp.json`, `.claude.json`, `.gitmodules`, `.ripgreprc`, `CLAUDE.md`, `CLAUDE.local.md`, and `.husky/`. Paths in that list that do not exist on the base branch are removed, and the PR-authored versions are kept under `.claude-pr/` for reference only.
When the action runs against a pull request, it restores a fixed list of Claude configuration paths from the PR base branch before starting Claude: `.claude/`, `.mcp.json`, `.claude.json`, `.gitmodules`, `.ripgreprc`, `CLAUDE.md`, `CLAUDE.local.md`, `AGENTS.md`, and `.husky/`. Paths in that list that do not exist on the base branch are removed, and the PR-authored versions are kept under `.claude-pr/` for reference only.
Everything else in the working tree — including `package.json`, lockfiles, `Makefile`, `node_modules/`, and formatter/linter config files — stays at the PR head, apart from the files described below. If a hook, `apiKeyHelper`, or `statusLine` command in your base-branch `.claude/settings.json` runs a package-manager script (`bun run …`, `npm run …`, `yarn …`, `pnpm run …`), a `make` target, a repo-relative script, or a tool that loads executable project config, that command resolves through files the pull request supplies. Keep such commands self-contained: invoke the tool directly with a pinned version and pass its configuration on the command line (for example `bunx [email protected] --no-config --write .` rather than `bun run format`).
+1
View File
@@ -31,6 +31,7 @@ export const SENSITIVE_PATHS = [
".ripgreprc",
"CLAUDE.md",
"CLAUDE.local.md",
"AGENTS.md",
".husky",
];
+29
View File
@@ -148,6 +148,35 @@ describe("restoreConfigFromBase", () => {
);
});
test("removes an AGENTS.md that only the PR has", () => {
writeRepoFile("AGENTS.md", "pr agent instructions\n");
git(["add", "AGENTS.md"]);
git(["commit", "-m", "pr adds agents file"]);
const restored = restoreConfigFromBase("main");
expect(restored).toContain("AGENTS.md");
expect(existsRepoFile("AGENTS.md")).toBe(false);
expect(readRepoFile(".claude-pr/AGENTS.md")).toBe(
"pr agent instructions\n",
);
});
test("uses the base branch's AGENTS.md, also through a CLAUDE.md link", () => {
setupSymlinkedMainBranch();
writeRepoFile("AGENTS.md", "pr agent instructions\n");
git(["commit", "-am", "pr edits agents file"]);
restoreConfigFromBase("main");
expect(readRepoFile("AGENTS.md")).toBe("shared agent instructions\n");
expect(readRepoFile("CLAUDE.md")).toBe("shared agent instructions\n");
expect(readRepoFile(".claude-pr/AGENTS.md")).toBe(
"pr agent instructions\n",
);
expect(git(["diff", "--cached", "--name-only"])).toBe("");
});
test("records dangling links as placeholders, including top-level ones", () => {
setupSymlinkedMainBranch();