Background agents should handle permission denials gracefully and/or delegate to foreground
Problem
When background agents (launched via Task tool with run_in_background: true) encounter tools that require user permission, they fail silently with:
Permission to use Write has been auto-denied (prompts unavailable).
Permission to use Bash has been auto-denied (prompts unavailable).
The agents continue trying to make progress but can't, and eventually the Claude Code process can crash (exit code 1). The user has no visibility into why the agents failed until they dig through the JSONL output files.
Current Behavior
- Background agent needs a permission (e.g.,
Write,Bash) - Permission isn't pre-approved in settings
- Agent can't prompt user (running in background)
- Tool returns error: "Permission to use X has been auto-denied (prompts unavailable)"
- Agent may retry or try alternatives, but remains stuck
- No notification to user or foreground session
- Eventually crashes or times out silently
Proposed Solutions
Option A: Permission Delegation (Preferred)
Allow background agents to request permissions through the foreground session:
- Background agent encounters permission block
- Agent sends permission request to foreground:
````
Background Agent "task-abc123" requests permission:
Tool: Write
Path: /path/to/file.md
Reason: Creating implementation plan
[Allow Once] [Allow for Session] [Deny]
- User responds in foreground
- Permission decision relayed to background agent
- Agent continues or handles denial gracefully
Option B: Graceful Failure with Clear Messaging
If delegation isn't feasible, background agents should fail fast and clearly:
- Background agent encounters permission block
- Agent immediately terminates with structured error:
``json``
{
"status": "failed",
"reason": "permission_denied",
"tool": "Write",
"message": "Background agent requires 'Write' permission which is not pre-approved",
"suggestion": "Add 'Write' to permissions.allow in settings, or run task in foreground"
}
- Foreground session notified immediately:
```
Warning: Background task "task-abc123" failed: Permission denied for 'Write'
To fix: Add "Write" to your .claude/settings.local.json permissions.allow array
```
Option C: Pre-flight Permission Check
Before launching a background agent, check if all tools in the agent's likely toolset have permissions:
Warning: This background task may need these permissions that aren't pre-approved:
- Write (for creating/editing files)
- Bash (for shell commands)
[Approve All for This Task] [Configure Settings] [Run in Foreground Instead]
Use Case
Running parallel worker agents that need to:
- Write plan files
- Execute bash commands (git, jq, server management)
- Edit code files
These are legitimate development workflows that benefit from parallelization but currently require manually pre-approving every possible tool/command pattern.
Environment
- Claude Code version: 2.1.1
- Running in: VSCode extension
- Task tool with
run_in_background: true
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗