npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jeffrey0617/cc-export

v1.0.3

Published

Export Claude Code sessions to Markdown with stats and token reports

Downloads

569

Readme

cc-export

将 Claude Code 的 session 对话历史导出为 Markdown 文档。

每个 session 导出两个文件:

  • <session-id>.md — 完整对话内容(一问一答格式)
  • <session-id>.meta.md — 元信息与统计分析

导出文件统一放在对应项目目录下的 sessions/ 子目录中。

安装

npm install
npm link   # 全局安装 cc-export 命令(可选)

不安装也可以直接用 node index.js <command>。

命令

list — 列出所有 session

cc-export list
cc-export list --project bobi        # 按路径关键词过滤
cc-export list --json                # JSON 格式输出

每条记录显示:session ID、项目路径、轮次数、开始时间、首条消息摘要。


export — 导出单个 session

cc-export export --id <session-uuid>
cc-export export --id <uuid> --from 5 --to 20   # 只导出第 5-20 轮
cc-export export --id <uuid> --output-dir ./exports

默认输出到 <项目目录>/sessions/。指定 --output-dir 后,两个文件直接输出到该目录:

./exports/
├── <uuid>.md
└── <uuid>.meta.md

export-dir — 批量导出某目录下所有 session

cc-export export-dir /home/ubuntu/projects/bobi-日常管理系统开发
cc-export export-dir /home/ubuntu/projects/bobi-日常管理系统开发 --output-dir ./exports

默认时,session 分别写入其对应项目目录的 sessions/ 子目录。指定 --output-dir 时,以该目录作为导出根目录,并保留相对的子项目结构:

./exports/
├── sessions/                         # 与导出源目录直接对应的 session
│   ├── <uuid>.md
│   └── <uuid>.meta.md
└── frontend/
    └── sessions/                     # 来源的子目录 session
        ├── <uuid>.md
        └── <uuid>.meta.md

update — 更新单个 session(覆盖重写)

cc-export update --id <session-uuid>
cc-export update --id <session-uuid> --output-dir ./exports

默认覆盖 <项目目录>/sessions/ 下的同名文件;指定 --output-dir 则覆盖该目录下的同名 .md 和 .meta.md 文件。


update-dir — 批量更新某目录下所有 session

cc-export update-dir /home/ubuntu/projects/bobi-日常管理系统开发
cc-export update-dir /home/ubuntu/projects/bobi-日常管理系统开发 --output-dir ./exports

--output-dir 的目录映射规则与 export-dir 相同。


输出结构示例

/home/ubuntu/projects/bobi-日常管理系统开发/
└── sessions/
    ├── 0b26fc12-134c-40a8-ba0d-eed9a0781be7.md
    ├── 0b26fc12-134c-40a8-ba0d-eed9a0781be7.meta.md
    ├── 86ca43d1-7d32-448e-bf1d-45e2da9032e4.md
    └── 86ca43d1-7d32-448e-bf1d-45e2da9032e4.meta.md

子目录的 session 也按各自的真实路径归位:

/home/ubuntu/projects/bobi-日常管理系统开发-frontend/
└── sessions/
    └── 3e018eb0-f206-48c0-9871-c4ba117ee039.md

元信息报告内容

每个 <session-id>.meta.md 包含:

  • 基本信息:Session ID、项目路径、Claude Code 版本、开始/结束时间、持续时长。
  • 对话统计:有效轮次、用户/AI 消息数、双方字数、单轮输入与回复的最小/平均/最大长度。
  • 模型与 Token 消耗:每个模型的 AI 消息数;输入、输出、缓存创建、缓存读取及计入请求总 Token。Token 来自 Claude Code JSONL 中每条 AI 消息记录的实际 usage 字段。
  • 服务层级与工具调用:standard 等服务层级的消息分布、工具调用次数,以及(如存在)服务端 Web Search / Fetch 请求数。
  • 主题摘要:首条用户消息的截断摘要。

示例:

## 模型与 Token 消耗

| 指标 | Token |
|------|------:|
| 输入 Token | 3,223,164 |
| 输出 Token | 27,183 |
| 合计 Token(不含缓存) | 3,250,347 |
| 缓存创建 Token | 562,639 |
| 缓存读取 Token | 8,329,686 |
| 计入请求的总 Token | 12,142,672 |

### 模型使用分布

| 模型 | AI 消息数 |
|------|----------:|
| claude-sonnet-4-6 | 85 |

Token 统计是 session 内各 AI 消息 usage 的累计值。缓存 Token 反映请求处理量,不等同于模型输出或账单金额。


数据来源

Session 文件位于 ~/.claude/projects/<encoded-path>/<session-uuid>.jsonl,每行一条 JSON 消息。cc-export 解析其中的 user(promptId 标识真实用户输入)和 assistant 消息,跳过工具调用结果,按 parentUuid 链关联每轮的所有 AI 回复。