r/ClaudeCode • u/BigB-69 • 7d ago
Bug / Issue PSA: isolation: "worktree" subagents rewrite your repo's .git/config behind your back
TL;DR: if your repo uses a relative core.hooksPath (Husky's .husky/_, or any repo-tracked hooks dir), spawning a subagent with isolation: "worktree" runs git config core.hooksPath <absolute path> from inside the new worktree. Worktrees share one config. Your main repo's .git/config just got edited. Three launches, three rewrites.
How it surfaced
My agents hash git config --list --local before and after every run. One came back with "config changed, wasn't me." I restored it, and it changed again. Then I spawned a subagent whose only job was to reply "ok": rewritten about a second later.
What it does (Claude Code 2.1.321, read from the minified binary)
- Reads
core.hooksPath. - If relative, resolves it against the repo root.
- Runs
git config core.hooksPath <abs>with the worktree as cwd and logs "Configured worktree to use hooks from main repository."
Good intent: keep hooks working in .claude/worktrees/agent-*. Wrong git. Plain git config in a linked worktree writes the shared .git/config. Only --worktree with extensions.worktreeConfig writes a per-worktree file. An already-absolute value causes no write; unset I haven't tested.
Who's exposed
- Husky v9 (
.husky/_is relative per its source). Logic says yes; not tested. - Anyone running
git config core.hooksPath scripts/hooks-style setups. - Anyone using
isolation: "worktree"in Agent calls, skills or subagent defs. No warning shown.
Why it's not cosmetic
- Wrong hooks, wrong tree. With an absolute path, a push from any worktree runs the main checkout's copy of the hook. A hook that does
cd "$(dirname "$0")/../.."now validates main, not your branch. Your branch passes because main passes. (Same week, separate bug: tests escaped a fake repo via inheritedGIT_DIRand rewrote my real one. Fun.) - Moved repo, dead hooks. The path points nowhere. As far as I know git skips a missing hooks dir quietly (untested). There goes your secret scan.
- Integrity checks scream. You'll blame your own agents first. I did.
Catch it
git config --show-origin --get core.hooksPath # relative? which file?
stat -f '%Sm' .git/config # Linux: stat -c '%y' .git/configRun it before and after a launch. Flipped to absolute with a matching mtime: that's this bug.
Prevent it
- Skip
isolation: "worktree"in these repos.git worktree addyourself and point the agent at it, or do reviews in a throwawaygit clone --no-hardlinks. - Enforce, don't ask. A CLAUDE.md rule is a suggestion. Use a
PreToolUsehook that deniesisolation: "worktree"on the Agent tool, plusgit pushandgit configwrites on Bash. - Gate pre-push and merge on
core.hooksPathbeing exactly the value you expect. - Don't "fix" it by setting the path absolute yourself. See wrong hooks, wrong tree.
Caveats: minified code, reproduced in a throwaway clone and with a no-op subagent. Not in the changelog or docs that I found. Could be fixed in a newer build or differ by platform. Run the two commands and see. Reporting it upstream.
Your agents are probably innocent. The harness did it.
•
u/AutoModerator 7d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Far_Reindeer8428 7d ago
we saw this with hooks, the worktrees share one config file and every agent that writes it wins. pinning core.hooksPath per worktree fixed it
2
u/Apprehensive-Cod699 7d ago
on the husky part, v9's husky command (what the prepare script runs) does git config core.hooksPath .husky/_ every time. so every npm install puts the relative value back and the next worktree subagent rewrites it again, in husky repos it would keep flipping, not happen once
1
u/Financial_Leader9701 6d ago
the "wasn't me" response is honestly the weirdest part
.git/config isn't even something you'd normally see in a PR diff
how did you first notice it was being changed? did the hooks just stop working?