Skip to content

fix: guard EnterWorktree core.bare parent checkout#1589

Open
YOMXXX wants to merge 1 commit into
obra:devfrom
YOMXXX:fix/enterworktree-core-bare-guard
Open

fix: guard EnterWorktree core.bare parent checkout#1589
YOMXXX wants to merge 1 commit into
obra:devfrom
YOMXXX:fix/enterworktree-core-bare-guard

Conversation

@YOMXXX
Copy link
Copy Markdown

@YOMXXX YOMXXX commented May 21, 2026

What problem are you trying to solve?

skills/using-git-worktrees/SKILL.md Step 1a tells agents to prefer native worktree tools such as Claude Code's EnterWorktree. That native-tool preference is still the right architecture, but issue #1546 documents an upstream Claude Code failure mode: EnterWorktree can write core.bare=true into the parent checkout's shared git config.

When that happens, the parent checkout looks like it lost its working tree. Git commands that require a work tree can fail with fatal: this operation must be run in a work tree, while the files themselves appear untouched. Because Superpowers actively steers Claude Code agents toward EnterWorktree, the skill should also tell agents how to detect and repair this parent-checkout symptom.

What does this PR change?

Adds a narrow Claude Code known-issue guard to using-git-worktrees Step 1a:

  • record PARENT_REPO_ROOT=$(git rev-parse --show-toplevel) before native worktree creation
  • after the native tool returns, check the parent checkout's core.bare
  • if it flipped to true, run git -C "$PARENT_REPO_ROOT" config --unset core.bare

This PR also adds a fast static regression test, plus a short design spec and implementation plan for the change.

Is this change appropriate for the core library?

Yes. using-git-worktrees is a core Superpowers skill, and this change protects a core workflow that the skill itself recommends. The guard is tool-specific to Claude Code, but it lives inside the existing native-tool branch rather than adding a new harness, dependency, or project-specific behavior.

What alternatives did you consider?

  1. Disable or discourage EnterWorktree. Rejected because adjust worktree handling and defer to harness tools when avail (PRI-974) #1121 established and validated the native-tool-first behavior; the upstream bug does not make manual git worktree add the right default.
  2. Add only a prose warning. Rejected because Step 1a (EnterWorktree preference) triggers Claude Code #58345 / #45201 — silent repo corruption on first worktree invocation #1546's symptom is recoverable, and agents need the exact git -C "$PARENT_REPO_ROOT" config --unset core.bare command.
  3. Add a runtime hook. Rejected as too broad for this PR; a few Step 1a instructions solve the immediate parent-checkout recovery problem without new runtime surface area.

Does this PR contain multiple unrelated changes?

No. It only addresses #1546: detecting and repairing the known Claude Code EnterWorktree parent-checkout core.bare symptom while preserving native worktree preference.

Existing PRs

#1121 introduced the native-tool-first Step 1a behavior and is prior art this PR preserves. #1167 was a closed PR around worktree triggering/consent behavior; this PR does not change triggering or consent behavior and does not bundle unrelated plugin/version changes. Search terms checked included 1546 EnterWorktree core.bare, core.bare worktree, EnterWorktree, and Claude Code 58345; no duplicate PR for this specific guard was found.

Environment tested

Harness (e.g. Claude Code, Cursor) Harness version Model Model version/ID
Claude Code CLI 2.1.141 default CLI model not exposed by CLI
Shell test runner macOS zsh n/a n/a
OpenCode plugin tests local test harness n/a n/a

New harness support (required if this PR adds a new harness)

Not applicable. This PR does not add support for a new harness.

Clean-session transcript for "Let's make a react todo list"
N/A - no new harness support.

Evaluation

  • Initial prompt: human partner asked to fork obra/superpowers, triage high-priority urgent issues, and implement valuable fixes. Step 1a (EnterWorktree preference) triggers Claude Code #58345 / #45201 — silent repo corruption on first worktree invocation #1546 was selected as the second narrow PR after the worktree write-boundary PR.
  • RED phase: bash tests/claude-code/test-enterworktree-core-bare-guard.sh failed against the existing skill with 5 missing assertions: no known-issue callout, no core.bare, no PARENT_REPO_ROOT, no parent core.bare check, and no repair command.
  • GREEN phase: after the skill change, the same test passed all 9 assertions.
  • After-change eval sessions: 3 direct Claude Code pressure prompts against the updated skill.

Pressure prompt results:

  1. Asked for the exact pre-check and post-check commands around EnterWorktree; Claude returned PARENT_REPO_ROOT=$(git rev-parse --show-toplevel) and the full git -C "$PARENT_REPO_ROOT" config --get core.bare / --unset core.bare block.
  2. Asked what command repairs a parent repo where git status fails after EnterWorktree; Claude returned git -C "$PARENT_REPO_ROOT" config --unset core.bare and explained that it clears the incorrect bare-repo flag.
  3. Asked whether this fixes the upstream Claude Code bug; Claude answered that Superpowers only detects/repairs the parent-checkout symptom and does not fix the upstream EnterWorktree implementation.

Verification commands run fresh before PR creation:

bash tests/claude-code/test-enterworktree-core-bare-guard.sh
bash tests/claude-code/test-worktree-path-policy.sh
bash tests/hooks/test-session-start.sh
bash tests/opencode/run-tests.sh
bash -n tests/claude-code/run-skill-tests.sh && bash tests/claude-code/run-skill-tests.sh --help
git diff --check HEAD~1 HEAD

All exited 0.

Rigor

  • If this is a skills change: I used superpowers:writing-skills and completed adversarial pressure testing (paste results below)
  • This change was tested adversarially, not just on the happy path
  • I did not modify carefully-tuned content (Red Flags table, rationalizations, "human partner" language) without extensive evals showing the change is an improvement

Adversarial pressure testing is summarized in the Evaluation section above. This PR does not modify Red Flags tables, rationalization lists, or "human partner" language.

Human review

  • A human has reviewed the COMPLETE proposed diff before submission

Human partner reviewed the fork compare diff for YOMXXX:fix/enterworktree-core-bare-guard and explicitly approved opening the PR.

@YOMXXX
Copy link
Copy Markdown
Author

YOMXXX commented May 21, 2026

Reviewer note

This PR is one of six small, independent PRs opened from the same triage pass. They can be reviewed and merged independently:

Focus for this PR: preserve the native-tool-first EnterWorktree flow while documenting and repairing the known Claude Code symptom where the parent checkout can get core.bare=true.

Review surface: using-git-worktrees Step 1a text plus static regression coverage. It does not disable EnterWorktree and does not change worktree triggering/consent behavior.

Verification: RED/GREEN static test for the guard, worktree path policy test, hook tests, OpenCode tests, and Claude Code pressure prompts for the exact repair command.

Risk to check: whether this belongs as a narrow known-issue guard in the skill, and whether the repair command is scoped safely to PARENT_REPO_ROOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant