Skip to content

fix(opencode): allow tool hooks to replace call arguments#20009

Open
phuctm97 wants to merge 3 commits intoanomalyco:devfrom
phuctm97:codex/tool-hook-args
Open

fix(opencode): allow tool hooks to replace call arguments#20009
phuctm97 wants to merge 3 commits intoanomalyco:devfrom
phuctm97:codex/tool-hook-args

Conversation

@phuctm97
Copy link
Copy Markdown

@phuctm97 phuctm97 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?

This fixes how tool execution hooks handle call arguments. tool.execute.before receives an output object with args, but the wrapper was still executing the tool with the original args variable. That meant a hook could mutate an existing object in place, but it could not replace missing args with a new object.

This change normalizes missing args to {} before the hook runs, then executes the tool with the possibly replaced output.args. The regression tests cover both native tools and MCP tools when the original call args are undefined.

How did you verify your code works?

  • bun test test/session/tool-hooks.test.ts
  • bun run typecheck

Screenshots / recordings

Not applicable.

Checklist

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

@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Allow tool hooks to replace call arguments doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions github-actions bot added needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Mar 30, 2026
@phuctm97 phuctm97 changed the title Allow tool hooks to replace call arguments fix(opencode): allow tool hooks to replace call arguments Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tool.execute.before cannot replace missing tool call arguments

1 participant