fix(hooks): guard a nested member clone on any branch #167
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/guard-nested-clone"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
In an umbrella, a user may keep a member's clone on their own feature
branch, or stop it in the middle of a rebase. If an agent slips and
edits the clone instead of opening the member's worktree, the
main-checkout guard lets the edit through. The edit lands among the
user's own work and nothing warns either of them, although
AGENTS.md§ Members keeps the member's clone as it was. The guardrefused only while a main worktree was on its main branch. It exempted
every other state so that adoption could work, and a member clone fell
under the same exemption. Fixes #147.
The alternative was to document the gap in § Members. It was set aside
because it leaves the user's branch open to the edit.
What changed
The guard now refuses an edit in a main worktree that lies inside
another repository's working tree, whatever that worktree has checked
out: the main branch, another branch, or a detached HEAD. The refusal
names the enclosing repository and points to a worktree. A main
worktree that sits in no other repository keeps its exemption off its
main branch, as adoption needs. Ignored files still pass in both cases.
How to verify
From a fresh checkout of the branch, run
bash tests/agent-config/main-checkout-guard.sh. All 18 cases pass. Thenew cases build an umbrella with an ignored member clone on
feature/x, then on a detached HEAD. In both states an edit of theclone's
README.mdis refused, with "lies in the repository"; on
mainthe same events exit 0. Two pins show that anon-nested repository still passes on a detached HEAD and that an
ignored file in a nested clone still passes.
To reproduce by hand, put any repository with a commit under an
ignored path of another, switch it to a branch other than main, and
pipe a Claude Code
Editevent for one of its tracked files into.agents/hooks/main-checkout-guard.sh. It exits 2 on this branch and 0on
main.The README's Maintenance checks pass on
d3f36eb, including 303agent-configuration tests. Run through
run-sandboxed.shon main's codewith this branch's tests, the two regression tests fail at exit 0 and
the other 16 cases pass. Three rounds of change and security review
closed every medium finding. I did not exercise the guard inside a
live Claude Code, Codex or OpenCode session.
Considerations
A repository that sits inside another one without being an umbrella
loses the exemption off its main branch. One example is a home
directory kept as a non-bare Git repository. An adoption there is
refused and told to open a worktree, which it can do instead.
The two pins came in a review fixup rather than in a commit before the
fix. Both pass on main's code.
d3f36eb419tob47921f4b1