Where do OpenCode servers store messages and session info?

devv1.1.18
c87939arelease: v1.1.18
This post might have stale content, as dev is 3063 commits ahead.

say i build an opencode server: where do they store the messages/session info? in the file system?

Avatar of anthropic/claude-opus-4.5
Claude Opus 4.5
commented

This is very clear now. Let me summarize what I've found:

##Summary: Where OpenCode Stores Session/Message Data

Yes, OpenCode stores all session and message data in the file system using JSON files.

###Location

The storage root is at:

~/.local/share/opencode/storage/

This is derived from the XDG Base Directory Specification (xdgData) in packages/opencode/src/global/index.ts.

###Directory Structure

From the Storage module (packages/opencode/src/storage/storage.ts), data is organized as:

~/.local/share/opencode/storage/
├── session/<projectID>/<sessionID>.json    # Session metadata
├── message/<sessionID>/<messageID>.json    # Messages
├── part/<messageID>/<partID>.json          # Message parts (tool calls, etc.)
├── session_diff/<sessionID>.json           # File diffs per session
├── share/<sessionID>.json                  # Share info (if session is shared)
├── project/<projectID>.json                # Project metadata
└── migration                               # Migration version tracker

###Storage API

The Storage namespace provides simple CRUD operations:

  • Storage.write(key[], content) - Write JSON to key.json
  • Storage.read<T>(key[]) - Read JSON from key.json
  • Storage.update<T>(key[], fn) - Read-modify-write pattern
  • Storage.remove(key[]) - Delete a file
  • Storage.list(prefix[]) - List all files under a prefix

###Examples from Session code:

  • Create session: Storage.write(["session", projectID, sessionID], result)
  • Get session: Storage.read<Info>(["session", projectID, sessionID])
  • Save message: Storage.write(["message", sessionID, messageID], msg)
  • Save part: Storage.write(["part", messageID, partID], part)

So it's all plain JSON files on the local filesystem - no database involved!


END OF POST

Where do OpenCode servers store messages and session info? — anomalyco/opencode