All Agent Engineering

Claude Code tool failures: event boundaries and error fields

Inspect PostToolUseFailure triggering and account for pre-execution rejection.

AINavWritten / Updated
On this page

At a glance

This page inspects one event contract from official Claude Code hook documentation. Use a reviewed settings copy, inspect event input and output, then observe loading. This run checked synthetic JSON only and enabled no actual hook.

Runtime and applicability

Article type
Spec file
Verified
Applies to
  • Claude Code Applies to the Claude Code hook event documented here.

File locations

PathScopeHow it is read
.claude/settings.jsonProject hooks settings copy; preserve existing configuration.Read by Claude Code under settings loading and the event contract; not enabled in this run.

When to use

  • Inspect PostToolUseFailure triggering and account for pre-execution rejection.

When not to use

  • The event or required fields are unclear, or a local JSON check is expected to replace permission and execution evidence.

Separate failures from pre-execution rejection

PostToolUseFailure runs when a started tool fails, including a thrown error or MCP error result. Unknown tools, schema/tool validation rejections and permission denials do not trigger it. Validation rejection also skips PreToolUse, while permission denial passes through PreToolUse. This event count cannot represent all failures and rejections.

error text is not a stable parsing protocol

Input carries tool_name, tool_input and top-level error, with optional is_interrupt and duration_ms. Execution duration excludes permission prompts and PreToolUse waiting; cancelling a running tool itself does not fire this hook. error varies by tool. Shell exits commonly start with Exit code N, but startup failures may have only text, so not every error has a parsable exit code.

Feedback does not undo execution

Use hookSpecificOutput.additionalContext for corrective context. Treat error content as display text rather than a new shell command. Record tool names, optional-field presence and bounded summaries while handling sensitive log content separately. This page sends no notifications and automatically retries or undoes nothing.

Inspect missing optional fields

Local checks covered an Exit code 1 header, plain error text and missing duration_ms, preserving unknown exit codes and durations instead of inventing zero. No failing tool or hook was run. Inspect event logs and evidence of execution; archive pre-execution rejections separately rather than forcing execution to produce a failure event.

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 →