How do I find session ids for -s/--session?
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
/sessionscommand, I see (non-unique) names and timestamps, but no ids - Maybe it'd be helpful to add an
opencode sessionssub-command to the cli to list sessions with their ids, for the user to copy/paste into-s/--session
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
/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
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 "
}
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
},
})
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
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.
@0xRango yes but you're gonna be unhappy because its not user friendly ids
@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.
we allow u to do -c and --session
for OP:
added session list command in next release: https://github.com/sst/opencode/commit/a8ad74aef3f8b6cd84c76855cbbb30f4fb472b86
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
Thanks! Confirmed opencode session list is now working in 1.0.129.
