Session health

Export OpenCode, Codex and Claude sessions to Markdown

OpenCode exports JSON, Codex writes Markdown, Claude Code writes plain text. Three jq filters give one readable file per session. Tested on real sessions.

Kifah Abbad, smiling, in a scarf and jacket on a Berlin street

Kifah Abbad Published Last verified 11 min read

The short answer. OpenCode exports a session as JSON (opencode session export <id>), Codex and Claude Code export from inside a live session, and one short jq filter per agent turns any of them into the same readable Markdown. The three filters and what each drops are below.

Three kinds of session file, an OpenCode export, a Codex rollout and a Claude Code transcript, each go through a jq filter and come out as one session.md file.

Why this matters. A session with a coding agent holds decisions, dead ends and the reasoning behind a change, and it is easy to lose or impossible to read where it is stored. Exported as Markdown it becomes a file you can search, read, keep next to the code, paste into a review, hand to a colleague or feed to another tool.

What you get. One readable file per session, in the same shape from OpenCode, Codex and Claude Code, so a single search finds a session from any of them. You need this when you finish a long session you want to keep, or when you want to reuse one somewhere else.

Each agent gives you something different today: OpenCode exports JSON, Codex writes Markdown, Claude Code writes plain text, and two of the three work only inside a live session. This post shows the three exports and three short jq filters that turn them into the same Markdown. The conversion took under a second on every session I tried, including a 488-message one.

Every claim carries a label: tested (run on 19 November 2026 on copies of my own data), assumed (from the vendor’s documentation or source, not run), or not tested. I read counts, sizes and key names, never message content. Versions: OpenCode 2.3.0, jq 1.7.1, zstd 1.5.7; Claude Code 2.1.173 and the Codex command line 0.170.0, both run through a local model proxy (see the sections on each). This post covers how to get the file. Where each agent keeps its sessions on disk is on the collector’s reference page.

Who needs this

Possible scenario. You close a Jira ticket after a long back-and-forth with the agent. Two weeks later a reviewer asks why the retry logic was written that way, or a colleague hits the same bug. The reason is in the session, and the session is in a database or a folder of JSON you cannot read or search. Exporting it to Markdown when you finish costs seconds; reconstructing the reasoning later does not.

RoleWhat changes for them
Senior software engineerHands over or reviews work with the conversation attached, instead of a diff alone.
DevOps or platform engineerCan script the export for every session and store it with the repository or in a backup.
CTO or engineering leadGets sessions in one format regardless of which agent a team member uses, which is the precondition for any audit or sharing.

Table: who gains what, my reasoning, not measured. I did not measure time saved for any role.

What each agent gives you today

OpenCodeCodexClaude Code
Commandopencode session export <id>/export in the session/export [filename] in the session
OutputJSONMarkdownplain text
Works for a session you are not inyes, by idno, slash commandno, slash command
Read straight from diskno, databaseyes, one JSONL file per sessionyes, one JSONL file per session

Table: the built-in way to get a transcript out of each agent. OpenCode was run; the Codex and Claude Code rows come from their command listings (Codex source at commit 6eea328, Claude Code’s command reference), not from running them.

The built-in exports leave a gap. OpenCode’s is JSON that nobody wants to read. The other two work only from inside a live session, and only for the one that is open. For all your past sessions, you read the files on disk.

OpenCode: export, then convert

opencode session export ses_YOURID > session.json

Without an id it asks you to pick one, and refuses to run when there is no terminal: “Pass a session ID when running without an interactive terminal” (tested). opencode session list --format json gives you the ids. The export has two keys, info and messages. A message is one of user, assistant, system, synthetic or compaction, and an assistant message holds text blocks and tool blocks.

Add --sanitize before you share a file. It replaces text, summaries, tool input and tool output with a placeholder such as [redacted:text:msg_…]: the structure survives, the content does not (tested). I did not check here how well it catches secrets, so treat it as a first pass: a later post tests it and finds that error messages and file names stay readable.

This filter writes Markdown, keeping your prompts, the assistant’s text, a one-line list of the tools it called, and any compaction summary:

jq -r '"# \(.info.title // "Untitled")\n",
(.messages[]
 | if .type == "user" then "## You\n\n\(.text)\n"
   elif .type == "assistant" then
     ([.content[]? | select(.type == "text") | .text] | join("\n\n")) as $text
     | ([.content[]? | select(.type == "tool") | "- tool: \(.name)"]
        | join("\n")) as $tools
     | select($text != "" or $tools != "")
     | "## Assistant\n\n\($text)\n\n\($tools)\n"
   elif .type == "compaction" then
     "## Compaction summary\n\n\(.summary // "")\n"
   else empty end)' session.json > session.md
Message type in the exportWhat the filter writes
usera “You” section with your text
assistantan “Assistant” section: its text, then one line per tool it called (the name only); nothing if it has neither
compactiona “Compaction summary” section (what compaction is, and how often it fires on my sessions: measured here; what each agent does: the compaction reference)
system, syntheticnothing

Table: what the filter above does to each message type. Tool input and tool output are not kept.

I ran it on three sessions from a copy of my database:

SessionJSONMarkdownTimeSections
21 messages497,271 B37,554 Bunder 1 s1 You, 19 Assistant
105 messages1,271,062 B29,904 Bunder 1 s10 You, 85 Assistant
488 messages3,071,603 B275,606 B1 s71 You, 399 Assistant, 2 Compaction

Table: size and time of the conversion on three real sessions (OpenCode 2.3.0, jq 1.7.1, 19 November 2026). The Markdown is 11 to 42 times smaller, because tool output is not kept.

That is the point and the cost: the tool calls appear as names only, with no input and no output. If you need what a command printed, read the JSON. The filter is a starting point, not a faithful archive.

Codex: it writes Markdown, and the files on disk convert the same way

Inside an interactive session, /export saves the conversation as Markdown (assumed, from the source: the command is described as “export the conversation as markdown” and takes a file path). I could not run it: in codex exec the text is treated as a prompt, not as a command, and I could not drive the interactive screen. For sessions you are not in, read the rollout file. Codex keeps old ones compressed (see the earlier finding), so a reader has to handle .jsonl.zst too:

FILTER='select(.type == "response_item" and .payload.type == "message"
  and (.payload.role == "user" or .payload.role == "assistant"))
| ([.payload.content[]? | .text] | join("\n\n")) as $text
| select($text != ""
  and ($text | test("^\\s*<(environment_context|user_instructions|INSTRUCTIONS)") | not)
  and ($text | test("^# AGENTS.md") | not))
| "## \(if .payload.role == "user" then "You" else "Assistant" end)\n\n\($text)\n"'

jq -r "$FILTER" rollout-….jsonl > session.md
zstd -dc rollout-….jsonl.zst | jq -r "$FILTER" > session.md

Codex adds its own text to the conversation: your AGENTS.md, the environment, instructions. The filter drops those. In the plain rollout I tried, 28 user messages became 24 You sections, so four were injected context (tested). The compressed one gave 1 You and 3 Assistant sections in 7 KB. Neither file needed more than a second.

Claude Code: a built-in text export, and one JSONL shape to convert

Tested on two real Claude Code sessions, both short, both from print mode (claude -p) on 19 November 2026, version 2.1.173. Neither was a long interactive session with tool-heavy work, so I have not seen what a transcript with subagents, images or compaction records looks like. Check the counts (see “Check the result”) on your own sessions before you rely on the filter.

/export writes the conversation as plain text, with a filename argument or a dialog (documented). I could not run it: in print mode it answers “/export isn’t available in this environment”, and it is a command for an interactive session, which I did not manage to drive. To convert the files on disk, the transcript is one JSON object per line with a message.role and either a string or a list of content blocks:

jq -r 'select(.message.role == "user" or .message.role == "assistant")
| (if (.message.content | type) == "string" then .message.content
   else ([.message.content[]? | select(.type == "text") | .text]
         | join("\n\n")) end) as $text
| select($text != "")
| "## \(if .message.role == "user" then "You" else "Assistant" end)\n\n\($text)\n"' \
  session.jsonl > session.md

On the two real sessions it gave 1 You and 1 Assistant section each, from four or five transcript lines: your prompt and the model’s final text. The lines that hold a tool call, the model’s thinking and a tool result produce no section, because they have no text block (tested). So the Markdown is 116 bytes from an 11 KB transcript in one case. That is the same trade as the OpenCode filter: the dialogue survives, the tool use does not.

One thing it would miss: when Claude Code asks you a question through its question tool, the question is a tool call, so it is not in the Markdown. In my second session the model’s reply repeated the questions, which is the only reason they appeared (tested, once).

The gap, and what would be better

This is not available today. A developer working with agents would want one export command that behaves the same in all three: works on any session by id without opening it, writes Markdown, says what it dropped, and has a flag to include tool calls and results. Today you need three commands, and two of them work only inside a live session.

Check the result

A conversion that silently drops messages is worse than none. Count the sections against the source:

jq '[.messages[] | select(.type == "user")] | length' session.json
grep -c '^## You' session.md

The two numbers must match for OpenCode (they did on all three sessions above). For Codex they differ by the injected context blocks: 28 user messages gave 24 sections in my plain rollout, and the 4 dropped were all <environment_context> or AGENTS.md text (tested). For Claude Code, expect fewer sections than JSON lines, because tool-result lines are skipped.

Ten minutes: one script for your whole history

opencode session list shows only the sessions of the project you are standing in (27 from my monorepo folder, 3 from /tmp; tested). The paged API lists all of them: the loop below follows the cursor until it is empty, and wrote 1,212 unique ids in about a second (tested).

cursor=""
while :; do
  page=$(opencode api get "/api/session${cursor:+?cursor=$cursor}")
  printf '%s' "$page" | jq -r '.data[].id'
  cursor=$(printf '%s' "$page" | jq -r '.cursor.next // empty | @uri')
  [ -z "$cursor" ] && break
done > ids.txt

mkdir -p ~/session-md
while read -r id; do
  opencode session export "$id" | jq -r -f opencode.jq \
    > ~/session-md/opencode-$id.md
done < ids.txt

I tested the export-and-convert half on 8 random sessions (1 second, no empty files) and the listing on all 1,212, but not the second loop over all of them. Estimate: 8 sessions took about 1 second, so 1,212 should take about 2.5 minutes if the cost is linear in the count; session sizes vary, so it could be several times that. The ${cursor:+...} form is written for sh and zsh; I ran the listing as a zsh script that does the same.

If you used our app

AgentsOfMine is our product. If you synced a session with the collector, the app can show it and export it: Settings → Export my data gives a JSON file per project. It is not a Markdown export and not a backup: it uploads at most 150 messages per session, cuts tool output to 500 characters and redacts common secret formats (what it reads and uploads).

Windows and Linux

Tested on Linux for the filters and the loop; Windows documented or assumed, nothing run there. On 20 November 2026 I ran, in an Ubuntu 24.04 container (arm64), the Codex filter on a made-up rollout in both forms (jq 1.7, zstd 1.5.5: the plain and the compressed file gave identical output), and the paging loop against a stub that returns three pages, under dash and bash (both gave the four ids, including a cursor with a space and a +). I did not run opencode or codex there. Labels: tested, documented, reported, assumed.

  • Linux. jq is in the Debian and Ubuntu repositories (documented: the jq download page). A bare Ubuntu image has neither jq nor zstd; install both (tested).
  • Windows, tools. The jq page lists winget install jqlang.jq, Scoop, Chocolatey and executables (documented). I found no vendor page with a zstd installer for Windows; winget and Scoop list packages (reported), and one Scoop issue, ScoopInstaller/Main#6557, says zstd@1.5.7 failed to install because the release ZIP changed (reported, closed in February 2025; I did not retry it). The vendor’s GitHub release 1.5.7 lists win64 and win32 zips (documented).
  • Windows, the filters. The FILTER text has quotes and \n that PowerShell parses first (documented in general: Microsoft’s about_Parsing; I did not run it there). Put each filter in a file and run jq -r -f codex.jq (assumed); the OpenCode loop already does this with opencode.jq.
  • Windows, the loop. while :; do ... done, ${cursor:+...} and mkdir -p ~/session-md are sh. Run them in WSL (assumed); I wrote no PowerShell version of the loop. Where each agent keeps its sessions: session formats.

What this post does not cover

  • Windows and Linux. Nothing ran on Windows; on Linux I ran the filters and the loop, not the agents. See Windows and Linux.
  • Long Claude Code sessions, subagent transcripts and images. I tested two short ones.
  • Claude Code /export itself. Refused in print mode here.
  • Codex /export itself. I installed the CLI (0.170.0) but did not manage to drive its interactive screen from a script, so I never saw the real export file. One thing I did see: in codex exec, the text /export file.md is not run as a command. It went to the model as a prompt, and the model wrote a 24-byte file with a shell call. Do not use codex exec to export.
  • Tool output. The filters drop it by design.
  • One machine, one version of each. OpenCode’s export format is not a published contract; check the key names on your version.