Git-repo detection cached at session start — agent worktree isolation permanently fails after in-session git init

Open 💬 0 comments Opened Jun 13, 2026 by achatt89

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?

Agent/subagent isolation: "worktree" always errors Cannot create agent worktree: not in a git repository and no WorktreeCreate hooks are configured, and the startup banner shows Is a git repository: false — even though the directory is a normal git repo and the git CLI works for every Bash command (commits, branches, merges all succeed).

Root cause (evidence): The "is this a git repository?" check appears to be evaluated once at session/process start and cached, never refreshed when the directory later becomes a repo. In my case the Claude Code session opened the directory ~6h before the repo was created in-session:

  • session/project dir created: Jun 12 19:20
  • .git created / first commit: Jun 13 01:11 (~6h later, by an in-session scaffolding step)

A sibling repo opened after it was already a git repo works natively with zero config. Same machine, same git, no hooks.

What Should Happen?

Detection re-evaluates (or is computed lazily) so a repo created mid-session is recognized; worktree isolation works without restarting.

Error Messages/Logs

Steps to Reproduce

  1. Start Claude Code in an empty directory.
  2. In-session, git init + commit (or run any scaffolding that does so).
  3. Spawn a subagent with isolation: "worktree" → fails with "not in a git repository". The Bash tool's git works the whole time.

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.176

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Workaround: Restart the session after the repo exists.

View original on GitHub ↗