
I’ve been using OpenCode a lot lately.
One thing I didn’t notice was that every time I start opencode, even in the same directory, it always starts a new session.
Over time, there are a lot of saved sessions.
I checked using the opencode session list command and it has a bunch of sessions like this:
$ opencode session list
Session ID Title Updated
───────────────────────────────────────────────────────────────────────────────
ses_01a79c031ffeoTF781ma9DAYiR New session - 2026-08-09T07:56:48.462Z 10:14 PM · 8/9/2026
ses_02142df4bffeJZJCNI2flGgZiw New session - 2026-08-08T00:19:24.468Z 7:07 AM · 8/9/2026
ses_03051a679ffe7LNdjOeQQs8hC8 New session - 2026-08-05T02:08:57.735Z 9:10 AM · 8/5/2026
ses_03fb4423effeJSOWB6yROH3mzp New session - 2026-08-02T02:26:57.089Z 9:35 AM · 8/2/2026
ses_25fdf08f1ffetxmcBDVYGfI1Me Code functionality review 5:33 PM · 4/18/2026
ses_260544176ffe1iW1RyEcxgz102 Codebase review 3:20 PM · 4/18/2026One beautiful day, I wanted to start a project with a fresh, clean slate; no existing session should be available. So what I had to do was to delete all sessions.
Unfortunately, opencode didn’t have (yet) a way to delete all sessions in one command.
You can only delete a single session like this:
opencode session delete $sessionIDBut, with the power of the command line, you can still delete all opencode sessions using a one-line terminal command.
To make it work, you need to install the jq command line first.
For example, you can install jq on macOS with the Homebrew package manager like this:
brew install jqThen, here’s how to remove all opencode sessions with a one-line command:
opencode session list --format json \
| jq -r '.[].id' \
| xargs -r -n1 opencode session deleteBasically, you just need to list the OpenCode’s sessions in JSON format, extract all the IDs using jq, and execute the standard opencode session delete.
That’s it.
Now you can always fresh clean up your opencode sessions easily from Terminal.
As usual, if you have any questions or a better method, leave a comment below. Thanks for reading, and see you next time!