Skip to content

Stop hook signals task-complete while background subagents are still running #82

Description

@Sfaiug

on-stop.sh sends the task-complete payload on every Claude Code Stop event. But Stop fires whenever the main agent's turn ends — including turns that launched background subagents (Agent tool) or background Bash tasks that are still running. Warp flips the session to "Complete" and fires the done notification while work continues, then bounces back to "working" when the harness re-invokes the main agent on task completion.

Repro: in Warp, run claude, prompt "launch a research subagent in the background and end your turn." The turn ends → Warp shows Complete; the subagent is still running.

Suggested fix: Claude Code doesn't expose pending-task state to Stop hooks, but the transcript (transcript_path in hook input) carries a reliable ledger: spawn markers in tool_results (Async agent launched successfully … agentId: X / Command running in background with ID: X) and completion records (queue-operation entries containing <task-notification><task-id>X). If any spawned id lacks a completion record, suppress the stop payload — a later Stop fires naturally when the harness re-invokes the main agent after the last task completes. Fail open on parse errors. I have a working wrapper implementation locally and am happy to share it. (Longer term, an official pending-background-tasks field in Stop hook input from Anthropic would make this robust.)

Environment: plugin v2.2.0, Claude Code 2.1.233, macOS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions