code-stats
Scannednpx machina-cli add skill aiskillstore/marketplace/code-stats --openclawFiles (1)
SKILL.md
2.7 KB
Code Statistics
Quickly analyze codebase size, composition, and changes.
tokei - Line Counts
# 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'
Sample Output
===============================================================================
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 - Semantic Diffs
# 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
Why Semantic?
| Traditional diff | difft |
|---|---|
| Line-by-line | AST-aware |
| Shows moved as delete+add | Recognizes moves |
| Whitespace sensitive | Ignores formatting |
Quick Reference
| Task | Command |
|---|---|
| Count all code | tokei |
| Compact output | tokei --compact |
| Sort by code | tokei --sort code |
| TypeScript only | tokei -t TypeScript |
| JSON output | tokei --output json |
| Exclude dir | tokei --exclude node_modules |
| Semantic diff | difft file1 file2 |
| Git diff | GIT_EXTERNAL_DIFF=difft git diff |
When to Use
- Getting quick codebase overview
- Comparing code changes semantically
- Understanding project composition
- Reviewing refactoring impact
- Tracking codebase growth
Additional Resources
For detailed patterns, load:
./references/tokei-advanced.md- Filtering, output formats, CI integration./references/difft-advanced.md- Display modes, git integration, language support
Source
git clone https://github.com/aiskillstore/marketplace/blob/main/skills/0xdarkmatter/code-stats/SKILL.mdView on GitHub Overview
Code Statistics analyzes a codebase to report size, language mix, and changes. It uses tokei for fast line counts and difft for semantic diffs, giving a quick project overview without manual counting.
How This Skill Works
The skill runs tokei to count lines by language and can output JSON for scripting. It uses difft to perform semantic diffs, with options for inline display or git integration. It relies on Bash and requires the tokei and difft CLIs to be installed.
When to Use It
- Getting quick codebase overview
- Comparing code changes semantically
- Understanding project composition
- Reviewing refactoring impact
- Tracking codebase growth
Quick Start
- Step 1: Install tools: brew install tokei difft (macOS) or cargo install tokei difftastic (cross-platform).
- Step 2: Count code with tokei (e.g., tokei --exclude node_modules --output json | jq '.Total.code').
- Step 3: Compare files or commits with difft (e.g., difft old.ts new.ts) or use GIT_EXTERNAL_DIFF=difft git diff.
Best Practices
- Install required tools (tokei and difft) before use.
- Use tokei with --output json for automation and scripting.
- Filter out noisy dirs like node_modules and dist to focus on source.
- Use --compact or sortable options to generate concise reports.
- Leverage git integration (GIT_EXTERNAL_DIFF=difft) for PR reviews.
Example Use Cases
- Count all code in a TypeScript project and review per-language breakdown.
- Compare two commits semantically to see moved or refactored code with difft.
- Generate a JSON codebase summary for CI dashboards.
- Filter counting to TypeScript/JavaScript for frontend-heavy repos.
- Track growth over time by repeating counts across releases.
Frequently Asked Questions
Add this skill to your agents