[BUG] `GIT_INDEX_FILE` inherited from git hooks causes index corruption during plugin initialization

Resolved 💬 4 comments Opened Mar 24, 2026 by 0w0miki Closed Jun 1, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When Claude Code is launched from a git hook (e.g., post-commit), it inherits GIT_INDEX_FILE from the hook environment. During startup, Claude's plugin initialization runs git commands that write to this index, overwriting the project's index with plugin file entries.

Root Cause Analysis

  1. Git sets GIT_INDEX_FILE during hook execution
  2. Claude starts and initializes plugins (e.g., Atlassian at ~/.claude/plugins/cache/claude-plugins-official/atlassian/...)
  3. The plugin directory has no .git — git commands there inherit the parent git context
  4. Git commands run during plugin initialization inherit GIT_INDEX_FILE, pointing to the project's active index
  5. Plugin files (.claude-plugin/, skills/, CODE_OF_CONDUCT.md, etc.) get staged into the project's index, overwriting it entirely
  6. The index now references blob hashes that don't exist in the project's object store

Evidence

  • git ls-files --stage after corruption shows 28 plugin files replacing the original project files
  • fswatch on the worktree shows NO file creation on disk — only the index binary is modified
  • fswatch on the index shows IsFile Renamed events (git's atomic write pattern) during startup
  • Issue does NOT reproduce when running claude interactively (no GIT_INDEX_FILE set)
  • Issue does NOT reproduce after unset GIT_INDEX_FILE
  • --strict-mcp-config does NOT fix it — it's the plugin system, not MCP

What Should Happen?

The index of worktree should not be changed after commit.

Error Messages/Logs

> git status
fatal: unable to read 6e4407fffe7b08aaaa324c05d5961913ada66992

> git ls-files --stage
100644 6e4407fffe7b08aaaa324c05d5961913ada66992 0       .claude-plugin/marketplace.json
100644 1d85aa437958911c9f201a6c19163e581476e7c2 0       .claude-plugin/plugin.json
100644 7e2333aa15ac37d2fbb714e684f10f812f4a6994 0       .cursor-plugin/plugin.json
100644 8faed2e5a39aab6b11239b85a97ea9e1efd6cb8b 0       .mcp.json
100644 ea879c941c135821538e9c3c8070007ddb64cefa 0       CODEOWNERS
100644 1c8292dab0fccecd9df8eac9165df36fedf7faef 0       CODE_OF_CONDUCT.md
100644 27b6982fc12c6999a5a44302060d316c56323cca 0       CONTRIBUTING.md
100644 afd647276ae287009e5648865495ff888090af9e 0       LICENSE
100644 7e520b2d1644cd8c57f2383c2ba7132a080571cc 0       README.md
100644 d46b1bc74c141fbc686c76a0795d9e7321fdb8e1 0       SECURITY.md
100644 3bc6c0a3a0a3d0592e6b73ed02bae2ba73ca4dff 0       assets/logo.svg
100644 50508e27f9a9619489cd61a503c04f3462325519 0       gemini-extension.json
100644 dd1ec236c75580a0ceb4e6aef3c4183a8729bc37 0       images/atlassian_logo_brand_RGB.svg
100644 87d967c2a6347e8a5ad5cdcbc97dc632152fbb14 0       scripts/validate-template.mjs
100644 9bd7560a8ae1fec23e960763e322d113e35ab95a 0       skills/capture-tasks-from-meeting-notes/SKILL.md
100644 02cbaf0830f01afd1c82f01d3017223008645524 0       skills/capture-tasks-from-meeting-notes/references/action-item-patterns.md
100644 b02e8b5786f39138861ad78bad4d50f2d661846a 0       skills/generate-status-report/SKILL.md
100644 b71bb25990672ba1b820fa051285b317ca5acb1a 0       skills/generate-status-report/references/jql-patterns.md
100644 d6b835c84392a8037f1c6a4926974e6d978a4566 0       skills/generate-status-report/references/report-templates.md
100644 4d0f56a616508299d0dcd4d3a5cbbe2e2387c4fb 0       skills/generate-status-report/scripts/jql_builder.py
100644 61f42ed0985ccaf1e55fba940b36c74162601049 0       skills/search-company-knowledge/SKILL.md
100644 fc9f5623a383f51bbf87426fc03f1677c9672ec1 0       skills/spec-to-backlog/SKILL.md
100644 a40d326b7b7b7a84d7b26d781323de40b93bf1ec 0       skills/spec-to-backlog/references/breakdown-examples.md
100644 cddafd2cd9fc6085dceff7aa3fdffb252f0bc890 0       skills/spec-to-backlog/references/epic-templates.md
100644 d381843e48ab13e85533af8ea7017e62391e6582 0       skills/spec-to-backlog/references/ticket-writing-guide.md
100644 3b8665da8018ccdb03423e463f00ef31d81c15d5 0       skills/triage-issue/SKILL.md
100644 ff07c3119ccb4455a9610973e37da99ffdcd4e3f 0       skills/triage-issue/references/bug-report-templates.md
100644 8d70db65c8e578d050dd767b5cacc19af3d94570 0       skills/triage-issue/references/search-patterns.md

Steps to Reproduce

  1. Install a plugin (e.g., Atlassian)
  2. Create a post-commit hook that launches Claude in print mode:
#!/bin/sh
SHORT_HASH=$(git rev-parse --short HEAD)
tmux new-session -d -s "test-$SHORT_HASH" \
  "claude -p 'Say hello' --tools '' --strict-mcp-config"
  1. Make a commit (especially in a worktree)
  2. Run git status

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.81 (Claude Code)

Platform

AWS Bedrock

Operating System

macOS

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗