Skip to content

New file structure for OpenCode v1.2 #61

@merphx

Description

@merphx

OpenCode v1.2.0 introduced a change to how it stores state:

This release includes a data migration that will execute on first run. It will migrate all flat files in data directory to a single sqlite database.

I have observed it prevents shared state from propagating between the host system and the coder container. E.g. running leash opencode --continue loads the last session from before upgrading to OpenCode v1.2.0 or later.

I had a coding agent do some exploration, and these are the new volume mounts that it suggested:

"~/.config/opencode" = "/root/.config/opencode:rw"
"~/.local/state/opencode" = "/root/.local/state/opencode:rw"
"~/.local/share/opencode/auth.json" = "/root/.local/share/opencode/auth.json:rw"
"~/.local/share/opencode/mcp-auth.json" = "/root/.local/share/opencode/mcp-auth.json:rw"
"~/.local/share/opencode/opencode.db" = "/root/.local/share/opencode/opencode.db:rw"
"~/.local/share/opencode/opencode.db-wal" = "/root/.local/share/opencode/opencode.db-wal:rw"
"~/.local/share/opencode/opencode.db-shm" = "/root/.local/share/opencode/opencode.db-shm:rw"
"~/.local/share/opencode/log" = "/root/.local/share/opencode/log:rw"
"~/.local/share/opencode/snapshot" = "/root/.local/share/opencode/snapshot:rw"
"~/.local/share/opencode/plans" = "/root/.local/share/opencode/plans:rw"
"~/.local/share/opencode/worktree" = "/root/.local/share/opencode/worktree:rw"

# Pre-v1.2.0 files
# These should be mounted at least once so OpenCode can migrate to the new format
# After that, there's no harm in keeping them, or they could be dropped
"~/.local/share/opencode/storage" = "/root/.local/share/opencode/storage:rw"

Relevant snippets from its analysis:

Major change: JSON to SQLite migration

What changed

Before v1.2.0 (v1.1.65):

  • Session data, messages, projects, and metadata stored as individual JSON files
  • Files organised in hierarchical directory structure under ~/.local/share/opencode/storage/
  • Each entity type (projects, sessions, messages, parts) had its own directory
  • File-level locking used for concurrent access

After v1.2.0:

  • All structured data consolidated into single SQLite database: ~/.local/share/opencode/opencode.db
  • Automatic migration from JSON files on first run
  • SQLite Write-Ahead Logging (WAL) mode for improved concurrency
  • Old JSON files in storage/ directory become legacy (can be deleted after migration)

Changes summary table

Component v1.1.65 v1.2.0+ Status
Session storage JSON files in storage/ SQLite opencode.db 🔄 Changed
Projects storage/project/*.json SQLite projects table 🔄 Changed
Messages storage/message/{sessionID}/*.json SQLite messages table 🔄 Changed
Authentication auth.json, mcp-auth.json Same ✅ Unchanged
Configuration ~/.config/opencode/ Same ✅ Unchanged
Logs log/ directory Same ✅ Unchanged
Cache ~/.cache/opencode/ Same ✅ Unchanged
Binaries bin/ directory Same ✅ Unchanged
Migration JSON file migrations Automatic JSON→SQLite 🔄 Changed
Concurrency File-level locks SQLite transactions 🔄 Changed

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions