All Agent Engineering

Claude Code async hooks: results and session teardown

Use background hooks for non-blocking work and distinguish process completion from result delivery.

AINavWritten / Updated
On this page

At a glance

This page explains one configuration contract from official documentation and records the local synthetic checks. It changes no actual settings, runs no hook, creates no subagent and calls no external service. Documented capabilities are separate from execution results.

Runtime and applicability

Article type
Spec file
Verified
Applies to
  • Claude Code Applies to the documented Claude Code configuration; version and event support appear in the body.

File locations

PathScopeHow it is read
PostToolUse: command Hook; subsequent conversation turnsThe event or subagent configuration described in this page.Read by Claude Code during relevant configuration loading and event execution; not enabled in this run.

When to use

  • Use when inspecting this configuration, loading location and result contract.

When not to use

  • Stop integration and consult specific documentation when the event, version or permission boundary is unclear.

Background mode is command-only

In a reviewed settings copy, locate the PostToolUse matcher and hooks array and set async=true on a command hook. Only type=command supports this field. Background work cannot control an action that has already completed, so decision, permissionDecision and continue cannot block it. Keep synchronous validation when the action must wait for a successful check.

Output arrives in the next turn

A background hook receives the same JSON on stdin as a synchronous hook. After it exits, additionalContext and systemMessage are delivered in the next turn; an idle session ordinarily waits for interaction, while asyncRewake has a separate wake-up contract. Claude Code does not enforce timeout after a normal async hook starts in the background. Do not treat that field as a guaranteed background-process deadline.

Non-interactive teardown cancels unfinished work

The documentation states that claude -p kills an async hook still running at teardown and records it as cancelled. Work that must outlive the session needs a separate process-management design; async=true does not grant persistent execution. Inspect process state, produced output and delivery to the main session separately. No background hook was launched here.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. Anthropic · Hooks reference

Found an error? Tell us →