claude-code - ✅(Solved) Fix [FEATURE] export: add --format flag (md/json) and --last N selective export [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54764Fetched 2026-04-30 06:36:40
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Timeline (top)
labeled ×2commented ×1

Fix Action

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)

PR fix notes

PR #54777: feat(plugins): add export-session plugin (md/json/txt/docx/pdf export)

Description (problem / solution / changelog)

Summary

Adds export-session plugin to plugins/ with support for exporting session outputs to md, json, txt, docx, and pdf formats with optional --last N selective export.

What it does

  • Reads ~/.claude/projects JSONL transcript directly — zero extra model tokens
  • --format md/json/txt/docx/pdf — five output formats
  • --last N — export only last N assistant turns
  • Auto-names output to .claude/exports/YYYY-MM-DD-session.<fmt> if no filename given
  • docx/pdf use bundled export.py script with python-docx and fpdf2

Usage

/export-session:export-session summary.md --format md --last 1
/export-session:export-session report.pdf --format pdf
/export-session:export-session data.json --format json --last 3
/export-session:export-session notes.docx --format docx

Relates to

Closes #<issue-number>

Checklist

  • Follows standard plugin structure (.claude-plugin/plugin.json, skills/, README.md)
  • disable-model-invocation: true set (user-invoked only)
  • No external services or auth required
  • Works on macOS and Linux
  • Python deps auto-install on first use (docx/pdf only)

Changed files

  • plugins/export-session/.claude-plugin/plugin.json (added, +11/-0)
  • plugins/export-session/README.md (added, +57/-0)
  • plugins/export-session/skills/export-session/SKILL.md (added, +57/-0)
  • plugins/export-session/skills/export-session/scripts/export.py (added, +226/-0)
  • plugins/export-session/skills/export-session/scripts/requirements.txt (added, +2/-0)
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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

extent analysis

TL;DR

The proposed solution involves adding a format flag and selective export option to the /export command to allow users to save specific outputs as clean .md files without incurring token costs.

Guidance

  • Review the proposed solution and consider adding the --format and --last flags to the /export command handler to enable zero-token exports.
  • Evaluate the parity justification and ensure that the new flags align with existing commands like /copy [N].
  • Examine the provided plugin (export-session) as a potential workaround and assess its feasibility as a native feature.
  • Investigate related issues (#34339 and #26890) to ensure the proposed solution addresses all relevant concerns.

Example

No code snippet is provided as the issue focuses on proposing a new feature rather than fixing a specific code issue.

Notes

The proposed solution relies on reading the existing JSONL transcript, which is already written to disk on every turn. This approach aims to minimize token costs and ensure a seamless user experience.

Recommendation

Apply the proposed workaround by integrating the export-session plugin into the native /export command, as it provides a functional solution while the native flag is being considered. This approach allows users to benefit from the new functionality without waiting for the native implementation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING