claude-code - 💡(How to fix) Fix Background task notifications should include exit code and output tail

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

In practice, the model often skips this step and treats "completed" as "succeeded." A command that fails with exit code 1 and a clear error message goes unnoticed because the notification looks identical to a success. This way a non-zero exit code is impossible to miss, and the error context is right there without a round-trip. Background tasks are used for builds, test runs, and long-running processes where the model proceeds with other work while waiting. When the result arrives, the model needs to make a correct judgment call immediately. Forcing a manual file read to discover failures is error-prone and adds latency. The information is already available — it just isn't surfaced.

Root Cause

Background tasks are used for builds, test runs, and long-running processes where the model proceeds with other work while waiting. When the result arrives, the model needs to make a correct judgment call immediately. Forcing a manual file read to discover failures is error-prone and adds latency. The information is already available — it just isn't surfaced.

Code Example

<task-notification>
  <task-id>abc123</task-id>
  <status>completed</status>
  <exit-code>1</exit-code>
  <output-tail>
. postinstall: cp: no such file or directory: ./node_modules/foo/data
. postinstall: Failed
 ELIFECYCLE  Command failed with exit code 1.
  </output-tail>
</task-notification>
RAW_BUFFERClick to expand / collapse

Problem

When a background Bash command (run_in_background: true) completes, the <task-notification> delivered to the model contains only:

  • task ID
  • output file path
  • status: "completed"
  • a one-line summary like Background command "..." completed (exit code 0)

The exit code is buried in the summary string, not structured. And crucially, the actual output (stdout/stderr) is not included — the model has to make a separate Read call on the output file to see what happened.

In practice, the model often skips this step and treats "completed" as "succeeded." A command that fails with exit code 1 and a clear error message goes unnoticed because the notification looks identical to a success.

Proposal

Include two additional fields in the <task-notification>:

  1. exit_code (integer) — structured, not embedded in prose
  2. output_tail (string) — last N lines (e.g. 20) of the output file

Example:

<task-notification>
  <task-id>abc123</task-id>
  <status>completed</status>
  <exit-code>1</exit-code>
  <output-tail>
. postinstall: cp: no such file or directory: ./node_modules/foo/data
. postinstall: Failed
 ELIFECYCLE  Command failed with exit code 1.
  </output-tail>
</task-notification>

This way a non-zero exit code is impossible to miss, and the error context is right there without a round-trip.

Why this matters

Background tasks are used for builds, test runs, and long-running processes where the model proceeds with other work while waiting. When the result arrives, the model needs to make a correct judgment call immediately. Forcing a manual file read to discover failures is error-prone and adds latency. The information is already available — it just isn't surfaced.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Background task notifications should include exit code and output tail