Skip to content

hooks: support dynamic tools in PreToolUse/PostToolUse#20335

Closed
eternal-openai wants to merge 7 commits into
mainfrom
codex/dynamic-tool-hooks
Closed

hooks: support dynamic tools in PreToolUse/PostToolUse#20335
eternal-openai wants to merge 7 commits into
mainfrom
codex/dynamic-tool-hooks

Conversation

@eternal-openai
Copy link
Copy Markdown
Contributor

@eternal-openai eternal-openai commented Apr 30, 2026

Why

After tightening dynamic tool registration to the same identifier contract that Responses actually accepts, we can extend Codex's hook support to dynamic tools using the same plain tool identities that already exist on the model-facing surface.

This keeps hook matching aligned with the tool names app-server and Responses already use, instead of inventing a separate dynamic-only namespace. It also makes dynamic tool hooks behave like the existing function-style tool hooks we already support.

What changed

  • extend PreToolUse and PostToolUse to dynamic tools by teaching DynamicToolHandler to build hook payloads from parsed JSON arguments
  • serialize namespaced dynamic tools to hook tool_name as namespace__tool, while plain dynamic tools keep their plain tool name
  • percent-encode only the bytes that would make the flattened namespace__tool form ambiguous, so matcher identities stay injective even when identifiers contain edge or repeated underscores
  • populate dynamic tool_response with the same body shape the model sees: a JSON string for a single text item, or the full content-item array for richer output
  • reuse the shared hook-facing naming helper across dynamic tools, MCP, and permission-request plumbing so matcher behavior stays consistent
  • keep the existing non-goal that dynamic tools do not start participating in new approval-runtime / PermissionRequest flows in this pass

Verification

  • cargo test -p codex-hooks
  • cargo test -p codex-core hooks_dynamic
  • cargo test -p codex-core for_dynamic_tool_
  • cargo test -p codex-core dynamic_post_tool_use_

Docs

No external docs update is needed for this stacked change.

@eternal-openai eternal-openai force-pushed the codex/dynamic-tool-hooks branch from 3e61061 to 7dc4444 Compare May 2, 2026 02:49
@eternal-openai eternal-openai changed the base branch from main to codex/dynamic-tool-responses-contract May 2, 2026 02:49
Base automatically changed from codex/dynamic-tool-responses-contract to main May 6, 2026 04:05
@github-actions
Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant