[BUG] Polling background task output files instead of using TaskOutput tool

Resolved 💬 3 comments Opened Jan 8, 2026 by aaron-sangster Closed Jan 12, 2026

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?

Problem

When background tasks are started with run_in_background: true, Claude repeatedly polls the output file using Read or Bash tail commands to check task status. Each poll brings the (potentially large) output contents into the conversation context window.

Note: This behavior is not consistently replicable but occurs sporadically.
Note: Observed using the Opus 4.5 model.

## Impact

  • Context window explosion: Each file read adds the full output to context, even if checking the same file multiple times
  • Token waste: Repeated reads of identical or incrementally growing output consume tokens rapidly
  • Session degradation: Large context can cause slowdowns, summarization triggers, or hitting context limits prematurely
  • Unnecessary operations: The polling pattern ignores built-in notification mechanisms

What Should Happen?

  1. Use the TaskOutput tool to check background task status (designed for this purpose)
  2. Wait for system notifications when tasks complete rather than polling
  3. Use TaskOutput with block=true when the result is needed before proceeding
  4. Prefer synchronous execution when there's no other meaningful parallel work to perform
  5. Never use Read or Bash tail on background task output files

Error Messages/Logs

Steps to Reproduce

  1. Start a long-running task (e.g., build, test suite) with run_in_background: true
  2. Observe Claude using Read or Bash tail on the output file to check status
  3. Claude repeats step 2 multiple times, each time adding output to context

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.1

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other

Additional Information

Extract from Claude Code:

⏺ Three agents are now running in parallel implementing Tasks 1, 2, and 3. Let me check their progress.

⏺ Bash(tail -30 /tmp/claude/-Users-<repository>/tasks/a460b12.output)
  ⎿  {
       "parentUuid": null,
       "isSidechain": true,
     … +189 lines (ctrl+o to expand)

⏺ Bash(tail -30 /tmp/claude/-Users-<repository>/tasks/a5053a7.output)
  ⎿  {
       "parentUuid": null,
       "isSidechain": true,
     … +191 lines (ctrl+o to expand)

⏺ Bash(tail -30 /tmp/claude/-Users-<repository>/tasks/a4ba22c.output)
  ⎿  {
       "parentUuid": null,
       "isSidechain": true,
     … +149 lines (ctrl+o to expand)

⏺ All three agents are running. Let me wait a moment and check their progress again.

⏺ Bash(sleep 15 && tail -50 /tmp/claude/-Users-<repository>/tasks/a460b12.output            timeout: 1m
      2>/dev/null | grep -E '"type":"(user|assistant)"…)                                                                          0s
  ⎿  {
       "parentUuid": "0a5759bc-d2f6-4d2f-a945-604ecf7ed6ef",
       "isSidechain": true,
     … +252 lines (ctrl+o to expand)

⏺ The agents are progressing. They're reading the route files to understand the existing patterns. Let me wait longer and check for completion.

⏺ Bash(sleep 60)
  ⎿  (No content)

⏺ Bash(tail -100 /tmp/claude/-Users-<repository>/tasks/a460b12.output 2>/dev/null | grep -E
      '(Implementation Result|Status:|Files…)
  ⎿  {
       "parentUuid": "1e44f7ae-8167-4f4a-b986-67ff35a788e9",
       "isSidechain": true,
     … +270 lines (ctrl+o to expand)

⏺ Bash(tail -100 /tmp/claude/-Users-<repository>/tasks/a5053a7.output 2>/dev/null | grep -E
      '(Implementation Result|Status:|Files…)
  ⎿  {
       "parentUuid": "3355cbff-d251-4d13-847f-eb3cf5bd069f",
       "isSidechain": true,
     … +269 lines (ctrl+o to expand)

⏺ Bash(tail -100 /tmp/claude/-Users-<repository>/tasks/a4ba22c.output 2>/dev/null | grep -E
      '(Implementation Result|Status:|Files…)
  ⎿  {
       "parentUuid": "f629155a-0ec2-4a75-b368-b981f54c9981",
       "isSidechain": true,
     … +268 lines (ctrl+o to expand)

⏺ The agents are still working. Let me wait longer for them to complete their tasks.

⏺ Bash(sleep 90) timeout: 3m 0s
  ⎿  (No content)

⏺ Bash(tail -150 /tmp/claude/-Users-<repository>/tasks/a460b12.output 2>/dev/null | grep -E '(##
      Implementation|Status:|success|b…)
  ⎿  {
       "parentUuid": null,
       "isSidechain": true,
     … +306 lines (ctrl+o to expand)

⏺ Bash(tail -150 /tmp/claude/-Users-<repository>/tasks/a5053a7.output 2>/dev/null | grep -E '(##
      Implementation|Status:|success|b…)
  ⎿  {
       "parentUuid": "68037c9a-1034-4f98-845d-f8b71daa856f",
       "isSidechain": true,
     … +292 lines (ctrl+o to expand)

⏺ Bash(tail -150 /tmp/claude/-Users-<repository>/tasks/a4ba22c.output 2>/dev/null | grep -E '(##
      Implementation|Status:|success|b…)
  ⎿  {
       "parentUuid": null,
       "isSidechain": true,
     … +305 lines (ctrl+o to expand)

⏺ The agents are still actively working. Let me wait a bit longer and check for final completion.

View original on GitHub ↗

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