Skip to content

[FEATURE]: Native --stdin support for opencode run to handle large prompts without ARG_MAX errors #25508

@aleka

Description

@aleka

Problem Description

When using opencode run with large prompts (e.g., code reviews of 1700+ line files), the prompt is passed as a positional argument. This causes critical issues:

  1. ARG_MAX limit: On Linux, the maximum argument length is ~2MB. Large prompts exceed this, causing E2BIG: argument list too long errors before the command even executes.
  2. Performance: Passing large strings as command-line arguments is inefficient and slow.
  3. Workaround complexity: Currently requires writing to a temp file and using -f flag, which has security restrictions (files must be within project directory, see related issues).

Current Behavior

# This fails with large prompts (>2MB)
opencode run --model kimi-for-coding/kimi-k2-thinking "very large prompt..."

# Current workaround: write to file in project directory
echo "$prompt" > ./temp_prompt.txt
opencode run --model kimi-for-coding/kimi-k2-thinking "Review this" -f ./temp_prompt.txt

Proposed Solution

Add native --stdin support for opencode run:

# Option 1: Explicit --stdin flag
printf '%s' "$prompt" | opencode run --model kimi-for-coding/kimi-k2-thinking --stdin

# Option 2: Auto-detect stdin when no positional args
printf '%s' "$prompt" | opencode run --model kimi-for-coding/kimi-k2-thinking

Benefits

  • No ARG_MAX issues: Stdin has no practical size limit
  • Better performance: No command-line parsing of large strings
  • Simpler integration: Tools can pipe content directly without temp files
  • Security: No need to create temp files in project directory

Related Issues

Context

This issue was discovered while working with GGA, a tool that uses OpenCode for automated code reviews. When reviewing commits with large files, the prompt exceeds ARG_MAX limits, causing timeouts and failures.

Environment

  • OpenCode version: 1.14.33
  • OS: Linux (Ubuntu/Debian)
  • Shell: Bash 5.x
  • Use case: Automated code review via CI/CD pipelines

Verification

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions