[BUG] Backgrounded Bash command killed by its timeout reports "completed (exit code 0)"
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?
When a Bash command is started with run_in_background: true and a timeout, and that command is still running when the timeout expires, the harness kills it but reports it to the model as a successful completion:
<status>completed</status> Background command "..." completed (exit code 0)
There is no way to distinguish "the command finished" from "the harness killed it partway through." The captured output simply stops mid-stream.
Because the model is told exit code 0 / completed, it reports success to the user. Any work the command had not yet done is silently lost.
Real impact from a production session: a background loop over 40 batch jobs (each ~5 minutes, timeout 600000) was killed after 4 iterations. The notification said completed, exit code 0. I told my user the batch succeeded. 36 units of paid API work never ran and neither of us knew for hours. The only clue was that a final summary line the script prints at the end was missing from the output, which requires the user to have written such a line and to think to check for it.
What Should Happen?
A command terminated by the harness must not be reported as a successful completion. Specifically:
The task notification should carry a distinct terminal state, e.g. status: timed_out (or killed), not status: completed.
The exit code should be non-zero (128+SIGKILL/SIGTERM is the shell convention), not 0.
The notification text should say the process was killed after N seconds and that output is truncated.
Ideally a truncation marker is appended to the captured output stream so the model sees the cut even if it only reads the tail.
Any one of 1-3 would have prevented the incident.
Error Messages/Logs
Notification received by the model:
<task-notification> <task-id>bqe403itt</task-id> <status>completed</status> <summary>Background command "Run pipeline across 8 unscanned metros, 5 categories, 60 places each" completed (exit code 0)</summary> </task-notification>
Tail of the captured output file (note: no final "TOTAL" line the script prints on normal completion, and only 4 of 40 iterations present):
accountant 32801: found=60 qualified=48 [output ends here mid-run]
Steps to Reproduce
Create a script that loops 10 times, sleeping 90s per iteration, printing the iteration number each time and printing "DONE" after the loop:
for i in $(seq 1 10); do echo "iter $i"; sleep 90; done; echo "DONE"
Run it with the Bash tool using run_in_background: true and timeout: 120000 (2 minutes), so it is guaranteed to be killed mid-loop.
Wait for the completion notification.
Observed: status "completed", exit code 0, output contains only ~1 iteration and no "DONE". Expected: a timed-out/killed status with a non-zero exit code.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
1.40609.0
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
_No response_