[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_
13 Comments
I had this issue because I was unintentionally triggered background process mode, the new (to me) '&' command, that I had assigned as a prefix for my prompt snippets. Calling a prompt in the Claude console would also initiate background process mode.
However, the underlying issue - that background processes are unable to detect the git repo they are being called in, still stands.
I face the same issue - instructions for installation unclear. Changelog suggests
Added background agent support. Agents run in the background while you workbut using what appears to be the entryway to that feature& <my task>just results in an error even after adding the github app<img width="969" height="302" alt="Image" src="https://github.com/user-attachments/assets/1044f81e-a5b8-4638-ac68-04568d4bf621" />
I'm getting the same error
Same for me.
clauderunning in~/sandbox:Though it does work if one tells claude that is should be a background task
Have this same problem ((CC 2.0.76)
<img width="720" height="197" alt="Image" src="https://github.com/user-attachments/assets/afb0bf5b-345a-45a5-bc44-c5017ac079c8" />
I can work with this repo on the web claude code without issues, but I can't run background remote tasks from local claude code.
UPDATE:
Description
When trying to use
& PROMPTto launch a remote Claude Code session, I receive the error:Despite being in a valid git repository with a GitHub remote configured.
Environment
Repository Configuration
The .git directory exists and git status works correctly.
Debug Logs
Running claude --debug shows the URL parsing failure:
[DEBUG] Git remote URL: https://github.com/emssik/cc.kurs.web.git
[DEBUG] Could not parse repository from: https://github.com/emssik/cc.kurs.web.git
[DEBUG] Parsed repository: null from URL: https://github.com/emssik/cc.kurs.web.git
[DEBUG] Not in a GitHub repository, skipping path mapping update
Attempted Fixes
❌ Removed .git suffix: https://github.com/emssik/cc.kurs.web
❌ Changed to SSH format: git@github.com:emssik/cc.kurs.web.git
All formats produce the same parsing error.
Expected Behavior
Claude Code should recognize standard GitHub remote URLs and allow launching remote sessions via & PROMPT.
Additional Context
Claude Code on the Web works correctly with the same repository
GitHub App is installed and configured
User is authenticated with Max subscription
claude doctor reports no issues
Adding debug findings from a similar case (closed #16256 as duplicate):
Environment: Claude Code 2.0.76, macOS Darwin 25.1.0, private repo with standard HTTPS remote
Debug log shows the specific failure point:
The repo parsing works correctly:
But the GitHub app installation check receives HTTP 200 (success) and treats it as "unexpected", causing the failure.
Verified setup:
.github/workflows/claude.ymlexistsANTHROPIC_API_KEYsecret configuredgit rev-parse --is-inside-work-treereturns trueThe issue appears to be in
checkGithubAppInstallednot handling a successful 200 response correctly.User impact clarification:
This bug blocks the core workflow of handing off local sessions to claude.ai/code using
&. The intended use case is:&--teleportto switch between local and webThis is a major productivity workflow, not just a minor feature. The GitHub app check failing prevents any handoff to the cloud, completely blocking parallel web execution.
~I'm not sure if this helps anyone, but I was having this exact problem. GitHub app looked installed completely fine. GitHub actions were even in place and working. But I still got:~
~I managed to resolve it by going to https://claude.ai/code, selecting the repo and sending a prompt (Can literally be anything). Once I did that once. It then allowed me to use
&.~Edit: I clearly had a different promblem to this thread. Just leaving this comment here in case anyone lands on it via first google result like I did
This should now be resolved. Sorry about that!
Not to further hijack this thread, but your crossed out resolution is what worked for me as well for:
There is a bug that can be worked around by starting a web session for the repo. And then a background task can be started for that repo. Thanks!
I was getting this error and I had to do the above. I simply went to https://claude.ai/code and clicked on the repo name from the dropdown list. That's it. Then it worked.
Not always 😿
https://github.com/anthropics/claude-code/issues/16831
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.