<!-- llms-explorer concept facts · https://llms-explorer.com/tree/hook-based-filtering-of-agent-output/ · pack 2026-09-23 · ~494 tokens -->

# Hook-based filtering of agent output

> Source-anchored research for Hook-based filtering of agent output. Run status: COMPLETED.

Parent: [Instruction-file hygiene for LLM lexical tics: linting, mirroring, hook filtering](https://llms-explorer.com/tree/ai-isms-instruction-hygiene/) · 2 facets · 5 facts · page: https://llms-explorer.com/tree/hook-based-filtering-of-agent-output/

## Problems, failure modes and limitations

- Hooks cannot directly modify assistant message text. Stop can only prevent stopping and continue the conversation, and last_assistant_message on Stop/SubagentStop is read-only input for analysis. (medium confidence) (verified as of 2026-09-23) — [source](https://code.claude.com/docs/en/hooks)

## Facts and statements

- A Stop hook can act as a post-generation filter: it inspects the final response and blocks with a reason, forcing the model to revise before the user sees the result. (medium confidence) — [source](https://dev.to/hexisteme/stop-hooks-as-hard-constraints-enforcing-claude-code-behavior-outside-the-model-1g6b)
- A regex-only Stop hook produces false positives; combining the regex with a second condition (e.g. prior tool-call activity) removes most of them. (low confidence) — [source](https://dev.to/hexisteme/stop-hooks-as-hard-constraints-enforcing-claude-code-behavior-outside-the-model-1g6b)
- A Stop hook that re-blocks without checking stop_hook_active can loop indefinitely; one reported case ran about 50 minutes and consumed the session quota. A nag-once pattern (block the first violation, let an identical repeat pass) avoids it. (medium confidence) (verified as of 2026-05-03) — [source](https://github.com/anthropics/claude-code/issues/55754)
- PostToolUse can replace a tool's output before the model sees it (updatedToolOutput), so filtering applies to tool results but not to the model's own prose. (medium confidence) (verified as of 2026-09-23) — [source](https://code.claude.com/docs/en/agent-sdk/hooks)
