Problem
During multi-step sessions the main repo's local core.bare config flips to true, after which any git operation that needs a work tree fails with fatal: this operation must be run in a work tree (checkout, add, commit, branch creation all break). It recurred 5+ times in one session and needed repairing with git config core.bare false each time. Nothing is lost on GitHub (commits and branches are pushed and safe); only the LOCAL checkout is corrupted, but it interrupts every git step until repaired.
Design / approach
The flip correlates with two reproducible triggers:
npm install (notably npm install --package-lock-only) flipped core.bare to true mid-operation, surfacing as a failed git add immediately after.
- Spawning worktree-isolated subagents (the review subagents under
.claude/worktrees/agent-*).
Diagnostics gathered:
- The repo carries multiple long-lived worktrees (
webjs-prefetch, webjs-testgate), both valid.
extensions.worktreeConfig is NOT enabled.
- The root
package.json prepare runs git config core.hooksPath .hooks, yet the live core.hooksPath ends up reset to the absolute default (.git/hooks), suggesting git-config writes from a worktree or workspace context land on and reset the shared .git/config, the same surface where core.bare lives.
Hypothesis: git-config writes from inside a linked worktree (or from npm running a workspace lifecycle script while worktrees are registered), without extensions.worktreeConfig enabled, bleed into the shared config and reset core.bare (and core.hooksPath).
Candidate mitigations to evaluate:
- Enable
extensions.worktreeConfig true so per-worktree config writes cannot touch shared config.
- Make the root
prepare hook's git config write worktree-safe and idempotent, scoped so it cannot reset shared core.* keys.
- Keep a guard/repair as a backstop (the Claude Code skill already runs
git config core.bare false around git ops); the durable fix should remove the need.
Acceptance criteria
Problem
During multi-step sessions the main repo's local
core.bareconfig flips totrue, after which any git operation that needs a work tree fails withfatal: this operation must be run in a work tree(checkout, add, commit, branch creation all break). It recurred 5+ times in one session and needed repairing withgit config core.bare falseeach time. Nothing is lost on GitHub (commits and branches are pushed and safe); only the LOCAL checkout is corrupted, but it interrupts every git step until repaired.Design / approach
The flip correlates with two reproducible triggers:
npm install(notablynpm install --package-lock-only) flippedcore.baretotruemid-operation, surfacing as a failedgit addimmediately after..claude/worktrees/agent-*).Diagnostics gathered:
webjs-prefetch,webjs-testgate), both valid.extensions.worktreeConfigis NOT enabled.package.jsonpreparerunsgit config core.hooksPath .hooks, yet the livecore.hooksPathends up reset to the absolute default (.git/hooks), suggesting git-config writes from a worktree or workspace context land on and reset the shared.git/config, the same surface wherecore.barelives.Hypothesis: git-config writes from inside a linked worktree (or from npm running a workspace lifecycle script while worktrees are registered), without
extensions.worktreeConfigenabled, bleed into the shared config and resetcore.bare(andcore.hooksPath).Candidate mitigations to evaluate:
extensions.worktreeConfig trueso per-worktree config writes cannot touch shared config.preparehook'sgit configwrite worktree-safe and idempotent, scoped so it cannot reset sharedcore.*keys.git config core.bare falsearound git ops); the durable fix should remove the need.Acceptance criteria
core.bare(instrument git-config writes duringnpm installand a worktree spawn)core.barestaysfalseacrossnpm installand worktree subagent spawns with multiple worktrees registered