[BUG] Background Tasks Fail to Detect Valid Git Repository
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?
Summary
Background tasks fail with "Background tasks require a git repository" error despite being in a valid git repository that is correctly detected by the main Claude Code session.
Environment
- OS: macOS 15.6.1 (Build 24G90)
- Platform: darwin
- Kernel: Darwin 24.6.0
- Git Version: 2.39.5 (Apple Git-154)
- Git Location: /usr/bin/git
Repository Information
- Working Directory:
/Users/Jonny/Documents/obsidian/trading - Git Repository Status: Valid and functional
- Main Session Detection: ✅ Correctly detected (
Is directory a git repo: Yes) - Background Task Detection: ❌ Fails with error
Expected Behavior
Background tasks should successfully detect the git repository, just as the main Claude Code session does.
Actual Behavior
Background tasks fail with a git repository detection error despite:
- Being in a valid git repository
- All git commands working correctly
- Main session detecting the repository properly
- No permission, symlink, or configuration issues
Additional Context
The repository has:
- Recent commits (verified with
git log) - Clean working tree
- Proper
.gitdirectory structure - All standard git operations working
Analysis
This appears to be a bug in the background task system's git detection logic. The background task spawning process uses different repository detection code than the main session, and this detection is failing even though:
- The repository is completely valid
- All git commands execute successfully
- The main Claude Code session correctly identifies it as a git repository
- No environmental or permission issues exist
Suggested Investigation
The background task system should use the same git repository detection logic as the main session, or inherit the repository status from the parent session rather than re-detecting independently.
Workaround
Currently, tasks must be run sequentially using the Task tool instead of background tasks, which significantly impacts performance when processing multiple independent items.
What Should Happen?
Background tasks should successfully detect the git repository, just as the main Claude Code session does.
Error Messages/Logs
Cannot launch remote Claude Code session.
Background tasks require a git repository. Initialize git or run from a git repository.
Steps to Reproduce
Steps to Reproduce
- Navigate to a valid git repository
- Verify git repository status:
``bash``
git rev-parse --is-inside-work-tree # Returns: true
git rev-parse --show-toplevel # Returns: /Users/Jonny/Documents/obsidian/trading
- Start Claude Code session (main session correctly detects git repo)
- Attempt to run background tasks using the background task syntax
- Observe error about missing git repository
Validation Performed
✅ Git Repository Validation
$ git rev-parse --is-inside-work-tree
true
$ git rev-parse --show-toplevel
/Users/Jonny/Documents/obsidian/trading
$ git rev-parse --git-dir
.git
$ git status
On branch main
nothing to commit, working tree clean
✅ Permissions Check
$ stat -f "%Sp %Su:%Sg" .git
drwxr-xr-x Jonny:staff
$ ls -la .git/
drwxr-xr-x@ 13 Jonny staff 416 Nov 30 19:49 .
drwxr-xr-x@ 22 Jonny staff 704 Nov 30 19:42 ..
-rw-r--r--@ 1 Jonny staff 11 Nov 30 19:47 COMMIT_EDITMSG
-rw-r--r--@ 1 Jonny staff 137 Nov 25 17:38 config
[... all files owned by user with proper permissions]
All .git subdirectories have proper permissions (755/drwxr-xr-x).
✅ Path Check (No Symlinks)
$ pwd
/Users/Jonny/Documents/obsidian/trading
$ pwd -P
/Users/Jonny/Documents/obsidian/trading
$ readlink -n "$(pwd)"
Not a symlink
No symlinks in the path - physical and logical paths are identical.
✅ Git Config Check
$ git config --list --local
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
Standard, valid git configuration with no unusual settings.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.58 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 13 comments on GitHub. Read the full discussion on GitHub ↗