[BUG] --worktree CLI flag rejects non-git repos without checking for WorktreeCreate hooks
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?
claude --worktree does an early git check and exits before consulting WorktreeCreate hooks:
$ cd ~/repo && claude --worktree test-session
Error: Can only use --worktree in a git repository, but /Users/tonyambrus/repo is not a git repository
However, the EnterWorktree tool (invoked mid-session) works correctly — it checks for WorktreeCreate hooks first via (minified function) YV1() before requiring git. The --worktree CLI flag should follow the same logic.
What Should Happen?
If WorktreeCreate hooks are configured, --worktree should proceed with hook-based worktree creation regardless of whether the cwd is a git repo. This is the documented behavior for the EnterWorktree tool: "Outside a git repository: delegates to WorktreeCreate/WorktreeRemove hooks."
Error Messages/Logs
Error: Can only use --worktree in a git repository, but /Users/tonyambrus is not a git repository
Steps to Reproduce
- Configure WorktreeCreate/WorktreeRemove hooks in settings.json
- cd to a non-git repo (e.g., Sapling/EdenFS)
- Run claude --worktree test-session
- Get rejected immediately with "Can only use --worktree in a git repository"
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.7.0
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Related to #28363 — hook-based worktrees have multiple issues. This bug prevents even creating them via the CLI flag.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗