Skip to main content

Claude Code 会话统计工具 — 分析 AI Coding 工程指标

Project description

cc-statistics

PyPI Downloads GitHub stars License

English | 中文

AI Coding 会话统计工具 — 支持 Claude Code / Gemini CLI / Codex / Cursor,从本地数据中提取工程指标。

CC Stats Dashboard

CLI Demo

CC Stats CLI Demo

核心亮点

  • 多数据源 — 支持 Claude Code、Gemini CLI、Codex、Cursor,可切换或聚合统计
  • 费用估算 — 内置 Opus / Sonnet / Haiku / Gemini 2.5 Pro / Flash / GPT-4o 等模型定价
  • 多维统计 — 指令数、工具调用 Top 10、开发时长(AI vs 用户)、代码变更(按语言)、Token(按模型)
  • 每日趋势 — 14 天费用趋势图,直观掌握 AI 使用规律
  • 用量预警 — 设置单日/每周费用上限,超限时状态栏变红 + 系统通知
  • 周报/月报 — 自动生成 Markdown 统计报告,支持飞书/钉钉/Slack 推送
  • 纯本地 — 所有数据读取自本地文件,不联网,不上传
  • 三种模式 — CLI 命令行 + Web Dashboard(跨平台)+ macOS 原生状态栏面板
  • 双语 — 自动跟随系统语言,支持中文 / English 手动切换

会话管理:搜索、恢复、分享

Claude Code 原生只提供 claude --resume(交互式选择器)和 claude --continue(续最近一个),没有内容搜索、没有导出、没有分享。cc-stats 补齐了这些能力。

搜索

按关键词搜索所有历史会话内容,快速定位到目标对话:

# CLI:按关键词搜索并导出
cc-stats --export-chat "登录bug"

macOS 面板内置搜索框,实时过滤会话列表,输入关键词即可匹配对话内容。

恢复

找到目标会话后,一键复制 claude --resume <session-id> 命令恢复对话:

  • macOS 面板 — 点击会话卡片的「恢复」按钮,命令自动复制到剪贴板,粘贴到终端即可继续
  • CLI--export-chat 导出的 Markdown 文件头部包含 session ID,配合 claude --resume 使用

导出 & 分享

将对话导出为可读格式,方便存档或分享给团队:

# 导出为 Markdown(自动保存到桌面)
cc-stats --export-chat "重构方案"

# 包含工具调用详情
cc-stats --export-chat "重构方案" --include-tools

macOS 面板支持选中多条消息,一键生成分享长图(PNG),直接发到微信/飞书/Slack。

请 cc 吃 Token

如果这个工具对你有帮助,欢迎请 cc 吃点 Token :)

微信赞赏码

安装

# uv(推荐,速度最快)
uv tool install cc-statistics

# pipx(隔离环境,任意终端可用)
pipx install cc-statistics

# pip
pip install cc-statistics

# Homebrew(macOS / Linux)
brew install androidZzT/tap/cc-statistics

零依赖,纯 Python 标准库。

从源码安装(开发用)

git clone https://github.com/androidZzT/cc-statistics.git
cd cc-statistics
uv sync           # 或 pip install -e .

使用

CLI 命令行(全平台)

cc-stats                     # 分析当前目录的所有会话
cc-stats --list              # 列出所有项目(Claude + Gemini)
cc-stats compose-album       # 按关键词匹配项目
cc-stats --all --since 3d    # 最近 3 天所有项目
cc-stats --all --since 2w    # 最近 2 周
cc-stats sailor --last 3     # 某项目最近 3 个会话
cc-stats --report week       # 生成周报(Markdown)
cc-stats --report month      # 生成月报
cc-stats --compare           # 多项目对比
cc-stats --compare --since 1w # 最近一周项目对比

Webhook 通知(飞书 / 钉钉 / Slack)

将每日统计摘要推送到团队群:

# 飞书(自动检测)
cc-stats --notify https://open.feishu.cn/open-apis/bot/v2/hook/xxx

# 钉钉
cc-stats --notify https://oapi.dingtalk.com/robot/send?access_token=xxx

# Slack
cc-stats --notify https://hooks.slack.com/services/xxx

# 手动指定平台
cc-stats --notify <url> --platform feishu

推送内容包括:指令数、活跃时长、Token、费用、代码变更、效率评分。

配合 cron 实现每日自动推送:

# 每天 21:00 推送日报到飞书
0 21 * * * cc-stats --notify https://open.feishu.cn/open-apis/bot/v2/hook/xxx

Web Dashboard(全平台:macOS / Windows / Linux)

cc-stats-web

启动后自动打开浏览器,展示暗色主题统计面板:

  • 数据源切换:Claude Code / Gemini CLI / All Sources
  • 项目选择器 + 时间范围切换(Today / 7d / 30d / All)
  • 4 项指标卡片:指令数、工具调用、活跃时长、预估费用
  • 每日趋势:14 天费用条形图
  • 开发时间:AI 占比环形图 + 时长明细
  • 代码变更:Git commit 统计 + 按语言拆分
  • Token 用量:按模型堆叠条形图 + 每模型费用
  • 工具调用:Top 10 排行

macOS 状态栏面板(仅 macOS)

cc-stats-app

需要 Xcode Command Line Tools(xcode-select --install),Swift 组件首次启动自动编译。

状态栏:

  • Claude logo + 当日 Token 用量 + 预估费用
  • 右键菜单切换显示模式(Token+费用 / Token / 费用 / 会话数)
  • 超限变红预警

统计面板(原生 SwiftUI):

  • 多数据源:Claude Code / Gemini CLI / Codex / Cursor,可切换或聚合展示
  • 主题切换:跟随系统 / 深色 / 浅色
  • 用量预警:单日/每周费用上限,超限系统通知
  • 导出统计数据(JSON / CSV,自动保存到桌面并打开)
  • 设置页:开机自启、语言切换、主题切换、版本更新检测
  • 会话搜索 + 一键恢复(复制 claude --resume
  • 进程管理:查看所有 Claude 进程内存占用
  • 工具调用拆分:Skill 和 MCP 工具展开为具体名称
  • 全局快捷键 Cmd+Shift+C

命令总览

命令 平台 说明
cc-stats 全平台 CLI 终端输出
cc-stats-web 全平台 浏览器 Web 面板
cc-stats-app 仅 macOS 原生状态栏面板

数据来源

所有数据读取自本地文件,不联网,不上传:

数据源 路径
Claude Code ~/.claude/projects/<project>/<session>.jsonl
Gemini CLI ~/.gemini/tmp/<project>/chats/<session>.json
Codex ~/.codex/sessions/*.jsonl
Cursor ~/Library/Application Support/Cursor/User/globalStorage/state.vscdb
Git 变更 项目目录的 git log --numstat

致谢

  • 状态栏 Clawd 动画素材来自 clawd-on-desk — 一个 Electron 桌面宠物应用,通过 hook 系统实时感知 AI coding agent 的工作状态并播放像素风动画。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cc_statistics-0.12.6.tar.gz (135.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cc_statistics-0.12.6-py3-none-any.whl (146.4 kB view details)

Uploaded Python 3

File details

Details for the file cc_statistics-0.12.6.tar.gz.

File metadata

  • Download URL: cc_statistics-0.12.6.tar.gz
  • Upload date:
  • Size: 135.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cc_statistics-0.12.6.tar.gz
Algorithm Hash digest
SHA256 04394ef5c8b4335ef597adadc3422250a307bfb5acd74ce0fffb50bc2286438e
MD5 86f127d7bba5b67277dd73760924c87f
BLAKE2b-256 4154b2e8b465e01e6cae3d4d42edfefdd945a92cf39cd1c104d5e41b9d781394

See more details on using hashes here.

Provenance

The following attestation bundles were made for cc_statistics-0.12.6.tar.gz:

Publisher: publish.yml on androidZzT/cc-statistics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cc_statistics-0.12.6-py3-none-any.whl.

File metadata

  • Download URL: cc_statistics-0.12.6-py3-none-any.whl
  • Upload date:
  • Size: 146.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cc_statistics-0.12.6-py3-none-any.whl
Algorithm Hash digest
SHA256 eb0af914ca61b3306c6b6065a9c23ef06e000aea79a2629704f7e69d11d3cb79
MD5 3607b397a9b3e1551eed695f051ea358
BLAKE2b-256 72233363e2bfb8b109f7262b7b1fa04257063dc8d786c5de34c5462af0016781

See more details on using hashes here.

Provenance

The following attestation bundles were made for cc_statistics-0.12.6-py3-none-any.whl:

Publisher: publish.yml on androidZzT/cc-statistics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page