Session privacy
What OpenCode's --sanitize export removes, and what stays
I exported test sessions with planted fake secrets. --sanitize hid prompts, outputs and the folder but left error messages and file names. A check to run first.
Kifah Abbad Published Last verified 10 min read
The short answer. opencode session export --sanitize replaces your prompts, the assistant’s replies, tool inputs and tool outputs, the session title and the working directory with [redacted:...] placeholders. In my tests it did not remove tool error messages or the file names in the change list, and both can hold a full path or a name you wanted to keep private. Read the sanitized file, or run the small check below, before you send it to anyone.

Why this matters. A session export is the thing people attach to a bug report, and it holds your prompts, your code and your folder names. The flag sounds like a guarantee. It is a partial filter, and the parts it leaves out are the ones you would not think to look for: a failed command or a file name.
What you get. A table of what --sanitize changed and what it kept in OpenCode 2.3.2, how I tested it without using a real session, a short check you can run on an exported file, and a note on what Codex and Claude Code offer instead.
Who needs this
Possible scenario. You hit a bug in OpenCode and a maintainer asks for the session. You run the export with --sanitize, skim the first screen, see only placeholders, and attach it to a public issue. The file still has the error message of a failed read, with the absolute path of your project folder and the name of the file you were looking for.
| Role | What changes for them |
|---|---|
| Junior software engineer | Knows the flag is a first filter, not a clearance, and has a short list of what to look for before sharing. |
| DevOps or platform engineer | Can put the check into a script that runs on an export before it leaves the machine, and knows which fields it covers. |
| CTO or engineering lead | Learns that “sanitized” is not a policy: an export that leaves the company needs a review step, and the gaps are known. |
Table: who gains what, my reasoning, not measured. I did not measure time saved for any role.
How I tested it without a real session
I did not use any of my own sessions. I made a throwaway folder in a temporary directory, with a git repository and a small file, and ran opencode run there five times with prompts that made the agent read a file, run a shell command, write files and fail on purpose. Each prompt and each file carried an invented marker that does not exist anywhere else (CANARY-PROMPT-1187, CANARY-ERR-9910 and so on). Then for each session I ran opencode session export and opencode session export --sanitize, counted the markers in both files, and compared them field by field. Afterwards I deleted the five sessions and the folder, and checked that my real counts were unchanged: 1,215 OpenCode sessions, 201 Codex files, no Claude Code projects.
OpenCode 2.3.2, macOS, 20 November 2026, one run per case. The model behind it was served through a local proxy, so the content of the replies is not the point: what matters is which fields the export keeps.
What the flag removed
In the plain export of the same sessions every one of these was readable. With --sanitize:
- Replaced by a text placeholder such as
[redacted:text:msg_...]: your prompt text, the assistant’s reply text, tool output (file contents, shell output), the session title and the session’s working directory. - Replaced by an object
{"redacted": ...}: tool input (the command, the file path, the content written) and tool metadata (exit code, status, truncated).
Tested. Every marker I planted in a prompt, a file, a command, a written file and a command’s output was gone from the sanitized file.
What stayed
| What stayed readable | Why it can matter |
|---|---|
| The error message of a failed tool call | It holds the full absolute path of the project folder, the same path the flag hid in the session’s directory field, and the name of the file you tried to read |
| The names of files a step created or changed | A name such as notes-for-ACME-PROJECT-ZEBRA.md stays readable |
| IDs, timestamps, model and provider names | An ID links the file to your session; the provider name shows which service you use |
| Token counts and cost | Harmless alone, but they say how long and how expensive the session was |
Table: what is still readable in a sanitized export. Tested for the first two rows, one run each. In the JSON they are state.error.message on a tool entry and snapshot.files on a message; an example of the first is File not found: <full path>/nothing-here-....txt.
In one run, a failed shell command (ls on a missing name) was sanitized correctly: its output is in tool-output, and the whole tool state was redacted. A failed read call (the dedicated read tool, not the shell) ended in the error state, and its message was left in the file. So whether an error is exposed depends on which kind of tool produced it. I tested one of each, not every tool.
What the project says
I read the project’s documentation and issue tracker on 20 November 2026:
- The command reference says the flag “redact[s] sensitive transcript and file data” and the CLI help says the same.
- A GitHub issue reports that sanitize “leaves native data, error text and historical paths unredacted”. A maintainer bot reproduced it on 2.2.5. The same bot noted that an existing test expects a failed compaction’s error message to stay as it is, so keeping error text may be deliberate.
- A pull request adds a sentence to the documentation saying that error messages can remain and that the JSON should be reviewed before sharing. It was open when I read it.
- Two older issues are closed: one about a
pathfield ininfo(closed in August after a fix was proposed) and one about the full conversation stored by native compaction (closed in October; its text says the sanitizer then skipped that data).
Those are reports, not something I reproduced, apart from the error message which I did reproduce. The consequence is the same either way: the flag is a work in progress, and the file needs to be read.
A check to run before you share it
A 13-line script (sh and jq) that prints what to review:
#!/bin/sh
# usage: checklist.sh session.json "private words separated by |"
F=$1; MINE=$2
echo "1. your own private words, your home path and user name:"
grep -n -i -E "$MINE|$HOME|$USER" "$F" | cut -c1-110
echo "2. common secret shapes:"
grep -n -E 'AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{36}|sk-[A-Za-z0-9]{20,}' "$F" \
| cut -c1-110
echo "3. tool error messages (not redacted):"
jq -r '.messages[].content[]? | select(.type=="tool")
| .state.error.message? // empty' "$F"
echo "4. file names in snapshots (not redacted):"
jq -r '.messages[].snapshot.files[]?' "$F"
On my last test session it printed the full path of my test folder inside an error message, the invented key name I had put in a file name, and a project-code word in a file name. It also matched the secret-shape pattern on the error message, because I had put an example AWS key name in the file I asked the tool to read.
It checks four places. It does not prove the file is clean: it only looks for words and shapes you give it or that I thought of, and it only reads the fields I found. Treat an empty result as “nothing I looked for”, not “safe”.
Other tools
- Codex CLI 0.170.0. Its command list and the vendor’s CLI reference have no export command and no redaction flag. Sessions are JSONL files on disk. I read the reference and the
--helpof the commands; I did not look for a redaction feature in the desktop app. Sharing a session means copying a file, and nothing filters it for you. - Claude Code 2.1.173. There is an in-session
/exportcommand. The vendor’s commands page describes it as exporting the conversation as plain text, and it does not mention redaction. I did not run it for this post. When I tried it on 19 November, in print mode, it answered that/exportwas not available in that environment; my export post has the details.
In both cases the answer to “what does it remove” is “nothing, as far as the documentation says”. That makes the review step more important, not less.
What to do on Monday
- Export with
--sanitizeevery time you share an OpenCode session. It is better than the plain export. - Run the check above on the file, with a few words of your own: a client name, a project code name, a host name.
- Open the file and read the error messages and the file list by eye. Both are short.
- If an error message or a file name is private, edit the file or send a shorter excerpt.
- If the session mattered, check whether a screenshot or a short excerpt would do instead of the whole file.
Windows and Linux
Tested on Linux, documented or assumed for Windows, nothing run there. On 20 November 2026 I ran the whole check in an Ubuntu 24.04 container (grep 3.11, jq 1.7) on a made-up export: it printed all four blocks, with the planted words, the key shape, the error message and the file name (tested). I did not run opencode there.
$USERcan be empty. In that bare container$USERwas not set, so the pattern ended in a bare|(...|/root|), which matches every line (tested: 2 matching lines out of 2 where 1 was right). On macOS withUSERunset,grepstopped with an error (tested). If your shell does not set it, putUSER=rootor your own name in front of the command; I ran it that way withUSER=rootand it printed only the matching line (tested).- A Windows home path will not match. JSON writes each backslash twice, so a home folder
C:\Users\meappears in the file asC:\\Users\\me. In my testgrep -F 'C:\Users\me'found 0 lines in the raw JSON, whilejq -r '.. | strings'followed by the samegrepfound it (jq1.7.1 on macOS, 1.7 on Ubuntu; a made-up path; tested). So on Windows I expect line 1 of the check to miss your home folder unless you search the decoded text (assumed for Windows). The check also needssh, so run it in WSL. - Windows, tools.
jqhas awingetpackage and executables (documented: thejqdownload page). Where OpenCode keeps its database on Windows: session formats.
What I did not test
- Other versions. I ran 2.3.2. The behaviour changed over time according to the issue tracker, so a different version may redact more or fewer fields.
- Other tools and other error kinds. I tested a failed read and a failed shell command. A failed web fetch, a failed MCP call, or a compaction error may behave differently.
- Sessions with attachments, images or native compaction. I used text only. The issue tracker says such data was a gap that was closed in October; I did not reproduce it.
- How often a secret appears in a real session. I planted invented secrets. I did not measure how many real sessions carry a path or a key in an error message.
- The Codex and Claude Code export paths in practice. I read their documentation and help text; I did not run an export in either.
- Windows and Linux. Nothing ran on Windows. On Linux I ran the check on a made-up file, not
opencode. See Windows and Linux.