How to create an empty session from the cli? #6818

Closed
opened 2026-02-16 18:05:21 -05:00 by yindo · 3 comments
Owner

Originally created by @FrancescoSaverioZuppichini on GitHub (Jan 19, 2026).

Originally assigned to: @jayair on GitHub.

Question

I would like to understand how to create a session from the cli and attach it's session id to the run command. The use case is that I want to run opencode with a command to a specific session and then start opencode on that session so I can continue.

Originally created by @FrancescoSaverioZuppichini on GitHub (Jan 19, 2026). Originally assigned to: @jayair on GitHub. ### Question I would like to understand how to create a session from the cli and attach it's session id to the `run` command. The use case is that I want to run opencode with a command to a specific session and then start opencode on that session so I can continue.
yindo added the docs label 2026-02-16 18:05:21 -05:00
yindo closed this issue 2026-02-16 18:05:21 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 19, 2026):

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

  • #8890: Better support remote/server-client use-cases from the CLI - Directly addresses attaching to existing sessions via CLI
  • #8948: Server Registry & Auto-Discovery for Persistent Sessions - About persistent session connections and auto-connecting to existing servers
  • #9011: Cannot 'attach' to an opencode server with a password - Related to the attach command functionality
  • #9387: opencode session export to markdown or json - About session CLI commands
  • #9292: Expose session context to child processes via environment variables - About accessing session ID from CLI

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

@github-actions[bot] commented on GitHub (Jan 19, 2026): This issue might be a duplicate of existing issues. Please check: - #8890: Better support remote/server-client use-cases from the CLI - Directly addresses attaching to existing sessions via CLI - #8948: Server Registry & Auto-Discovery for Persistent Sessions - About persistent session connections and auto-connecting to existing servers - #9011: Cannot 'attach' to an opencode server with a password - Related to the attach command functionality - #9387: `opencode session export` to markdown or json - About session CLI commands - #9292: Expose session context to child processes via environment variables - About accessing session ID from CLI Feel free to ignore if none of these address your specific case.
Author
Owner

@R44VC0RP commented on GitHub (Jan 19, 2026):

Hey 👋🏻

So you can do this by running the following:

Your Workflow

  1. Run a command (creates a session):

opencode run "Your initial prompt here"

  1. Find the session ID:

opencode session list

image.png
  1. Run another command on that session:

opencode run -s <session-id> "Follow-up prompt"

  1. Start the TUI to continue interactively:

opencode -s <session-id>

Shortcut: Continue Last Session

If you just want to continue the most recent session:

Run command on last session

opencode run -c "Follow-up prompt"

Or open TUI on last session

opencode -c

If this answers your question you can close this issue 🙂

@R44VC0RP commented on GitHub (Jan 19, 2026): Hey 👋🏻<br><br>So you can do this by running the following:<br><br>Your Workflow 1. Run a command (creates a session): `opencode run "Your initial prompt here"` 2. Find the session ID: `opencode session list` <img src="https://uploads.linear.app/a959060b-9262-4398-9650-16bf10f1450e/46300f76-783b-4c8b-8cea-1478c513e5fb/eefbcb91-0e56-4a68-bcfa-579fa89bfbb2?signature=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXRoIjoiL2E5NTkwNjBiLTkyNjItNDM5OC05NjUwLTE2YmYxMGYxNDUwZS80NjMwMGY3Ni03ODNiLTRjOGItOGNlYS0xNDc4YzUxM2U1ZmIvZWVmYmNiOTEtMGU1Ni00YTY4LWJjZmEtNTc5ZmE4OWJmYmIyIiwiaWF0IjoxNzY4ODQwMjU5LCJleHAiOjE4MDA0MTA4MTl9.jg15VaFhEPpYD1eSXN8762iAB1os3DtA3miwQs5S-3o " alt="image.png" width="1039" data-linear-height="171" /> 3. Run another command on that session: `opencode run -s <session-id> "Follow-up prompt"` 4. Start the TUI to continue interactively: `opencode -s <session-id>` ## Shortcut: Continue Last Session If you just want to continue the most recent session: ### Run command on last session `opencode run -c "Follow-up prompt"` ### Or open TUI on last session `opencode -c`<br><br>If this answers your question you can close this issue 🙂
Author
Owner

@FrancescoSaverioZuppichini commented on GitHub (Jan 20, 2026):

thanks a lot; will try :)

@FrancescoSaverioZuppichini commented on GitHub (Jan 20, 2026): thanks a lot; will try :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6818