tokei
Fast code statistics tool with multi-language support.
Official WebsiteFeatures
FastMultiple LanguagesJSON/YAML OutputGitignore Aware
Installation
Homebrew
brew install tokeiPacman (Arch)
pacman -S tokeiCargo (Rust)
cargo install tokeiWhy use tokei?
tokei (named after the Japanese word for "statistics") is a tool that quickly displays code statistics. Perfect for understanding project scope and checking language composition.
Ultra Fast
Built in Rust with parallel processing. Analyzes large codebases in seconds.
150+ Languages
Supports a wide range from major to minor languages. Includes auto-detection.
Detailed Statistics
Counts code lines, comment lines, and blank lines separately. Provides accurate statistics.
Multiple Output Formats
Outputs in text, JSON, YAML, and CBOR formats. Easy integration with CI/CD and other tools.
Installation
Installation
# macOS (Homebrew)
brew install tokei
# Cargo (Rust)
cargo install tokei
# Arch Linux
sudo pacman -S tokei
# Ubuntu/Debian (apt)
sudo apt install tokei
# Windows (Chocolatey)
choco install tokei
# Windows (Scoop)
scoop install tokeiBasic Usage
Basic Commands
Basic
# Analyze current directory
tokei
# Analyze specific directory
tokei /path/to/project
# Analyze multiple directories
tokei src tests docsOutput Example
=============================================================================== Language Files Lines Code Comments Blanks =============================================================================== Rust 120 15000 12000 1500 1500 TypeScript 80 8000 6500 800 700 JavaScript 30 2500 2000 300 200 JSON 25 500 500 0 0 Markdown 10 800 0 800 0 =============================================================================== Total 265 26800 21000 3400 2400 ===============================================================================
Displays file count, total lines, code lines, comment lines, and blank lines for each language.
Common Patterns
Sorting
Sorting
# Sort by code lines (default)
tokei --sort code
# Sort by file count
tokei --sort files
# Sort by total lines
tokei --sort lines
# Sort by comment lines
tokei --sort comments
# Sort by blank lines
tokei --sort blanksFiltering
Filtering
# Show only specific languages
tokei -t Rust,TypeScript
# Exclude specific patterns
tokei -e "*.json" -e "*.md"
# Exclude specific directories
tokei --exclude node_modules --exclude target
# Include hidden files
tokei --hiddenPer-File Details
File Details
# Show statistics for each file
tokei --files
# File details for specific language
tokei --files -t RustAdvanced Usage
Output Format
Output Format
# Output in JSON format
tokei -o json
# Output in YAML format
tokei -o yaml
# Output in CBOR format (binary)
tokei -o cbor
# Save results to file
tokei -o json > stats.json
# Save multiple results for comparison
tokei -o json > stats_v1.json
# Later...
tokei -o json > stats_v2.jsonConfiguration File
.tokeignore
# Create .tokeignore file (same format as .gitignore)
# Place in project root
# Exclude dependencies
node_modules/
vendor/
target/
# Exclude build artifacts
dist/
build/
*.min.js
# Exclude test data
__snapshots__/
fixtures/Custom Language Definition
tokei.toml
# Define custom language in tokei.toml
# Place in project root
[[languages]]
name = "MyLang"
extensions = ["mlang"]
line_comment = ["//""]
multi_line_comments = [["/*", "*/"]]
# Add extensions to existing language
[languages.TypeScript]
extensions = ["tsx", "mts", "cts"]Common Options
| Option | Description | Example |
|---|---|---|
-t, --type | Show only specific languages | tokei -t Rust,Go |
-e, --exclude | Exclude patterns | tokei -e "*.test.js" |
-s, --sort | Specify sort criterion | tokei -s lines |
-o, --output | Specify output format | tokei -o json |
--files | Show per-file details | tokei --files |
--hidden | Include hidden files | tokei --hidden |
-c, --columns | Specify output width | tokei -c 120 |
Practical Examples
Project Analysis
Project Analysis
# Get project overview
tokei --sort code
# Check test code ratio
tokei src tests --files | grep -E "test|spec"
# Check documentation (comment) coverage
tokei --sort comments
# Compare frontend and backend
tokei frontend/
tokei backend/CI/CD Usage
CI/CD
# Example: Code statistics in GitHub Actions
# .github/workflows/stats.yml
name: Code Statistics
on: [push, pull_request]
jobs:
stats:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install tokei
run: cargo install tokei
- name: Generate stats
run: |
tokei -o json > stats.json
echo "## Code Statistics" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
tokei >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARYTracking Statistics
Statistics Tracking
# Script to record statistics periodically
#!/bin/bash
DATE=$(date +%Y-%m-%d)
tokei -o json > "stats_$DATE.json"
# Extract specific info from JSON (using jq)
tokei -o json | jq '.Rust.code'
tokei -o json | jq '[.[].code] | add'Comparison with Similar Tools
| Feature | tokei | cloc | scc |
|---|---|---|---|
| Speed | Very fast | Normal | Very fast |
| Language support | 150+ | 200+ | 200+ |
| Output formats | JSON, YAML, CBOR | JSON, XML, YAML, etc. | JSON, CSV, HTML, etc. |
| Complexity calculation | - | - | Yes |
Tips
- •Set exclusion patterns in
.tokeignorefile. Uses the same format as.gitignore - •Combine JSON output with
jqto extract specific statistics - •Use
tokei --languagesto display all supported languages - •For large repositories, exclude
node_modulesorvendorwith--excludefor faster results - •To display statistics as a badge in README, use a script to parse JSON output and generate SVG