关于 code-stats
用于快速分析代码库规模、语言组成和代码变更的 skill。它介绍使用 tokei 统计行数,并用 difft 进行 AST 感知的语义比较。
主要功能
- 01使用 tokei 按语言统计行数
- 02排序和筛选代码统计
- 03将统计结果导出为 JSON
- 04使用 AST 感知差异比较文件
- 05在 Git 中使用 difft
适用场景
- 01了解代码库规模和语言构成
- 02跟踪代码库增长
- 03审查重构变更
- 04比较文件并识别移动的代码
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ 0xdarkmatter/ claude-mods --skill code-stats安装后在 Claude Code 中输入/code-stats确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assets/.gitkeepreferences/difft-advanced.mdtokei-advanced.mdscripts/.gitkeep详细介绍
代码统计
快速分析代码库规模、组成和变更。
tokei - 行数统计
# Count all code
tokei
# Compact output sorted by code
tokei --compact --sort code
# Specific languages
tokei --type=TypeScript,JavaScript
# Exclude directories
tokei --exclude node_modules --exclude dist
# JSON output for scripting
tokei --output json | jq '.Total.code'
示例输出
===============================================================================
Language Files Lines Code Comments Blanks
===============================================================================
TypeScript 45 12847 9823 1456 1568
JavaScript 12 2341 1876 234 231
-------------------------------------------------------------------------------
Total 57 15188 11699 1690 1799
===============================================================================
difft - 语义差异
# Compare files
difft old.ts new.ts
# Inline mode
difft --display=inline old.ts new.ts
# With git
GIT_EXTERNAL_DIFF=difft git diff
GIT_EXTERNAL_DIFF=difft git show HEAD~1
为什么要关注语义?
| 传统 diff | difft |
|---|---|
| 逐行比较 | 感知 AST |
| 将移动的内容显示为删除后新增 | 识别移动的内容 |
| 对空白字符敏感 | 忽略格式 |
快速参考
| 任务 | 命令 |
|---|---|
| 统计所有代码 | tokei |
| 紧凑输出 | tokei --compact |
| 按代码量排序 | tokei --sort code |
| 仅统计 TypeScript | tokei -t TypeScript |
| JSON 输出 | tokei --output json |
| 排除目录 | tokei --exclude node_modules |
| 语义差异 | difft file1 file2 |
| Git 差异 | GIT_EXTERNAL_DIFF=difft git diff |
适用场景
- 快速了解代码库概况
- 从语义层面比较代码变更
- 了解项目组成
- 评估重构影响
- 跟踪代码库增长
更多资源
如需了解详细模式,请加载:
./references/tokei-advanced.md- 筛选、输出格式、CI 集成./references/difft-advanced.md- 显示模式、Git 集成、语言支持
评论
支持 Markdown