EnterWorktree corrupts git index with marketplace repo entries (GIT_INDEX_FILE leak)
Description
Team session worktrees created via EnterWorktree have their git index overwritten with entries from the claude-plugins-official marketplace repo (~/.claude/plugins/marketplaces/claude-plugins-official/). The worktree index references blobs that don't exist in the project's object store, making git commit, git diff, and pre-commit hooks fail with fatal: unable to read <sha>.
This is the same root cause as #38181 (GIT_INDEX_FILE leaking into marketplace git operations), but triggered by team session worktree creation rather than git hooks.
Reproduction
- Start a
claude-teamsession that creates worktrees viaEnterWorktree - Two worktrees are created in
.worktrees/(e.g.,picard-XXXX,q-XXXX) - Attempt
git commitorgit statusin either worktree
Expected: Normal git operations against the project's files.
Actual: Index contains marketplace plugin files. Pre-commit hooks fail with:
error: invalid object 100644 01c5c1ce... for '.claude-plugin/marketplace.json'
fatal: unable to read d9c5ddb...
Evidence
The corrupted worktree index contains marketplace files instead of project files:
$ GIT_DIR=.../.git/worktrees/q-73c12fc5-autouse-and-ci git ls-files | head -5
.claude-plugin/marketplace.json
.github/scripts/check-marketplace-sorted.ts
.github/scripts/validate-frontmatter.ts
.github/scripts/validate-marketplace.ts
.github/workflows/close-external-prs.yml
The marketplace repo's own .git/index is missing — its content was moved into the worktree indexes:
$ ls ~/.claude/plugins/marketplaces/claude-plugins-official/.git/index
ls: cannot access '.../.git/index': No such file or directory
$ git -C ~/.claude/plugins/marketplaces/claude-plugins-official status
Changes to be committed:
deleted: .claude-plugin/marketplace.json
deleted: .github/scripts/check-marketplace-sorted.ts
[... all files shown as staged for deletion ...]
Key observations:
- Both team session worktrees (
.worktrees/picard-*,.worktrees/q-*) are affected identically — created at the same second - Agent worktrees (
.claude/worktrees/agent-*) created via a different code path are not affected git fsckshows missing blobs (marketplace blob SHAs) and invalid cache-tree pointers in both corrupted worktree indexes- Deleting the worktree index and running
git reset HEADrecovers the worktree
Root cause
Same as #38181: GIT_INDEX_FILE (or equivalent git environment state) leaks from the worktree creation context into a subprocess that runs git commands against the marketplace directory. The marketplace git operations write their file entries into the project worktree's index instead of their own.
Workaround
Delete the corrupted index and rebuild:
rm -f .git/worktrees/<name>/index
git reset HEAD
Related issues
- #38181 — Same root cause, triggered by git hooks instead of EnterWorktree
- #32793 — Marketplace git ops corrupt project git remote URL (same isolation failure)
- #33045 —
isolation: "worktree"has no effect for team agents
Environment
- Claude Code CLI (team session mode)
- Linux (Ubuntu 24.04)
- Git 2.43.0
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗