[PR #4787] feat: add CLI flags support to attach command #11118

Open
opened 2026-02-16 18:15:54 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4787

State: open
Merged: No


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4787 **State:** open **Merged:** No --- ## 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 ```bash # 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
yindo added the pull-request label 2026-02-16 18:15:54 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11118