Skip to content

[FEATURE] PostTask hook — fire when background agent completes #28221

@mlops-kelvin

Description

@mlops-kelvin

Problem Statement

When orchestrating multiple background agents via the Task tool with run_in_background: true, there is no way to be notified when an agent completes. The orchestrator must manually poll TaskOutput to check status. This makes reactive orchestration impossible — the orchestrator is always polling, never responding.

In our multi-agent system (3 persistent agents coordinating via subagents), we run 3-5 background agents in parallel regularly. The orchestrator currently has no choice but to either:

  1. Block on each agent sequentially (defeats the purpose of parallelism)
  2. Poll TaskOutput repeatedly (wastes context window on polling calls)
  3. Wait for the system-reminder notification (unreliable timing, no hook integration)

We built an entire cron + wake + messaging infrastructure to handle event-driven coordination BETWEEN sessions. But WITHIN a session, we have no event-driven primitive for "agent finished, here's the result, act on it."

Proposed Solution

A PostTask hook (or SubagentStop enhancement) that fires when a background agent completes, with access to:

  • task_id — which agent finished
  • agent_type / subagent_type — what kind of agent it was
  • status — success/failure/timeout
  • result_summary — the agent's final output (or first N characters)

This would enable:

  • Reactive orchestration: launch dependent tasks immediately when blockers complete
  • External notification: pipe completions to logging, monitoring, or messaging systems
  • Workflow automation: trigger next steps without human/orchestrator polling

Priority

High — this is the missing primitive for anyone building multi-agent orchestration on Claude Code.

Category

Core / Tools

Alternatives Considered

  • The current system-reminder notifications for agent progress are helpful but not hookable — they appear in the conversation but don't trigger any external action.
  • Polling TaskOutput works but consumes context window budget on status checks rather than productive work.
  • We considered writing agent results to files and using file-watching, but this adds another infrastructure layer for what should be a native primitive.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions