opencode
opencode copied to clipboard
feat: add CLI flags support to attach command
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
titleandcommandproperties -
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
threadcommand 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
--formatflag was intentionally not added as it's only relevant for non-interactive output (like theruncommand), not for the TUI - Pre-existing TypeScript errors in
script/build.tsandsrc/mcp/index.tsare unrelated to these changes
/review
/review
lgtm