A command-line tool for counting lines of code, comments, tokens and blank lines in files within a directory.
What is ct-lines?
ct-lines (count lines) is a CLI that walks a directory tree and reports per-file and aggregate counts for lines of code, comment lines, blank lines, and tokens. It's useful for understanding the size and composition of a codebase at a glance — without installing heavyweight static analysis tools.
The Problem It Solves
When working across multiple projects or auditing a new codebase, it's useful to quickly answer: how much code is actually here? What percentage is comments? How many tokens would it cost to send this to an LLM?
Most tools that answer these questions are either too complex to install, too slow on large trees, or don't report token counts at all. ct-lines is a small, fast alternative that runs in seconds and outputs clean, readable summaries.
Core Features
Per-file breakdown
ct-lines ./src
File Lines Code Comments Blank Tokens
─────────────────────────────────────────────────────────────────
src/index.ts 142 98 22 22 1,840
src/parser.ts 310 241 40 29 4,102
src/formatter.ts 87 64 10 13 980
─────────────────────────────────────────────────────────────────
Total 539 403 72 64 6,922
Aggregate stats
After the per-file table, ct-lines prints a summary section:
Summary
Total files: 3
Total lines: 539
Code: 403 (74.8%)
Comments: 72 (13.4%)
Blank: 64 (11.9%)
Tokens: 6,922
Filtering
ct-lines ./src --ext ts,tsx # only TypeScript files
ct-lines . --exclude node_modules # skip directories
ct-lines . --min-lines 50 # only files with 50+ linesToken counting
Token counts use a GPT-compatible tokenizer approximation, making ct-lines useful for estimating LLM context costs before sending a codebase to an API.
Installation
npm install -g ct-linesRequirements: Node.js ≥ 18.
Tech Stack
- TypeScript — strict mode, compiled with esbuild
- fast-glob — efficient directory traversal
- meow — CLI argument parsing
- cli-table3 — formatted terminal table output
Use Cases
- Auditing a new codebase before a refactor
- Estimating LLM API token costs for context windows
- Tracking code growth across a project over time
- Generating quick reports for technical documentation