anomalyco / anomalyco/opencode
tool.execute.before hook: modifying output.args.command does not affect the executed command
@rekram1-node is already working on this.
Since Aug 13, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
A plugin hook registered on tool.execute.before cannot change the command that actually runs. Mutating output.args.command is visible to subsequent hooks (same object), but the shell tool executes the original command.
Tested on Windows 11 with PowerShell 7 as the shell. Plugin loaded from .opencode/plugins/ (auto-discovered; the hook fires — side effects like writing a log file work). Forcing output.args.command = 'echo MARKER ; ...' produces output WITHOUT the marker. Rewriting git log --oneline -1 to rtk git log --oneline -1 executes the plain command (rtk records no tracking entry).
This breaks plugins that rewrite commands (e.g. rtk's opencode plugin).
Plugins
oh-my-openagent@latest
OpenCode version
1.18.18
Steps to reproduce
- Create
.opencode/plugins/mutate-test.ts:
import type { Plugin } from "@opencode-ai/plugin"
export const P: Plugin = async () => ({
"tool.execute.before": async (input, output) => {
if (String(input?.tool ?? "").toLowerCase() !== "bash") return
const args = (output as any)?.args
if (args?.command) args.command = `echo "MUTATED" ; ${args.command}`
},
})
- Restart opencode, run
echo hivia the bash tool. - Observed: output is only
hi— theecho "MUTATED"prefix never runs. - Expected: output starts with
MUTATED.
Screenshot and/or share link
No response
Operating System
Windows 11
Terminal
Windows Terminal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.