Skip to content

Repository files navigation

CodeState

MIT LicenseStars

Instant codebase insights in your terminal — fast, local, zero telemetry. CodeState provides extreme performance while keeping its unique advanced features like Git Hotspot analysis and Code Health tracking.

Features

  • Written in Rust: Blazingly fast multi-threaded file scanning powered by rayon and ignore.
  • Zero-Allocation Byte Scanner: Near-instant execution times even on massive mono-repos.
  • AST Semantic Analysis: Integrates tree-sitter for perfectly accurate parsing of functions, classes, and dead code.
  • Software Composition Analysis (SCA): Instantly parse lockfiles to map your third-party dependencies.
  • Enterprise Policy Engine: Define project health constraints in a .codestate.yml to automatically guard your CI pipeline.
  • Static Dashboard Generator: One command to export a beautiful SPA dashboard with charts and health metrics.
  • Zero-Install: Download the standalone binary and run it instantly. No dependencies required!
  • GitHub Action Ready: Export SARIF for GitHub Advanced Security and automate PR reviews.
  • Beautiful TUI: Gorgeous terminal UI with sorting, hotkey navigation, and live exploring (codestate -i).
  • Native Git Hotspot analysis via git2-rs for lighting fast Churn vs Complexity Matrix generation.

Installation

Option 1: Cargo (Recommended for Windows / Rust users)

If you have Rust installed, this is the best way to install CodeState without triggering Windows SmartScreen warnings.

cargo install codestate

Option 2: Zero-Install Binaries

Download the standalone binary from the Releases page. No Python installation required!

# Windows (PowerShell)
Invoke-WebRequest -Uri "https://github.com/HenryLok0/CodeState/releases/latest/download/codestate-windows-amd64.exe" -OutFile "codestate.exe"
.\codestate.exe
# Linux
curl -L https://github.com/HenryLok0/CodeState/releases/latest/download/codestate-linux-amd64 -o codestate
chmod +x codestate
./codestate
# macOS
curl -L https://github.com/HenryLok0/CodeState/releases/latest/download/codestate-darwin-amd64 -o codestate
chmod +x codestate
./codestate

Option 2: Build from Source

# Requires Rust and Cargo
git clone https://github.com/HenryLok0/CodeState.git
cd CodeState
cargo build --release
./target/release/codestate

Usage Scenarios

CodeState is designed to be instantly useful for different daily scenarios.

1. Basic Scan: How big is this project?

Just run the tool without any arguments to get a blazingly fast overview of the language distribution, total lines of code, and comment density.

codestate

2. Code Health Check: What needs refactoring?

Use the summary flag to get a detailed breakdown of codebase health, including average function complexity and TODO counts.

codestate --summary

3. Find Bug Hotspots: Where should I focus my code review?

CodeState integrates directly with Git to find "Hotspots"—files that are modified most frequently. Files with high complexity and high churn are prime candidates for bugs.

codestate --hotspot --details

4. Interactive TUI Explorer

Launch a full-screen Terminal User Interface to interactively navigate, sort, and analyze your project.

codestate -i

5. Generate Static HTML Dashboard

Export a standalone, beautiful HTML dashboard with charts and complexity graphs for your team.

codestate --generate-dashboard --details

GitHub Action (CI/CD)

CodeState has built-in support for GitHub Actions! Automate codebase health checks and PR reviews by simply adding this to your .github/workflows/pr.yml:

name: PR CodeState Checkon: [pull_request]jobs:
codestate:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v4
- name: Run CodeState Analysisuses: HenryLok0/CodeState@v1with:
args: '--summary --failures-only'github_token: ${{ secrets.GITHUB_TOKEN }}

This action will automatically run CodeState and post a beautiful report as a PR comment.

Available Commands

CodeState's new Rust engine focuses on speed and simplicity.

OptionDescription
[Basic Analysis & Filtering]
directoryTarget directory to analyze (default: current directory)
--excludeDirectories to exclude (e.g. --exclude .git venv node_modules)
--extFile extensions to include (e.g. --ext .py .js)
--only-langOnly analyze specific file extensions, comma separated (e.g. py,js)
--top NShow only the top N files by lines or complexity
--failures-onlyShow only files with issues (naming, size, complexity, etc.)
--regexUser-defined regex rules for custom code checks (space separated, enclose in quotes)
--file-ageShow file creation and last modified time
--uncommittedShow stats for files with uncommitted changes (git diff)
--sizeShow each file's size in bytes as a table
--list-extensionsList all languages found in the project with count and percentage
--min-lines <N>Only show files with total lines >= N
--find <keyword/regex>Find all lines matching a keyword or regex in the codebase
--cacheBuild and use cache for much faster repeated analysis (highly recommended for large codebases)
--cache-deleteDelete all cache data in .codestate (force rebuild cache on next run)
[Statistics & Detailed Analysis]
--detailsShow detailed statistics for each file
--dupShow duplicate code blocks (5+ lines)
--maxminShow file with most/least lines
--langdistShow language (file extension) distribution as ASCII pie chart
--complexitymapShow ASCII heatmap of file complexity
--complexity-graphShow an ASCII bar chart of file complexity
--warnsizeWarn for large files/functions (optionally specify file and function line thresholds, default 300/50)
--namingCheck function/class naming conventions (PEP8, PascalCase)
--apidocShow API/function/class docstring summaries
--deadcodeShow unused (dead) functions/classes in Python files
--typestatsShow function parameter/type annotation statistics (Python)
--trendShow line count trend for a specific file
--refactor-suggestShow files/functions that are refactor candidates, with reasons
--autofix-suggestSuggest auto-fix patches for naming, comments, and duplicate code
--refactor-mapShow a table of files/functions that are refactor candidates
--complexity-threshold <value>Set custom complexity threshold for warnings (requires a value, e.g. --complexity-threshold 5)
--open <file>Show detailed analysis for a single file
--blame <file>Show git blame statistics for a file
--compare <dir1> <dir2>Compare statistics between two directories
[Output / Reports]
--sort <COLUMN>Sort output table by files, lines, code, comments, blanks, language
--htmlExport result as HTML table
--mdExport result as Markdown table
--jsonExport result as JSON
--csvExport summary statistics as CSV
--excelExport summary statistics as Excel (.xlsx)
--details-csvExport per-file details as CSV
--groupdir-csvExport grouped-by-directory stats as CSV
--groupext-csvExport grouped-by-extension stats as CSV
--test-coverage <coverage.xml>Show test coverage analysis from a coverage.xml file
--output, -oOutput file for HTML/Markdown/JSON/CSV/Excel export
--report-issuesExport all detected issues (naming, size, complexity, etc.) as a markdown or JSON report
--check-policyValidate project against .codestate.yml rules (CI mode)
--generate-dashboardCreate a static HTML SPA dashboard (output/dashboard.html)
--sarifExport SARIF format for GitHub Advanced Security integration
--scaPerform Software Composition Analysis (SCA) on lockfiles
[Project Structure & Health]
--treeShow ASCII tree view of project structure
--structure-mermaidGenerate a Mermaid diagram of the project directory structure
--healthShow project health score and suggestions
--summaryGenerate a markdown project summary (print or --output)
--badge-sustainabilityOutput SVG sustainability/health badge
--lang-card-svgOutput SVG language stats card (like GitHub top-langs)
[Contributors / CI]
--authorsShow git main author and last modifier for each file
--contributorsShow contributor statistics (file count, line count, commit count per author)
--contributors-detailShow detailed contributor statistics (including Impact %)
--hotspotShow most frequently changed files (git hotspots)
--churnShow most changed files in the last N days (default 30)
--ciCI/CD mode: exit non-zero if major issues found
[Automation / README / Badges]
--badgesAuto-detect and print project language/framework/license/CI badges for README
--readmeAuto-generate a README template based on analysis
[Other]
--style-checkCheck code style: indentation, line length, trailing whitespace, EOF newline
--openapiGenerate OpenAPI 3.0 JSON for Flask/FastAPI routes
--multi <dir1> [dir2 ...]Analyze multiple root directories (monorepo support, requires at least one directory)
--versionShow codestate version and exit

Examples

# Analyze the current directory (default)
codestate
# Analyze a specific directory and exclude build and dist folders
codestate myproject --exclude build dist
# Only analyze Python and JavaScript files
codestate --only-lang py,js
# Show only the top 5 largest files
codestate --top 5
# Show detailed statistics for each file
codestate --details
# Export results as HTML
codestate --html --output report.html
# Export results as CSV
codestate --csv --output report.csv
# Export results as Excel
codestate --excel --output report.xlsx
# Show only files with issues (naming, size, complexity, etc.)
codestate --failures-only
# Show file creation and last modified time
codestate --file-age
# Generate a markdown project summary
codestate --summary --output PROJECT_SUMMARY.md
# Set custom complexity threshold (requires a value)
codestate --complexity-threshold 5 --failures-only
# Analyze multiple directories (requires at least one directory)
codestate --multi src tests
# Sort summary table by specific column (files, lines, code, comments, blanks, language)
codestate --sort code
# List all file extensions with count and percentage
codestate --list-extensions

Why CodeState?

  • Instant understanding: go beyond LOC to highlight duplicates, complexity hotspots, refactor candidates, naming issues, and dead code — right in your terminal.
  • Visual by default: ASCII pie/heatmap/bar charts make trends obvious during reviews, without leaving the CLI.
  • History-aware decisions: git hotspots/churn help you prioritize the files that matter most.
  • Team visibility: contributors and blame insights per file unlock ownership and onboarding context.
  • CI-ready artifacts: export HTML/Markdown/JSON/CSV/Excel for reports, dashboards, and pipelines.
  • Faster repeat runs: built-in caching and .gitignore support keep large repositories snappy over time.

Tip: Combine CodeState with a GitHub Action to post a compact Markdown summary on every PR.

Star History

Star History Chart

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Support

If you have questions or need help, please open an issue on GitHub.

Thank you to all contributors and the open-source community for your support.


Troubleshooting

  • Windows path/encoding quirks: run from a local folder (avoid syncing folders) and ensure UTF-8 console.
  • Very large repos: run once with --cache, then subsequent commands will be much faster.

About

Blazingly fast codebase insights in your terminal. Written in Rust, CodeState goes beyond line counts to visualize code health, complexity, and Git hotspots with zero dependencies

Topics

Resources

Code of conduct

Contributing

Stars

11 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages