Export a Claude Code conversation to Markdown or JSON

Published · Updated · Checked against Claude Code 2.1.319

/export writes plain text, not Markdown or JSON. For either of those you convert the session's JSONL file with jq, which takes under a minute.

What /export does

The commands reference describes it in one line, and that is how it read on 10 Nov 2026: /export [filename] exports the current conversation as plain text. With a filename it writes straight to that file. Without one it opens a dialog to copy to the clipboard or save.

/export notes/rate-limiter-debug.txt

Nearby commands from the same page:

CommandWhat it gives you
/export [filename]The current conversation, plain text
/copy [N]The last (or Nth-latest) assistant response to the clipboard. In the picker, w writes the selection to a file
/branch [name]A branch of the conversation inside Claude Code, not a file
/bug, /feedbackA report to Anthropic after a consent screen, not an export for you

The docs do not say whether /export includes tool calls and results, or thinking, so export one session and read it before you rely on it. It also covers only the session you are in; an older one needs the file on disk.

Where the raw data is

Every session is already a file: ~/.claude/projects/<project>/<session-id>.jsonl (directory docs). It holds messages, tool calls and tool results, plus the system prompt, tool definitions and request parameters. Subagent transcripts are in a folder next to it. The layout is in where Claude Code stores your sessions, and picking one session out of many is in searching past Claude Code conversations.

This route reaches any session, but only while its file exists. Claude Code deletes transcripts after cleanupPeriodDays, default 30 (docs), so export what you care about early. See Claude Code silently deletes transcripts after 30 days.

Sealkeep can rescue a transcript that has already been swept, if it sealed the session first. sealkeep recover <id> <dest> restores the original bytes, and you run the jq below on that copy. sealkeep search <query>, with --content to look inside sessions, finds which one you want. It does not convert anything: sessions stay as the sealed original bytes, there is no export-to-Markdown command, and its command reference lists no flag for one.

What a line looks like

The field names in this guide are observed in sessions on Claude Code 2.1.319 with jq on macOS. They are not a documented, stable schema, and no official one exists in the docs.

Each line is one JSON object. In one 37,000-message session the useful type values were user and assistant; the rest were bookkeeping such as attachment, system, file-history-snapshot and request metadata. Inside message.content, a user prompt is a plain string or an array with a text block, a tool result comes back as a user line with a tool_result block, and an assistant line holds text, tool_use and thinking blocks.

Check on your own file:

f=~/.claude/projects/-Users-me-app/<session-id>.jsonl
jq -r '.type' "$f" | sort | uniq -c | sort -rn

To JSON

The file is already JSON Lines. If a tool wants one array, keep only conversation lines:

jq -s '[.[] | select(.type=="user" or .type=="assistant")
        | {type, timestamp, role: .message.role, content: .message.content}]' \
  "$f" > session.json

-s loads the whole file into memory. For a session of several hundred megabytes, stay in JSON Lines with jq -c and stream:

jq -c 'select(.type=="user" or .type=="assistant")
       | {type, timestamp, content: .message.content}' "$f" > session.jsonl

To Markdown

Save this as tomd.jq. It prints prompts, replies and tool calls, and leaves out tool results and thinking, where most of the size and most of the secrets live:

select(.type=="user" or .type=="assistant")
| .message as $m
| (if ($m.content|type)=="string"
   then [{type:"text",text:$m.content}]
   else $m.content end)[]
| if .type=="text"
  then "## " + (if $m.role=="user" then "User" else "Assistant" end)
       + "\n\n" + .text + "\n"
  elif .type=="tool_use"
  then "### Tool: " + .name + "\n\n```json\n" + (.input|tojson) + "\n```\n"
  else empty end

Run it:

jq -r -f tomd.jq "$f" > session.md

On one session this produced a readable file. Expect noise: slash-command wrappers such as <command-name> and <local-command-stdout> show up as user text. Adding | select((.text // "") | startswith("<") | not) before the if drops them, though that variant was not run.

To include tool output, add a branch for tool_result and truncate it, since one result can run to thousands of lines. Cutting with .content | tostring | .[0:2000] keeps the file usable.

Before it goes anywhere

An export is a copy of everything the session touched. The docs state that transcripts are plaintext and that a credential printed by a command is written to the file, so Markdown made from it carries the same text. Scan the export:

gitleaks dir session.md --no-banner --redact

gitleaks reads a file or directory with dir (README), and no match does not mean no secret. Redaction steps are in secrets in Claude Code transcripts. To hand a session to a person, see sharing a Claude Code session with a teammate.

FAQ

Does /export write Markdown?

The docs say plain text, and they list no option for Markdown or JSON.

Can I export a session from last month?

Not with /export, which works on the current conversation. Resume the session, or convert its JSONL file, if it still exists.

Will the JSONL format stay the same?

Unknown. The docs describe the contents but not a schema, and many line types are not messages. Select by .type and ignore the rest.

Why is the exported file so large?

Tool results. Reading a big file or running a noisy command puts the whole output in the transcript, and the Markdown script above skips those blocks.