Back to catalog / Agent recovery
Feed tool errors back to the agent for recovery
Inspect tool responses in a PostToolUse hook and add actionable error context for the next model turn.
Goal
Turn tool failures into structured feedback so the agent can correct course instead of claiming success.
Steps
- Register a
PostToolUsematcher, readinput_data["tool_response"], and detect an error state. [hooks] - Return
systemMessage,reason, andhookSpecificOutput.additionalContextwith concise, non-sensitive recovery hints. [hooks] - Test with one reproducibly failing tool and one successful tool; still inspect whether the final ResultMessage succeeded. [hooks]
How to verify
An error response adds context while a successful response does not; the application never treats a tool error as task completion.
Troubleshooting
If the model repeats failures, cap retries and define a stop condition; ensure detection does not flag normal output.
Permissions
Prerequisites
- Python 3.10+, SDK, and a controllable test tool or mocked tool response.
Permissions
- Return only error details needed for recovery; do not automatically retry side-effecting tools.
Limitations
Bound context size and redact secrets from tool output; after hook feedback, run the checks that confirm the recovery.
Pinned upstream source
- Repository
- anthropics/claude-agent-sdk-python
- File path
- examples/hooks.py
- Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Main topic
Take a coding Agent change from context to verification