Background tasks fail in git worktrees: 'Background tasks require a git repository'

Resolved 💬 3 comments Opened Feb 8, 2026 by mobob Closed Feb 12, 2026

Bug Description

Running a background task (with &) inside a git worktree fails with:

Cannot launch remote Claude Code session.
Background tasks require a git repository. Initialize git or run from a git repository.

The directory IS a valid git repository — it's a git worktree.

Reproduction Steps

  1. Create a git worktree:

``bash
git worktree add ../my-worktree -b my-branch
cd ../my-worktree
``

  1. Verify it's a valid git repo:

``bash
git rev-parse --is-inside-work-tree # returns "true"
``

  1. Try to run a background task in Claude Code (e.g. append & to a command or use background task functionality)
  2. Observe the error

Root Cause

Git worktrees use a .git file (not a directory) that contains a pointer to the main repo:

# Regular repo:
.git/          ← directory

# Worktree:
.git           ← file containing "gitdir: /path/to/main/.git/worktrees/<name>"

The background task launcher likely checks for .git as a directory (e.g., fs.statSync('.git').isDirectory()), which fails for worktrees.

Expected Behavior

Background tasks should work in git worktrees. The fix would be to use git rev-parse --is-inside-work-tree or check for .git as either a file or directory.

Environment

  • macOS (Darwin 25.2.0)
  • Claude Code CLI (latest as of Feb 2026)
  • Git worktree created with git worktree add

View original on GitHub ↗

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