Add 'list running background tasks' tool for post-compaction recovery

Resolved 💬 3 comments Opened Mar 15, 2026 by aziwar Closed Mar 19, 2026

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

  1. Start a long Claude Code session
  2. Launch background tasks (run_in_background: true on Bash or Agent tools)
  3. Continue working until context fills up
  4. Run /compact or let auto-compaction trigger
  5. Ask Claude "how many background tasks are running?"
  6. 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_background and Agent run_in_background tasks
  • 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.

View original on GitHub ↗

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