opencode icon indicating copy to clipboard operation
opencode copied to clipboard

How do I find session ids for -s/--session?

Open jdanbrown opened this issue 1 year ago • 12 comments

Question

How do I find the session ids to use with opencode --session <session-id> to continue or resume a previous session?

$ opencode --help | grep -- --session
  -s, --session     session id to continue                              [string]
  • When I run the /sessions command, I see (non-unique) names and timestamps, but no ids
  • Maybe it'd be helpful to add an opencode sessions sub-command to the cli to list sessions with their ids, for the user to copy/paste into -s/--session

jdanbrown avatar Nov 20 '25 21:11 jdanbrown

u can use opencode export or opencode run if u use run with the --format json flag. But youre correct we need that sessions list command

rekram1-node avatar Nov 20 '25 21:11 rekram1-node

/oc Read cmd/ directory, introduce a new command called session, it should have a subcommand called "list" so youd call it like: opencode session list

It should function kinda like how git log works where it paginates if possible and it should show session ids in a way or with flag in a way it could easily be used in a ci script if needed

rekram1-node avatar Nov 20 '25 21:11 rekram1-node

Created PR #4558

New%20session%20-%202025-11-20T21%3A50%3A32.854Z opencode session  |  github run

opencode-agent[bot] avatar Nov 20 '25 21:11 opencode-agent[bot]

Nice!

Another interim workaround: grep around under ~/.local/share/opencode/ to find the ses_* id. 🙃

~/.local/share/opencode $ rg 'clean up my alignment code'
storage/part/msg_a9e135a170018Ui4RfAZfIDlfl/prt_a9e135a17002vkzEexEqH2pup3.json
6:  "text": "clean up my alignment code in @src/ios/TasksView_i.swift "

~/.local/share/opencode $ cat storage/part/msg_a9e135a170018Ui4RfAZfIDlfl/prt_a9e135a17002vkzEexEqH2pup3.json
{
  "id": "prt_a9e135a17002vkzEexEqH2pup3",
  "sessionID": "ses_561eca5ebffeCngoybZWxbTrD8",
  "messageID": "msg_a9e135a170018Ui4RfAZfIDlfl",
  "type": "text",
  "text": "clean up my alignment code in @src/ios/TasksView_i.swift "
}

jdanbrown avatar Nov 20 '25 21:11 jdanbrown

Another workaround is to use a very simple tool, like this:

$ cat .opencode/tool/get-current-session-id.ts 
import { tool } from "@opencode-ai/plugin"

export default tool({
  description: "Get the current session ID",
  args: {},
  async execute(args, context) {
    return context.sessionID
  },
})

daniel-fahey avatar Nov 22 '25 22:11 daniel-fahey

Requires extra tool - Agent Sessions. I recently added OpenCode support. You can visually or via search find your sessions and then copy ID from a toolbar - will get something like - ses_533cded24ffeEg9nWRBZHMGN7c

jazzyalex.github.io/agent-sessions native macOS app (signed and notarized)• open source

ses_533cded24ffeEg9nWRBZHMGN7c

Image

jazzyalex avatar Nov 29 '25 21:11 jazzyalex

Can we specify a session ID when starting opencode? But don't be like Claude Code which insists on using UUIDs — make it like tmux where you can specify any name you want.

chenyuejie avatar Nov 30 '25 07:11 chenyuejie

@0xRango yes but you're gonna be unhappy because its not user friendly ids

rekram1-node avatar Dec 03 '25 01:12 rekram1-node

@0xRango yes but you're gonna be unhappy because its not user friendly ids

Yes, so I wish I could define session id myself. Claude Code currently only supports adding -c to continue the last session — it's too difficult to resume other sessions.

chenyuejie avatar Dec 03 '25 01:12 chenyuejie

we allow u to do -c and --session

for OP:

added session list command in next release: https://github.com/sst/opencode/commit/a8ad74aef3f8b6cd84c76855cbbb30f4fb472b86

rekram1-node avatar Dec 03 '25 01:12 rekram1-node

we allow u to do -c and --session

for OP:

added session list command in next release: a8ad74a

Hi, I found that --session arg not support for custom session id, like --session-id of claude code. but the UUID s are very user-unfriendly. Can we use custom session id, like --session project1 to start new one or continue session?

chenyuejie avatar Dec 03 '25 05:12 chenyuejie

Thanks! Confirmed opencode session list is now working in 1.0.129.

jdanbrown avatar Dec 03 '25 21:12 jdanbrown