home / skills / 0xdarkmatter / claude-mods / code-stats

code-stats skill

/skills/code-stats

This skill analyzes a codebase's size and composition using tokei and semantic diffs from difft to deliver quick statistics and insights.

npx playbooks add skill 0xdarkmatter/claude-mods --skill code-stats

Review the files below or copy the command above to add this skill to your agents.

Files (5)
SKILL.md
2.7 KB
---
name: code-stats
description: "Analyze codebase with tokei (fast line counts by language) and difft (semantic AST-aware diffs). Get quick project overview without manual counting. Triggers on: how big is codebase, count lines of code, what languages, show semantic diff, compare files, code statistics."
compatibility: "Requires tokei and difft CLI tools. Install: brew install tokei difft (macOS) or cargo install tokei difftastic (cross-platform)."
allowed-tools: "Bash"
---

# Code Statistics

Quickly analyze codebase size, composition, and changes.

## tokei - Line Counts

```bash
# 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

```bash
# 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

Overview

This skill analyzes a codebase for size, language composition, and semantic changes using fast line counters and AST-aware diffs. It provides quick, scriptable summaries and human-readable reports to help you understand project scale and the nature of edits. Use it to get counts, filter languages or directories, and inspect semantic differences between file versions.

How this skill works

It runs a lightweight line-count tool to enumerate files, lines, code, comments, and blanks per language and directory. For change inspection it uses an AST-aware diff tool that recognizes moved code, ignores formatting-only changes, and presents semantic edits. Both tools produce machine-friendly output for CI or JSON pipelines and readable summaries for manual review.

When to use it

  • Get a fast overview of project size and language breakdown.
  • Count lines of code for specific languages or the whole repo.
  • Exclude generated folders like node_modules or dist before counting.
  • Inspect refactorings or moves without noisy line-level diffs.
  • Integrate counts or semantic diffs in CI and reporting pipelines.

Best practices

  • Exclude build and dependency directories to avoid inflated counts.
  • Use JSON output for automated checks and dashboards.
  • Combine language filters to focus on areas of interest.
  • Set the semantic diff as GIT_EXTERNAL_DIFF for consistent reviews.
  • Run counts periodically to track growth and detect anomalies.

Example use cases

  • Run a compact tokei report to see top languages and total code lines before planning work.
  • Generate JSON totals in CI and fail a job if code growth exceeds a threshold.
  • Compare two TypeScript files with difft to see moved functions and renamed symbols.
  • Use difft as the external git diff tool to get cleaner code review outputs.
  • Exclude node_modules and dist when measuring codebase size for accurate metrics.

FAQ

Can the tools ignore generated files?

Yes. You can pass exclude flags to the line-count tool and configure your diff tool or git settings to skip generated directories.

Is the diff output machine-readable?

The semantic diff is human-focused, but it can be integrated with git and scripts. For automation, use the line-count tool's JSON output and combine with difft options suited to your display mode.