opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: preserve argument boundaries in run command

Open simondmorias opened this issue 1 month ago • 0 comments

Summary

Fixes argument parsing for opencode run --command when arguments contain spaces.

Problem

When running a command like:

opencode run --command testcommand val1 "val 2" val3

With a command template configured as:

Arg1: $1
Arg2: $2
Arg3: $3

The arguments were incorrectly parsed as:

Arg1: val1
Arg2: val
Arg3: 2

Instead of the expected:

Arg1: val1
Arg2: val 2
Arg3: val3

Cause

The issue was a double-parsing problem:

  1. The shell correctly parses the command line, treating "val 2" as a single argument
  2. run.ts joins all positional arguments with spaces: args.message.join(" ")val1 val 2 val3
  3. The command handler in prompt.ts re-parses this string using a regex that splits on whitespace

At step 2, the original quoting information is lost, so step 3 splits val 2 into two separate arguments.

Fix

Quote any argument containing spaces before joining, so the command handler can correctly identify the original argument boundaries. Also escapes any existing double quotes within arguments.

simondmorias avatar Dec 02 '25 10:12 simondmorias