opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add CLI flags support to attach command

Open simondmorias opened this issue 1 month ago • 4 comments

Summary

Add support for --model, --session, --continue, --prompt, --agent, --title, and --command flags to the opencode attach command, bringing feature parity with the main TUI and run commands.

Changes

  • Added CLI flags to AttachCommand builder:

    • --model / -m - Model to use (format: provider/model)
    • --session / -s - Session ID to continue
    • --continue / -c - Continue the last session
    • --prompt / -p - Prompt to use
    • --agent - Agent to use
    • --title - Title for the session
    • --command - Command to run (uses prompt for args)
  • Updated Args interface to include title and command properties

  • Implemented stdin piping support for prompts in attach command

  • Added command pre-fill support in home route - prepends / to command name and combines with prompt

  • Updated documentation with complete flag reference and usage examples

Usage Examples

# Attach with specific model and agent
opencode attach http://localhost:4096 --model anthropic/claude-3-5-sonnet --agent build

# Attach and continue last session
opencode attach http://localhost:4096 --continue

# Attach with pre-filled command
opencode attach http://localhost:4096 --command commit --prompt "with conventional format"

# Attach and provide initial prompt
echo "Review this code" | opencode attach http://localhost:4096 --prompt "and suggest improvements"

# Attach to specific session with title
opencode attach http://localhost:4096 --session abc123 --title "Bug fix session"

Files Changed

  • packages/opencode/src/cli/cmd/tui/attach.ts - Added flag definitions and argument passing
  • packages/opencode/src/cli/cmd/tui/context/args.tsx - Extended Args interface
  • packages/opencode/src/cli/cmd/tui/routes/home.tsx - Added command pre-fill logic
  • packages/web/src/content/docs/cli.mdx - Added attach command documentation

Testing

  • No new TypeScript errors introduced (verified with bun typecheck)
  • All flags follow the same patterns as the thread command for consistency
  • Documentation includes examples and complete flag reference
  • Manual test: bun run --cwd packages/opencode --conditions=browser src/index.ts \ attach http://localhost:4096 --agent plan

Notes

  • The --format flag was intentionally not added as it's only relevant for non-interactive output (like the run command), not for the TUI
  • Pre-existing TypeScript errors in script/build.ts and src/mcp/index.ts are unrelated to these changes

simondmorias avatar Nov 26 '25 16:11 simondmorias

/review

rekram1-node avatar Dec 17 '25 17:12 rekram1-node

/review

rekram1-node avatar Dec 24 '25 04:12 rekram1-node

lgtm

github-actions[bot] avatar Dec 24 '25 04:12 github-actions[bot]