Skip to content

Allow --session flag to accept session title/name, not just ID #12404

@yanlipnican

Description

@yanlipnican

Feature Request

Allow opencode -s / --session to accept a session title (name) in addition to a session ID.

Problem

Currently, --session only accepts a session ID like ses_3cf7dd8d4ffeUPfENpVxfFojZ2. This makes it impractical to script session resume workflows — for example, automatically resuming a specific session when opening a git worktree.

The session ID is opaque and changes every time, so there's no way to create a stable mapping like "always open this session for this worktree".

Proposed Solution

If the value passed to --session starts with ses_, treat it as an ID (current behavior). Otherwise, treat it as a title search using the existing GET /session/?search=<term> API endpoint.

# Current (still works)
opencode -s ses_3cf7dd8d4ffeUPfENpVxfFojZ2

# Proposed
opencode -s "my feature session"

If multiple sessions match, pick the most recently updated one. Exact title match should take priority over substring match.

Implementation Notes

This is a small change (~20 lines) in two files:

  1. packages/opencode/src/cli/cmd/run.ts — headless mode session resolution
  2. packages/opencode/src/cli/cmd/tui/app.tsx — TUI mode session resolution

The server-side search-by-title API already exists (GET /session/?search=<query> does case-insensitive substring matching), so no backend changes are needed.

Use Case

When using git worktrees with a terminal multiplexer (e.g., zellij), you want to automatically open/resume the correct opencode session for each worktree:

# In a zellij layout or lazygit custom command
opencode --port -s "feature/dark-mode"

This would resume the session titled "feature/dark-mode" if it exists, or could be combined with --title to create one with that name if it doesn't.

Metadata

Metadata

Assignees

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