Skip to content

fix: Allow plugin hooks to mutate tool call args before context creation#20053

Open
yejiming wants to merge 1 commit intoanomalyco:devfrom
yejiming:jimmy/2026-03-30-11-23-53
Open

fix: Allow plugin hooks to mutate tool call args before context creation#20053
yejiming wants to merge 1 commit intoanomalyco:devfrom
yejiming:jimmy/2026-03-30-11-23-53

Conversation

@yejiming
Copy link
Copy Markdown
Contributor

@yejiming yejiming commented Mar 30, 2026

Issue for this PR

Closes #20013

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

tool.execute.before hooks receive { args }, but tool execution continued with the original args reference captured before the hook ran. That meant hooks could mutate output.args without affecting the actual tool call.

This change routes both native tools and MCP tools through a mutable out = { args } object, triggers the before hook with that object, and then executes tools using out.args. It also passes out.args to tool.execute.after for consistency.

Why this works: the before hook can now replace or inject args by mutating the shared out.args object, and the execution path reads from the same object after the hook completes.

How did you verify your code works?

  • Ran bun test test/plugin/trigger.test.ts in packages/opencode (environment warning: missing preload module @opentui/solid/preload).
  • Ran bun typecheck in packages/opencode (environment warning: tsgo not available in this container).

Screenshots / recordings

Not a UI change

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

This PR appears to be addressing the same issue as #20053. Both are about allowing tool execution hooks (specifically tool.execute.before) to modify/replace tool call arguments. PR #20009 seems to be a related or potentially duplicate fix for the same problem described in issue #20013.

You should verify whether #20009 was already merged or if it's still open, as it may render the current PR redundant.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tool.execute.before cannot replace missing tool call arguments

1 participant