[PR #4979] fix: preserve argument boundaries in run command #11194

Closed
opened 2026-02-16 18:15:59 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4979

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4979 **State:** closed **Merged:** Yes --- ## Summary Fixes argument parsing for `opencode run --command` when arguments contain spaces. ## Problem When running a command like: ```bash 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.
yindo added the pull-request label 2026-02-16 18:15:59 -05:00
yindo closed this issue 2026-02-16 18:15:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11194