Skip to content

Add --session flag to opencode attach command #5445

@charles-cooper

Description

@charles-cooper

Summary

Add a --session / -s flag to opencode attach to navigate directly to a specific session when attaching to a running server.

Problem

The docs describe opencode serve as enabling "multiple clients" to interact with opencode programmatically. However, there's no clean way to attach a TUI to an existing server and open a specific session.

Currently:

  • opencode -s <session_id> starts a new server, defeating the purpose of opencode serve
  • opencode attach <url> connects to an existing server but has no way to specify which session to open

This means opencode serve can't really be used as intended - any TUI interaction requires starting a separate server.

Proposed Solution

// attach.ts
.option("session", {
  alias: ["s"],
  type: "string",
  description: "session id to navigate to",
})
// ...
await tui({
  url: args.url,
  args: {
    sessionID: args.session,
  },
})

Usage

opencode attach http://localhost:4096 -s ses_abc123

The tui() function already accepts sessionID in its args, so this is a one-line change.

Metadata

Metadata

Assignees

No one assigned

    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