[FEATURE] export: add --format flag (md/json) and --last N selective export
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
/export exports the full conversation as plain text. This misses a core
developer workflow: saving a specific output (summary, plan, change log)
as a clean .md file — without full conversation noise, and without
spending tokens on a model turn to do it.
Current workarounds all have token/friction costs:
- Copy-paste: manual
- Custom skill using Write tool: triggers a model invocation
- MCP wiki sync: also requires tokens
Proposed Solution
Two zero-token additions to /export (both read the existing JSONL transcript):
1. Format flag
/export --format md [filename] → preserves markdown, saves as .md
/export --format json [filename] → structured JSON with roles + content
/export --format txt [filename] → current default (plain text)
2. Selective export
/export --last 1 [filename] → last assistant response only
/export --last 3 [filename] → last 3 assistant turns
Combined:
/export --format md --last 1 .claude/exports/sprint-plan.md
Why zero-token
The JSONL transcript is already written to ~/.claude/projects/<hash>/<session>.jsonl on every turn. /export
already reads this — it only needs a format conversion step and a
message-slice filter. No model invocation required.
Parity justification/copy [N] already supports Nth-latest response selection. /export
having the same --last N selectivity is a natural parity gap.
I'd like to contribute a fix
Happy to open a PR. The change should be scoped to the /export
command handler — adding arg parsing and format-aware serialization.
Workaround
I'm contributing a plugin (export-session) to plugins/ as a working
workaround while this native flag is considered.
https://github.com/anthropics/claude-code/pull/54777
Related issues
- #34339 — /export strips markdown (bug; --format md would fix as side effect)
- #26890 — auto-save before compaction (different trigger)
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
_No response_
Additional Context
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗