A powerful command-line tool designed to analyze GitHub repositories and local directories, accurately counting Lines of Code (LOC) and visualizing repository structures.
Unlike other online counters (such as ghloc or codetabs):
- True SLOC Count: Instead of just counting text-containing lines (like standard engines), this tool computes actual Source Lines of Code (SLOC), comments, and blank lines.
- Private & Multiple Repositories: It fully supports private repositories (using a GitHub token) and analysis of all public repositories for a given user.
- Accurate Line Counting (SLOC): Counts exact Source Lines of Code, comments, and blank lines with high precision using the
locc4jengine. - Repository Tree Visualization: Generates and prints a directory tree structure directly to the console.
- Multi-Repository Analysis (User Mode): Analyzes and processes all public repositories of a given GitHub user in a single command.
- File Sorting: Groups and ranks files by LOC or programming languages.
- JSON Export: Export results into JSON files for easy parsing or external use.
📄 Example JSON Result (describing the structure and LOC of this project)
There are two main ways to run this application:
- Option 1: From Source (Java 17 & Maven)
mvn clean package java -jar target/githubloc-1.0.jar <command>
- Option 2: Prebuilt Executable (.exe for Windows / binary for Linux)
Download the latest archive from the Releases tab on GitHub and run:
./github-loc.exe <command>
For detailed, step-by-step setup and GitHub API token configuration instructions, see the Setup Guide.
Commands follow a simple format: [TARGET] [ACTION] [SORT]
- Analyze a single GitHub repository:
facebook/react
- Analyze all public repositories of a specific user:
sonle1501
- Sort and group files by programming language:
sonle1501/github-loc -a sort BYLANG
For the complete documentation on modes, action flags (-a/--action), sorting arguments, and interactive prompt mode, see the Command Guide.
Results and intermediate files are neatly organized in the local storage/ directory:
storage/repos/: Unzipped repository source folders.storage/zip-repos/: Raw downloaded repository.ziparchives.storage/json-results/: JSON analysis tree outputs and sorted lists.storage/user-repos/: JSON results of multi-repository analysis.
To evaluate the performance of github-loc, I ran a benchmark on the Elasticsearch repository (~6M LOC) using the JMH (Java Microbenchmark Harness).
Below are the average execution times (in milliseconds per operation, ms/op) for each approach:
| Benchmark | Mode | Cnt | Score | Error | Units |
|---|---|---|---|---|---|
CreateTreeBenchmark.measureBuildTreeMultithreading |
avgt | 5 | 3412.355 | ± 110.319 | ms/op |
CreateTreeBenchmark.measureBuildTreeMultithreadingWithBatch |
avgt | 5 | 4074.866 | ± 373.230 | ms/op |
CreateTreeBenchmark.measureBuildTreeSequential |
avgt | 5 | 15530.403 | ± 297.930 | ms/op |
Execution results visualized below:

This project utilizes the locc4j counting engine.
The github-loc project is licensed under the MIT License.
