Skip to content

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

Closed as not planned

Description

@travailleuse

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

Activity

  1. casper7756 commented on Sep 4, 2026

    @casper7756

    Hello,
    Is there any estimate on when this issue will be resolved?
    Thanks

  2. travailleuse commented on Sep 12, 2026

    @travailleuse
    Author
  3. travailleuse commented on Sep 12, 2026

    @travailleuse
    Author
  4. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions