--worktree fails in non-git repos even with WorktreeCreate/WorktreeRemove hooks configured

Resolved 💬 2 comments Opened Mar 26, 2026 by GLinnik21 Closed Mar 26, 2026

Description

When WorktreeCreate and WorktreeRemove hooks are configured, running claude -w in a non-git repository fails with:

Error: Can only use --worktree in a git repository, but /path/to/project is not a git repository

The git repo check runs before the hooks are invoked, making it impossible to use custom worktree behavior in non-git repositories.

Expected behavior

Per the docs:

Worktree isolation works with git by default. For other version control systems like SVN, Perforce, or Mercurial, configure WorktreeCreate and WorktreeRemove hooks to provide custom worktree creation and cleanup logic. When configured, these hooks replace the default git behavior when you use --worktree.

When WorktreeCreate/WorktreeRemove hooks are present, the git repository check should be skipped and the hooks should be invoked instead.

Steps to reproduce

  1. Configure WorktreeCreate and WorktreeRemove hooks in settings
  2. Run claude -w from a directory that is not a git repository
  3. Observe the error — hooks are never executed

Tested settings locations

Hooks were tested in all three settings files — same error in each case:

  • ~/.claude/settings.json (user global)
  • .claude/settings.json (project)
  • .claude/settings.local.json (project local)

Minimal reproduction config

{
  "hooks": {
    "WorktreeCreate": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo /tmp/test-worktree",
            "timeout": 60
          }
        ]
      }
    ],
    "WorktreeRemove": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "true",
            "timeout": 30
          }
        ]
      }
    ]
  }
}

Environment

  • macOS 26.3.1 (a)
  • Claude Code v2.1.84

View original on GitHub ↗

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