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

Closed
opened 2026-02-16 18:10:31 -05:00 by yindo · 1 comment
Owner

Originally created by @yanlipnican on GitHub (Feb 5, 2026).

Originally assigned to: @thdxr on GitHub.

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.

Originally created by @yanlipnican on GitHub (Feb 5, 2026). Originally assigned to: @thdxr on GitHub. ## 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. ```bash # 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: ```bash # 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.
yindo closed this issue 2026-02-16 18:10:31 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 5, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8336: Better session resume ergonomics - directly addresses difficulty in finding and resuming sessions by name/context
  • #3434: Feature request to start and continue a session with arbitrary string identifier instead of just IDs
  • #11680: CLI --continue --session syntax for persisting sessions and scripting session workflows
  • #11499: Search for a session in given workspace by name instead of ID
  • #2404: Headless mode --resume functionality for CLI-based session resumption

Additionally, these related issues show ecosystem demand for better session naming/identification:

  • #9292: Expose session context (including OPENCODE_SESSION_TITLE) to child processes via environment variables
  • #12158: Inject OPENCODE_SESSION_ID into shell command environment
  • #5579: Mirror parent session name to child sessions

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 5, 2026): This issue might be a duplicate of existing issues. Please check: - #8336: Better session resume ergonomics - directly addresses difficulty in finding and resuming sessions by name/context - #3434: Feature request to start and continue a session with arbitrary string identifier instead of just IDs - #11680: CLI --continue --session syntax for persisting sessions and scripting session workflows - #11499: Search for a session in given workspace by name instead of ID - #2404: Headless mode --resume functionality for CLI-based session resumption Additionally, these related issues show ecosystem demand for better session naming/identification: - #9292: Expose session context (including OPENCODE_SESSION_TITLE) to child processes via environment variables - #12158: Inject OPENCODE_SESSION_ID into shell command environment - #5579: Mirror parent session name to child sessions Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8666