GeezerVison is showing github.com — bash: valid $'\033\[?1049' escape rejected as "unterminated-quote" · Issue #64254 · anomalyco/opencode
bash: valid $'\033\[?1049' escape rejected as "unterminated-quote" #64254DescriptionSummary
The shell tool's command scanner rejects a valid command containing an ANSI-C quoted string with a non-standard escape ($'\033\[?1049'), reporting Portable shell scanner cannot analyze command: unterminated-quote. The command never runs. Bash itself accepts it and preserves the backslash, and the same script runs fine when invoked as bash script.sh.
Environment
- opencode version: 2.2.7
- OS: Linux 7.3.4-1-cachyos (linux x64)
- Terminal: kitty, TERM=xterm-kitty, COLORTERM=truecolor
- Shell: fish (commands run by the shell tool)
- Install/channel: release binary
- Active plugins: local plugin, @dietrichgebert/ponytail
Reproduction
-
Run through the shell tool:
printf '%s' $'\033\[?1049' | od -c
-
The tool refuses to execute it and returns:
Portable shell scanner cannot analyze command: unterminated-quote
Expected Behavior
The command executes and prints:
0000000 033 \ [ ? 1 0 4 9
Bash treats \[ as an unrecognized escape and keeps the backslash, which is exactly what is needed to feed a literal [ to grep.
Actual Behavior
Nothing is executed; the tool returns an error before spawning the shell. Reproducible 100%.
Additional Context
Minimal failing token: $'\033\[?1049'.
Scanner accepts (so it is specifically the escape, not ANSI-C quoting itself):
$'\033]66;s='
$'\033\\[?1049' (valid \\ escape, then a plain [)
- the same line inside a script, invoked as
bash script.sh
According to the minified bundle shipped in 2.2.7, the ANSI-C string parser accepts only \a \b \e \E \f \n \r \t \v \\ \' \" \?, \xNN, \uNNNN, \UNNNNNNNN and octal \NNN. Any other escape makes the parser return undefined, and the caller maps that to unterminated-quote. The message is misleading: the quote is terminated, the escape is simply unsupported.
Impact: valid shell commands are blocked, and the error text sends users looking for a quoting problem that does not exist. Workaround: double the backslash ($'\033\\[?1049') or wrap the snippet in a script file. Activityopencodejr commented on Nov 16, 2026 Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the detailed report. I reproduced this on 2.2.7, using a simulated model to send the shell tool call. When the shell tool was given printf '%s' $'\033\[?1049' | od -c, it refused it with Portable shell scanner cannot analyze command: unterminated-quote and the command never ran. With the backslash doubled ($'\033\\[?1049'), it ran and printed 0000000 033 \ [ ? 1 0 4 9, which is also what plain bash prints for the original command. It still happens on the latest dev (0796584).
It matches what you found in the bundle: the scanner's $'...' parser gives up on an escape it doesn't recognise, such as \[, and that is reported as an unterminated quote. Until it's fixed, doubling the backslash or putting the command in a script works. The recording and script below show both commands; the screenshot shows the end state.
recording.mp4

Reproduction script (drive.ts)
// Reproduces anomalyco/opencode#64254: the shell tool refuses $'\033\[?1049' as "unterminated-quote".
// Run: OPENCODE_DRIVE_MEDIA_DIR=/workspace/media opencode-drive run drive.ts (OC_DEV=<checkout> to run from source)
import { Effect, Stream } from "effect"
import { Llm, OpenCodeDriver } from "opencode-drive"
const failing = String.raw`printf '%s' $'\033\[?1049' | od -c`
const working = String.raw`printf '%s' $'\033\\[?1049' | od -c`
// Simulated model: title requests get a title; the agent turns run the two commands in order.
const turns = [
[Llm.toolCall({ index: 0, id: "call_fail", name: "shell", input: { command: failing } }), Llm.finish("tool-calls")],
[Llm.text("first call done")],
[Llm.toolCall({ index: 0, id: "call_ok", name: "shell", input: { command: working } }), Llm.finish("tool-calls")],
[Llm.text("second call done")],
]
const dump = (ui: any): Effect.Effect<void, unknown, never> =>
Effect.gen(function* () {
const frame: any = yield* (ui.capture() as Effect.Effect<unknown, unknown, never>)
const text = frame.lines.map((l: any) => l.spans.map((s: any) => s.text).join("").trimEnd()).filter((l: string) => l).join("\n")
yield* Effect.log("\n" + text)
})
export default OpenCodeDriver.use(
{
...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
project: { git: true },
tui: { recording: true },
},
({ ui, llm, opencode }) =>
Effect.gen(function* () {
let turn = 0
yield* llm.serve((request: any) => {
if (JSON.stringify(request).includes("You name conversations")) return Stream.make(Llm.text("Escape test"))
return Stream.make(...(turns[turn++] ?? [Llm.text("done")]))
})
yield* ui.submit("Run the escape test")
yield* Effect.sleep("6 seconds")
yield* Effect.sleep("1 second")
yield* ui.screenshot("after-failing-command")
yield* dump(ui)
yield* ui.submit("Run the control")
yield* ui.waitFor("second call done", { timeout: 30000 })
yield* Effect.sleep("1 second")
yield* ui.screenshot("after-control-command")
yield* dump(ui)
// Print the shell tool results recorded by the server
const sessions: any = yield* opencode.session.list()
for (const session of sessions.data ?? sessions) {
const messages: any = yield* opencode.message.list({ sessionID: session.id } as any)
for (const m of messages.data ?? []) if (m.type === "assistant") yield* Effect.log(JSON.stringify(m.content))
}
}),
)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|