Add 'list running background tasks' tool for post-compaction recovery
Problem
After context compaction (/compact), Claude loses references to background tasks (shell commands, agents) that were launched earlier in the conversation. The runtime's status line correctly shows them (e.g., 2 background tasks), but Claude has no way to enumerate or interact with them because the task IDs were in the compacted conversation history.
Reproduction Steps
- Start a long Claude Code session
- Launch background tasks (
run_in_background: trueon Bash or Agent tools) - Continue working until context fills up
- Run
/compactor let auto-compaction trigger - Ask Claude "how many background tasks are running?"
- Claude cannot find them — the task IDs were lost during compaction
Current Behavior
- Claude checks
TaskList(only tracks todo items, not background tasks) - Claude checks process list / agent output files (no reliable mapping)
- Claude confidently says "nothing is running" while the status line shows
2 background tasks - User must manually identify and kill stale tasks
Expected Behavior
Claude should be able to enumerate all running background tasks at any point in the conversation, regardless of compaction state.
Proposed Solution
Add a tool (or extend TaskList) that returns all active background tasks tracked by the runtime:
{
"name": "ListBackgroundTasks",
"description": "Lists all running background tasks (shell commands, agents) with their IDs, descriptions, and status",
"returns": [
{
"task_id": "bcmft34tg",
"type": "bash",
"description": "Check Azure App Service logs for startup errors",
"status": "running",
"started_at": "2026-03-15T14:30:00Z",
"output_file": "/tmp/claude-1000/.../tasks/bcmft34tg.output"
}
]
}
This would allow Claude to:
- Discover orphaned tasks after compaction
- Report accurate status to users
- Clean up stale tasks proactively
- Include task IDs in compaction summaries
Workarounds
Current workarounds (all fragile):
- User manually checks status line and kills tasks
- Before compacting, Claude notes background task IDs in the summary (easy to forget)
- User tells Claude about tasks it can't see
Environment
- Claude Code on WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2)
- Observed with both Bash
run_in_backgroundand Agentrun_in_backgroundtasks - Status line correctly tracks tasks — the data exists in the runtime, just not exposed to Claude
Impact
This affects any long-running session that uses background tasks and hits compaction. The mismatch between what the status line shows and what Claude can see erodes user trust.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗