Sessions, snapshots and undo

Find and resume past sessions, run several in parallel on one project, and use snapshot-based undo when an edit was the wrong direction.

Sessions are local and resumable

Every conversation is a session stored on your machine under OpenCode's data directory, keyed by project. That means you can close the terminal, come back tomorrow, and continue with the agent still holding the thread of what it was doing.

# inside the TUI
/new             # start a fresh session
/sessions        # list and switch between sessions
/export          # dump the current conversation to markdown
/share           # create a link (only if sharing is enabled)

# from the shell
opencode run -c "now add a test for the case we just discussed"   # continue the latest
opencode run --session <id> "and update the changelog"
  • Sessions are stored per project, so switching directories gives you a different list.
  • Session history is data on disk: it can contain pasted secrets, so treat the data directory as sensitive.
  • A long session degrades in the same way any long conversation does - start a new one per task and let the old one stay searchable.

Snapshots and undo

Before it edits anything, OpenCode records a snapshot of the working tree. Undo restores files to the state they were in at that point, which makes an agent's wrong turn reversible without you reconstructing the previous version by hand.

# in the TUI
/undo            # revert the last change set
/redo            # put it back if you changed your mind

# the underlying safety net is still git
git status --short
git stash push -m "before agent experiment"
SituationBest recovery
The last edit was wrong/undo
Several changes back were wrongRestore the file from git
Experimenting with a risky approachBranch or stash first, then undo freely
Uncommitted work mixed ingit stash before the session
⚠️
A snapshot restores files, not your uncommitted work from other tools, and not untracked files the agent never touched. Commit or stash before a large agent task anyway: version control is a stronger guarantee than any in-tool undo, and it produces a reviewable diff afterwards.

Running sessions in parallel

# two terminals, one repository, two independent tasks
# terminal A
opencode run "add pagination to the orders endpoint"

# terminal B - a different area of the tree
opencode run "upgrade the test runner and fix the fallout in tests/"

# a headless server one client can attach to
opencode serve --port 4096
  • Parallel sessions are safe only when they touch disjoint files; two agents editing the same file will overwrite each other.
  • Run git worktree add for genuinely independent work and give each session its own directory.
  • Use parallel sessions for research - one reading the codebase, one checking the docs - and serialise anything that writes.
  • Keep an eye on cost: each session is a separate conversation bill.
git worktree add ../proj-pagination -b pagination
cd ../proj-pagination && opencode

FAQ

Where are my sessions kept?
Under OpenCode's local data directory, organised by project and reachable with /sessions. They never leave the machine unless you explicitly create a share link, which is why the share setting defaults to manual.
Is /undo the same as git checkout?
No. Undo restores the files OpenCode snapshotted, at the granularity of its own change sets, and it works even in a directory that is not a git repository. Git still covers changes made by other tools and gives you a permanent, reviewable history - use both.

Permissions, privacy and secret handling Headless mode, the SDK and CI

Last refreshed 2026-09-18.