anomalyco / anomalyco/opencode

tool.execute.before hook: modifying output.args.command does not affect the executed command

Open
#42,409 3 comments 0 reactions 1 assignee View on GitHub

@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
  1. 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}`
  },
})
  1. Restart opencode, run echo hi via the bash tool.
  2. Observed: output is only hi — the echo "MUTATED" prefix never runs.
  3. Expected: output starts with MUTATED.
Screenshot and/or share link

No response

Operating System

Windows 11

Terminal

Windows Terminal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.