Skip to main content
← All posts
A 30s South Asian software engineer in a white linen shirt at a standing desk with three monitors showing macOS, Linux, and Windows terminals displaying file paths in warm coral text on near-black backgrounds, Wallpaper* editorial composition
·6 min read

Opencode Session History 2026: File Locations + Recovery

Where Opencode stores session files on macOS, Linux, and Windows, how to recover broken sessions, and how to search and back up your history.

Opencode writes every session to disk the moment you start it. This is the right behavior. It means nothing is lost between restarts, and the full history of your agent conversations sits in plain JSON on your machine, ready to search. The problem most engineers hit is finding the files. The paths vary by platform, the folder structure is not obvious from the CLI, and recovery from a broken session involves file operations the docs do not fully explain. This guide covers the exact storage paths on macOS, Linux, and Windows, then walks through the two recovery scenarios worth knowing before you need them.

Where Opencode Stores Session History by Platform

The storage root depends on your operating system and whether you have customized your user data directory. On macOS, Opencode follows the Apple convention and writes to ~/Library/Application Support/opencode/. On Linux it respects the XDG Base Directory Specification, with the default at ~/.local/share/opencode/, but if you have set XDG_DATA_HOME to something custom, Opencode writes there instead. On Windows, the root is %APPDATA%\opencode\, which typically resolves to C:\Users\<you>\AppData\Roaming\opencode\.

Inside that root, Opencode creates one subfolder per project. The subfolder name is a hash derived from the absolute path of the directory where you ran opencode. A project at /Users/you/work/api becomes something like project/a1b2c3d4/. Inside each project folder you will find storage/session/, then three subdirectories: info/ for session metadata, message/ for per-turn transcripts, and sometimes part/ for in-progress streamed chunks. This three-layer layout is consistent across all platforms once you are inside the platform-specific root.

Find Your Session Files Fast on Any OS

The fastest way to verify the path and see your most recent sessions is a one-liner matched to your platform. These commands print the five most recent session info files, sorted by modification time, which gives you session IDs and timestamps you can use in any follow-up lookup. Run one of these in a fresh terminal, not necessarily inside the project directory, since the goal is to see sessions across all projects at once. The output is a list of paths ending in a UUID filename, each one a session you can grep, open, or archive directly.

  • macOS: ls -lt ~/Library/Application\ Support/opencode/project/*/storage/session/info/*.json | head -5
  • Linux: ls -lt ~/.local/share/opencode/project/*/storage/session/info/*.json | head -5
  • Windows (PowerShell): Get-ChildItem "$env:APPDATA\opencode\project\*\storage\session\info\*.json" | Sort-Object LastWriteTime -Descending | Select-Object -First 5

If you get no output on Linux, check your XDG_DATA_HOME. Run echo $XDG_DATA_HOME in the same terminal where you run Opencode. If it is empty, the default path applies. If it is set to something like /data/user, Opencode is writing to /data/user/opencode/ instead. The same logic applies to Docker or WSL setups where the home directory resolves differently than expected. Our earlier guide on Opencode chat history file locations covers the internal file schema in depth once you have confirmed the root path.

How Session Recovery Works

Recovery comes up in two situations. The first is a clean recovery: you closed Opencode intentionally or it crashed, and you want to continue the session. Run opencode --continue from the same project directory, and the CLI reloads the most recent session automatically. For older sessions, start Opencode in that project root, then use the /sessions command inside the TUI to pick from a list sorted by recency. The agent reconstructs context from the message files on disk and you are back in the conversation.

The second situation is messier: a session was interrupted mid-stream, and the final assistant response is missing or truncated. This happens when you force-quit the terminal, hit a network timeout during a long tool call, or kill the process mid-generation. Check the part/ folder for that session ID. Opencode streams assistant responses by writing chunk files to part/<session-id>/ as they arrive, then coalesces them into the final message/<session-id>/<message-id>.json once the stream closes. If the process died before coalescing, the full text sits in numbered chunk files you can concatenate manually with cat part/<session-id>/*.json | jq -r '.content' to recover the partial response. The pattern is the same as what Codex CLI does for in-progress responses, and the same concatenation trick applies there.

Searching Across Sessions Without Opening Files

Once you know where the files are, the full session history becomes greppable in a way that beats any in-app search. The message files are plain JSON with a content or parts field containing the text. On macOS and Linux, grep -r "search term" ~/.local/share/opencode/project/*/storage/session/message/ returns every session and message that contains the phrase. Add jq -r '.parts[].text' in a pipeline if you want cleaner output than raw JSON. On Windows, Select-String with -Recurse does the same job.

This matters most for work review. If you want to find every session where Opencode modified a migration file, search for the filename. If you want all sessions where you discussed a specific API endpoint, search for that path. The plain-file approach Opencode uses means your session history integrates naturally with your existing shell toolchain, your backup software, and any indexer you already run on your home directory. For comparison, Claude Code stores sessions as JSONL under ~/.claude/projects/, and the same grep-first workflow transfers directly.

Backing Up and Moving Sessions to a New Machine

Backing up Opencode sessions is the same as backing up any directory. Point your backup tool at the platform root and you are done. Time Machine on macOS covers it automatically. On Linux, include the XDG data directory in your rsync or restic config. The one complication when moving sessions to a new machine is the project-hash folder name. The hash is derived from the absolute path of your project directory. If the project lives at /Users/alice/work/api on the old machine and /Users/bob/work/api on the new one, the hashes differ and Opencode will not map the sessions to the project automatically.

The fix is to rename the project folder on the new machine to match the hash from the old one, or to symlink it. Run ls ~/Library/Application\ Support/opencode/project/ on both machines and compare the hash names. Copy the folder from the old machine into the correct location on the new one, and the sessions appear in /sessions on the next launch. The same project-hash challenge comes up when migrating Codex CLI chat history to a new machine, since Codex uses a similar hashed folder layout. For larger setups where you work across many repos, keeping a plain text map of project-path to project-hash in a dotfiles repo saves time on the third migration.

FAQ

How do I find the project-hash for my current directory?

Start Opencode in the project root and open /sessions. The status bar or session list shows the full storage path, which contains the hash. Alternatively, run opencode once, exit immediately, and check which new folder appeared under the platform root with ls -lt sorted by modification time. Either method gives you the hash without any extra calculation.

Can I store Opencode sessions on a different drive or cloud folder?

Yes. On Linux, set XDG_DATA_HOME to a path on the drive you want before starting Opencode. On macOS, symlink ~/Library/Application Support/opencode/ to the target path before the first launch. iCloud, Dropbox, and Syncthing all work, with the small caveat that you should not have the same session open on two machines simultaneously, since concurrent writes can produce conflicting files.

What happens if a session file is corrupted or empty?

Opencode skips malformed session files on startup without crashing. The session will not appear in /sessions, but all other sessions remain intact. Open the info JSON in a text editor and verify it is valid JSON with a sessionId field. A missing or zero-byte file usually means a write was interrupted mid-flush, which the concatenation approach in the recovery section above can partially address.

Does Opencode delete old session files automatically?

No. Sessions accumulate indefinitely by default. A quarterly cleanup of sessions older than your retention preference is reasonable and straightforward, since the plain-file format makes selective deletion easy with a one-line find -mtime command. Sort by modification time, archive sessions older than 90 days to a compressed tarball, and delete the originals.

Read your Opencode sessions like proper documents, not raw JSON.

Free to start — no credit card.

Open Prism MD free →

Related reading

Ready to read your own AI documents?

Open ChatGPT, Claude, Gemini, or any markdown file in the reader built for the way models write.

  • ✓Renders code, math & Mermaid out of the box
  • ✓Works offline once you've opened a doc
  • ✓Free forever for personal reading