Repository navigation
Closed
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Problem
OpenCode routes all code execution through the bash tool. When an agent wants to run a Python snippet, a Node.js expression, or a quick SQL query, it must:
- Invoke
bashwith a full shell invocation (python3 -c "..."ornode -e "...") - Handle shell escaping of the code content (single quotes, newlines, special chars)
- Mix Python/JS exit codes with shell exit codes indistinguishably
- Use
DangerFullAccesspermission even for trivial read-only calculations
claw-code implements a REPL tool that accepts a code string and language field, runs the code in an isolated subprocess, and returns structured stdout, stderr, and exit_code — cleanly separated from shell semantics.
Proposed solution
// packages/opencode/src/tool/repl.ts
export const REPLTool = Tool.define({
name: "REPL",
description: "Execute a code snippet in a language-specific subprocess. Prefer this over bash for Python, JavaScript, or SQL snippets to avoid shell-escaping issues and get clean per-language exit codes.",
parameters: z.object({
code: z.string(),
language: z.enum(["python", "javascript", "typescript", "sql", "ruby", "shell"]),
timeout_ms: z.number().int().min(1).max(60_000).optional()
}),
execute: async ({ code, language, timeout_ms }) => {
const result = await executeREPL(code, language, timeout_ms ?? 10_000)
return {
language,
stdout: result.stdout,
stderr: result.stderr,
exit_code: result.exitCode,
duration_ms: result.durationMs
}
}
})Language dispatch
| Language | Subprocess |
|---|---|
python |
python3 -c <code> (or via stdin pipe for multiline) |
javascript |
node --input-type=module |
typescript |
bun run --smol - (stdin) |
sql |
Configurable: sqlite3, duckdb, or psql |
shell |
Direct subprocess (same as bash but with cleaner I/O isolation) |
Why this matters
- Eliminates shell-escaping bugs that cause agents to corrupt code containing quotes, backslashes, or newlines when passed through
bash -c - Produces clean, parseable
stdout/stderr/exit_codewithout shell wrapper noise - Particularly valuable for data science workflows running Python analysis snippets (DuckDB, pandas) inline without writing a temp file
- Permission model can be more nuanced: a
pythonREPL that only does computation could beReadOnly; only REPLs with filesystem access needWorkspaceWrite
Acceptance criteria
-
REPLtool executes code in an isolated subprocess with configurable timeout -
stdout,stderr, andexit_codeare returned as separate fields (not concatenated) - Multiline code strings are handled without shell-escaping issues (passed via stdin pipe, not
-cargument) -
timeout_mskills the subprocess cleanly and returns a timeout error instderr - At minimum
pythonandjavascript/typescriptare supported on first release; additional languages are additive
Related / cross-reference
- claw-code reference: https://github.com/instructkr/claw-code/tree/main/rust (
REPLtool) - Sub-agent tool-set isolation: [FEATURE]: Sub-agent tool-set isolation by role (Explore / Plan / Verification scopes) #20483
- Bash timeout kills background processes: Bash timeout kills background processes #20403
- Learnings from claude-code source: Lessons from claude-code-main? #20475
Metadata
Metadata
Assignees
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
Activity
rekram1-node commentedon Apr 1, 2026
closing due to issue spam