← Back to PRs

#11071: Plugins: add tool_result_received hook for output interception

by ThomasLWang open 2026-02-07 10:49 View on GitHub →
docs agents
## Summary - Add a new `tool_result_received` plugin hook that runs **after tool execution** but **before results reach the agent**, enabling plugins to modify or block tool outputs for security guardrails and content filtering. - Runs sequentially with async support, complementing the existing fire-and-forget `after_tool_call` hook. - Includes review fixes: preserve original params type (`unknown`), fix `runModifyingHook` type cast, clarify `durationMs` semantics. Based on #10328 by @ThomasLWang with review feedback from greptile-apps addressed. ## Test plan - [x] `pnpm build` passes - [x] `pnpm check` (tsgo + oxlint + oxfmt) passes - [x] `pnpm test` — 219 tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Thomas <thomas@openguardrails.com> <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a new plugin lifecycle hook, `tool_result_received`, which runs after a tool executes but before its output is delivered back into the agent loop. Tool execution is now wrapped so plugins can (a) modify tool params pre-execution via `before_tool_call` and (b) modify/block tool results post-execution via the new sequential hook, while `after_tool_call` remains parallel fire-and-forget. The hook runner (`src/plugins/hooks.ts`) gains a sequential “modifying hook” runner that supports both sync and async handlers and merges results in priority order, including preserving explicit `null` overrides for tool results. Documentation and changelog are updated to describe the new interception point in the agent loop. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk. - Changes are localized to plugin hook plumbing and tool wrapping, with clear semantics, idempotent wrapping, and explicit handling for null overrides; no remaining issues from prior review threads were found in the current commit. - No files require special attention <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs