Terminal GuideTerminal Guide
tokei icon

tokei

Dev Tools
macOSLinuxWindows
Rust

Fast code statistics tool with multi-language support.

Official Website

Features

FastMultiple LanguagesJSON/YAML OutputGitignore Aware

Installation

Homebrew
brew install tokei
Pacman (Arch)
pacman -S tokei
Cargo (Rust)
cargo install tokei

Why 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 tokei

Basic Usage

Basic Commands

Basic
# Analyze current directory
tokei

# Analyze specific directory
tokei /path/to/project

# Analyze multiple directories
tokei src tests docs

Output 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 blanks

Filtering

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 --hidden

Per-File Details

File Details
# Show statistics for each file
tokei --files

# File details for specific language
tokei --files -t Rust

Advanced 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.json

Configuration 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

OptionDescriptionExample
-t, --typeShow only specific languagestokei -t Rust,Go
-e, --excludeExclude patternstokei -e "*.test.js"
-s, --sortSpecify sort criteriontokei -s lines
-o, --outputSpecify output formattokei -o json
--filesShow per-file detailstokei --files
--hiddenInclude hidden filestokei --hidden
-c, --columnsSpecify output widthtokei -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_SUMMARY

Tracking 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

Featuretokeiclocscc
SpeedVery fastNormalVery fast
Language support150+200+200+
Output formatsJSON, YAML, CBORJSON, XML, YAML, etc.JSON, CSV, HTML, etc.
Complexity calculation--Yes

Tips

  • Set exclusion patterns in .tokeignore file. Uses the same format as .gitignore
  • Combine JSON output with jq to extract specific statistics
  • Use tokei --languages to display all supported languages
  • For large repositories, exclude node_modules or vendor with --exclude for faster results
  • To display statistics as a badge in README, use a script to parse JSON output and generate SVG
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More