DEV Community

Cover image for /export turns your Claude Code session into a file another agent can read
Daniel (San) Ávila
Daniel (San) Ávila

Posted on Originally published at Medium

/export turns your Claude Code session into a file another agent can read

What /export actually writes

Run /export with no argument and Claude Code opens a menu: copy the current conversation to your clipboard, or save it as a plain-text file. Pass a filename and it skips the menu and writes straight to that file.

What lands in the file is a rendered transcript, messages and tool outputs written out as readable text. That distinction matters more than it looks. It is not a dump of the session internals, it is the conversation rendered for a person to read. There is no documented size limit, so a long session produces a long file.

It also only ever covers the current conversation. There is no form of /export that reaches back into a session you closed yesterday. For that you reopen it first, with /resume from inside a session or claude --resume <session-id> from the shell, and then export.

Handing the session to another agent

This is the part worth building a habit around. A rendered transcript is portable in a way a live session is not. Any agent that can read a file can read it.

/export handoff.txt
Enter fullscreen mode Exit fullscreen mode

Then, in a fresh Claude Code session or in a different tool entirely:

> Read @handoff.txt. That was a previous session on this repo. Continue from where it stopped.
Enter fullscreen mode Exit fullscreen mode

The @ reference pulls the full content of the file into the conversation, so the new agent starts with everything the old one said and did. You pay tokens for the whole thing, which is the obvious cost, but you are not paying for a re-explanation that would have been shorter and less accurate.

Two things I would check before leaning on this. The export is a point-in-time snapshot, so if you keep working in the original session the file is stale the moment you save it. And if the receiving agent is also Claude Code, claude --resume <session-id> is cheaper and more faithful than an export, because it restores the session instead of a reading of it. Export is for crossing a boundary that --resume cannot cross.

Mining the transcript for skills

The second use is the one that compounds. A long session is a record of everything you corrected, re-explained and typed twice. Read it back and the repetition is obvious in a way it never is while you are inside it.

One step here is not handed to you, so be precise about it: there is no Claude Code command that turns a transcript into a Skill. /skills lists and toggles the ones you already have. You write the SKILL.md yourself, at ~/.claude/skills/<name>/SKILL.md for a personal skill or .claude/skills/<name>/SKILL.md for one that ships with the project. Every frontmatter field is optional, name defaults to the directory name, and description is the one worth writing carefully, because it is what decides whether the skill is ever invoked.

If you want the reading step done for you instead of doing it by hand, I have a command for that, Session Learning Capture:

npx claude-code-templates@latest --command team/session-learning-capture
Enter fullscreen mode Exit fullscreen mode

It runs over the current session and writes what it finds into your CLAUDE.md files, split by what you ask it for: project learnings, implementation corrections, structure insights, or workflow improvements. Same loop as reading an export by hand, with the reading automated and the output landing somewhere that changes the next session.

When you want the raw JSONL instead

The /export output is made for a person. If a script is the consumer, you want a different door.

Claude Code already stores every session on disk, and has a documented way to query one:

~/.claude/projects/<project>/<session-id>.jsonl
claude -p --resume <session-id> --output-format json "summarize what we changed" | jq -r '.result'
Enter fullscreen mode Exit fullscreen mode

Here <project> is your working directory path with every non-alphanumeric character replaced by a dash. Each line is one JSON object, for a message, a tool use or a metadata entry.

Parse that file directly and you are building on a format the docs call internal and say changes between versions, so do it only if you accept that any release can break you. The supported routes:

  1. claude -p with --output-format json or stream-json, for a single run you capture.
  2. The transcript_path that hooks and status line commands get as input. A SessionEnd hook can archive the transcript as the session closes.
  3. The Agent SDK, if Claude Code is embedded in your own TypeScript or Python app.

One more thing before you build anything on top: transcripts are kept 30 days by default. cleanupPeriodDays in settings.json changes the retention, CLAUDE_CONFIG_DIR moves the storage off ~/.claude, and CLAUDE_CODE_SKIP_PROMPT_HISTORY suppresses the writes entirely.

Where the commands live

You can follow me on my social media:

Top comments (0)