Skip to content

Conversation

@simondmorias
Copy link

@simondmorias simondmorias commented Nov 26, 2025

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

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 all missing CLI flags to AttachCommand builder
- Updated Args interface to include title and command properties
- Implemented stdin piping support for prompts
- Added command pre-fill support (prepends / to command name)
- Updated documentation with complete flag reference and examples

This allows users to attach to a running server with pre-configured settings like:
  opencode attach http://localhost:4096 --model anthropic/claude-3-5-sonnet --agent build
  opencode attach http://localhost:4096 --command commit --prompt 'with conventional format'
@simondmorias simondmorias marked this pull request as ready for review November 26, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant