1# Sloc Cloc and Code (scc)2345> scc powers [searchcode.com](https://searchcode.com) — structured code intelligence over any repo, built for AI agents.67A tool similar to cloc, sloccount and tokei. For counting the lines of code, blank lines, comment lines, and physical lines of source code in many programming languages.89Goal is to be the fastest code counter possible, but also perform COCOMO calculation like sloccount, LOCOMO estimation for LLM-based development costs, estimate code complexity similar to cyclomatic complexity calculators and produce unique lines of code or DRYness metrics. In short one tool to rule them all.1011Also it has a very short name which is easy to type `scc`.1213If you don't like sloc cloc and code feel free to use the name `Succinct Code Counter`.1415[](https://github.com/boyter/scc/actions/workflows/go.yml)16[](https://coveralls.io/github/boyter/scc?branch=master)17[](https://github.com/boyter/scc/)1819[](https://github.com/avelino/awesome-go)2021Licensed under MIT licence.2223## Table of Contents2425- [Install](#install)26- [Background](#background)27- [Pitch](#pitch)28- [Usage](#usage)29- [Configuration Files](#configuration-files)30- [Complexity Estimates](#complexity-estimates)31- [Unique Lines of Code (ULOC)](#unique-lines-of-code-uloc)32- [COCOMO](#cocomo)33- [LOCOMO](#locomo)34- [Git Insight Reports](#git-insight-reports)35- [HTML Report](#html-report)36- [Output Formats](#output-formats)37- [Performance](#performance)38- [Development](#development)39- [MCP Server Mode](#mcp-server-mode)40- [Adding/Modifying Languages](#addingmodifying-languages)41- [Issues](#issues)42- [Badges](#badges)43- [Language Support](LANGUAGES.md)44- [Citation](#citation)4546### scc for Teams & Enterprise4748While scc will always be a free and open tool for individual developers, companies and businesses, we are exploring an enhanced version designed for teams and businesses. scc Enterprise will build on the core scc engine to provide historical analysis, team-level dashboards, and policy enforcement to help engineering leaders track code health, manage technical debt, and forecast project costs.4950We are currently gathering interest for a private beta. If you want to visualize your codebase's evolution, integrate quality gates into your CI/CD pipeline, and get a big-picture view across all your projects,51sign up for the early access list [here](https://docs.google.com/forms/d/e/1FAIpQLScIBKy3y2m0rKu89L67qwe26Xyn9Scu0gW-HQX9lC0qEAx9nQ/viewform)5253### Install5455#### Go Install5657You can install `scc` by using the standard go toolchain.5859To install the latest stable version of scc:6061`go install github.com/boyter/scc/v4@latest`6263To install a development version:6465`go install github.com/boyter/scc/v4@master`6667Note that `scc` needs go version >= 1.25.6869#### Snap7071A [snap install](https://snapcraft.io/scc) exists thanks to [Ricardo](https://feliciano.tech/).7273`$ sudo snap install scc`7475*NB* Snap installed applications cannot run outside of `/home` <https://askubuntu.com/questions/930437/permission-denied-error-when-running-apps-installed-as-snap-packages-ubuntu-17> so you may encounter issues if you use snap and attempt to run outside this directory.7677#### Homebrew7879Or if you have [Homebrew](https://brew.sh/) installed8081`$ brew install scc`8283#### Fedora8485Fedora Linux users can use a [COPR repository](https://copr.fedorainfracloud.org/coprs/lihaohong/scc/):8687`$ sudo dnf copr enable lihaohong/scc && sudo dnf install scc`8889#### MacPorts9091On macOS, you can also install via [MacPorts](https://www.macports.org)9293`$ sudo port install scc`9495#### Scoop9697Or if you are using [Scoop](https://scoop.sh/) on Windows9899`$ scoop install scc`100101#### Chocolatey102103Or if you are using [Chocolatey](https://chocolatey.org/) on Windows104105`$ choco install scc`106107#### WinGet108109Or if you are using [WinGet](https://github.com/microsoft/winget-cli) on Windows110111`winget install --id benboyter.scc --source winget`112113#### FreeBSD114115On FreeBSD, scc is available as a package116117`$ pkg install scc`118119Or, if you prefer to build from source, you can use the ports tree120121`$ cd /usr/ports/devel/scc && make install clean`122123### Run in Docker124125Go to the directory you want to run scc from.126127Run the command below to run the latest release of scc on your current working directory:128129```bash130docker run --rm -it -v "$PWD:/pwd:ro" --network none ghcr.io/boyter/scc:master scc /pwd131```132133#### Manual134135Binaries for Windows, GNU/Linux and macOS for both i386 and x86_64 machines are available from the [releases](https://github.com/boyter/scc/releases) page.136137#### GitLab138139<https://about.gitlab.com/blog/2023/02/15/code-counting-in-gitlab/>140141#### Other142143If you would like to assist with getting `scc` added into apt/chocolatey/etc... please submit a PR or at least raise an issue with instructions.144145### Background146147Read all about how it came to be along with performance benchmarks,148149- <https://boyter.org/posts/sloc-cloc-code/>150- <https://boyter.org/posts/why-count-lines-of-code/>151- <https://boyter.org/posts/sloc-cloc-code-revisited/>152- <https://boyter.org/posts/sloc-cloc-code-performance/>153- <https://boyter.org/posts/sloc-cloc-code-performance-update/>154155Some reviews of `scc`156157- <https://nickmchardy.com/2018/10/counting-lines-of-code-in-koi-cms.html>158- <https://www.feliciano.tech/blog/determine-source-code-size-and-complexity-with-scc/>159- <https://metaredux.com/posts/2019/12/13/counting-lines.html>160161Setting up `scc` in GitLab162163- <https://about.gitlab.com/blog/2023/02/15/code-counting-in-gitlab/>164165A talk given at the first GopherCon AU about `scc` (press S to see speaker notes)166167- <https://boyter.org/static/gophercon-syd-presentation/>168- <https://www.youtube.com/watch?v=jd-sjoy3GZo>169170For performance see the [Performance](https://github.com/boyter/scc#performance) section171172Other similar projects,173174- [SLOCCount](https://www.dwheeler.com/sloccount/) the original sloc counter175- [cloc](https://github.com/AlDanial/cloc), inspired by SLOCCount; implemented in Perl for portability176- [gocloc](https://github.com/hhatto/gocloc) a sloc counter in Go inspired by tokei177- [loc](https://github.com/cgag/loc) rust implementation similar to tokei but often faster178- [loccount](https://gitlab.com/esr/loccount) Go implementation written and maintained by ESR179- [polyglot](https://github.com/vmchale/polyglot) ATS sloc counter180- [tokei](https://github.com/XAMPPRocky/tokei) fast, accurate and written in rust181- [sloc](https://github.com/flosse/sloc) coffeescript code counter182- [stto](https://github.com/mainak55512/stto) new Go code counter with a focus on performance183184Interesting reading about other code counting projects tokei, loc, polyglot and loccount185186- <https://www.reddit.com/r/rust/comments/59bm3t/a_fast_cloc_replacement_in_rust/>187- <https://www.reddit.com/r/rust/comments/82k9iy/loc_count_lines_of_code_quickly/>188- <http://blog.vmchale.com/article/polyglot-comparisons>189- <http://esr.ibiblio.org/?p=8270>190191Further reading about processing files on the disk performance192193- <https://blog.burntsushi.net/ripgrep/>194195Using `scc` to process 40 TB of files from GitHub/Bitbucket/GitLab196197- <https://boyter.org/posts/an-informal-survey-of-10-million-github-bitbucket-gitlab-projects/>198199### Pitch200201Why use `scc`?202203- It is very fast and gets faster the more CPU you throw at it204- Accurate205- Works very well across multiple platforms without slowdown (Windows, Linux, macOS)206- Large language support207- Can ignore duplicate files208- Has complexity estimations209- You need to tell the difference between Coq and Verilog in the same directory210- cloc yaml output support so potentially a drop in replacement for some users211- Can identify or ignore minified files212- Able to identify many #! files ADVANCED! <https://github.com/boyter/scc/issues/115>213- Can ignore large files by lines or bytes214- Can calculate the ULOC or unique lines of code by file, language or project215- Supports multiple output formats for integration, CSV, SQL, JSON, HTML and more216217Why not use `scc`?218219- You don't like Go for some reason220- It cannot count D source with different nested multi-line comments correctly <https://github.com/boyter/scc/issues/27>221222### Differences223224There are some important differences between `scc` and other tools that are out there. Here are a few important ones for you to consider.225226Blank lines inside comments are counted as comments. While the line is technically blank the decision was made that once in a comment everything there should be considered a comment until that comment is ended. As such the following,227228```c229/* blank lines follow230231232*/233```234235Would be counted as 4 lines of comments. This is noticeable when comparing scc's output to other tools on large236repositories.237238`scc` is able to count verbatim strings correctly. For example in C# the following,239240```C#241private const string BasePath = @"a:\";242// The below is returned to the user as a version243private const string Version = "1.0.0";244```245246Because of the prefixed @ this string ends at the trailing " by ignoring the escape character \ and as such should be247counted as 2 code lines and 1 comment. Some tools are unable to248deal with this and instead count up to the "1.0.0" as a string which can cause the middle comment to be counted as249code rather than a comment.250251`scc` will also tell you the number of bytes it has processed (for most output formats) allowing you to estimate the252cost of running some static analysis tools.253254### Usage255256Command line usage of `scc` is designed to be as simple as possible.257Full details can be found in `scc --help` or `scc -h`. Note that the below reflects the state of master not a release, as such258features listed below may be missing from your installation.259260```text261$ scc -h262Sloc, Cloc and Code. Count lines of code in a directory with complexity estimation.263Version 4.0.0264Ben Boyter <ben@boyter.org> + Contributors265https://github.com/boyter/scc266267Usage:268 scc [flags] [files or directories]269270Examples:271 Count the current directory:272 scc273274 Count a specific folder or file:275 scc myproject/276 scc main.go277278 Count several paths at once:279 scc src/ docs/ README.md280281 Show a per-file breakdown instead of the per-language summary:282 scc --by-file283284 Output as CSV or JSON (e.g. for further processing):285 scc --format csv286 scc --format json -o counts.json287288 Count an unrecognised extension as a known language:289 scc --count-as jsp:html290291 Count files matching a path pattern as a new category (glob by default):292 scc --count-as-pattern '*_spec.rb:Ruby Spec:Ruby'293294 Generate a self-contained HTML infographic report:295 scc --report296 scc --report=out.html --report-title "myrepo" --report-skip cocomo297298 Use a project config file (./.sccconfig) or a global one (precedence: global < project < CLI):299 export SCC_CONFIG_PATH=~/.sccconfig300 scc --config team.sccconfig301302 Tune the COCOMO cost estimate, or turn it off (see https://en.wikipedia.org/wiki/COCOMO):303 scc --avg-wage 75000 --cocomo-project-type semi-detached304 scc --no-cocomo305306Flags:307 --avg-wage int average wage value used for basic COCOMO calculation (default 56286)308 --binary disable binary file detection309 --buckets int time-bucket resolution for the git timeline reports (default 60)310 --by-author render the author rollup report (bus factor and last-toucher attribution over recent git history)311 --by-file display output for every file312 -m, --character calculate max and mean characters per line313 --ci enable CI output settings where stdout is ASCII314 --cocomo-project-type string change COCOMO model type [organic, semi-detached, embedded, "custom,1,1,1,1"] (default "organic")315 --cognitive calculate cognitive (nesting-weighted) complexity316 --config string load this file as the global config source; overrides SCC_CONFIG_PATH, honored even with --no-config317 --cost-comparison show both COCOMO and LOCOMO estimates side by side318 --count-as string count extension as language [e.g. jsp:htm,chead:"C Header" maps extension jsp to html and chead to C Header]319 --count-as-pattern stringArray count files matching a path pattern as a new named category backed by a base language [repeatable; pattern is glob by default, prefix with re: for regex; e.g. *_spec.rb:"Ruby Spec":Ruby or re:\.test\.js$:"JavaScript Tests":JavaScript]320 --count-ignore set to allow .gitignore and .ignore files to be counted321 --count-unsupported count files with an unrecognised language under an "Unknown" category as plain text322 --coupling render the change-coupling report (file pairs that change together over recent git history)323 --coupling-for string blast-radius view: given a file path, show what tends to change with it over recent git history324 --coupling-weighted weight coupling by file complexity so pairs of complex files rank above generated/data-file churn (implies --coupling)325 --currency-symbol string set currency symbol (default "$")326 --debug enable debug output327 --depth int commit window size for git history reports; 0 means entire history (large repos may be slow) (default 1000)328 --directory-walker-job-workers int controls the maximum number of workers which will walk the directory tree (default 8)329 -a, --dryness calculate the DRYness of the project (implies --uloc)330 --eaf float the effort adjustment factor derived from the cost drivers (1.0 if rated nominal) (default 1)331 --exclude-dir strings directories to exclude (default [.git,.hg,.svn])332 -x, --exclude-ext strings ignore file extensions (overrides include-ext) [comma separated list: e.g. go,java,js]333 -n, --exclude-file strings ignore files with matching names (default [package-lock.json,Cargo.lock,yarn.lock,pubspec.lock,Podfile.lock,pnpm-lock.yaml])334 --file-gc-count int number of files to parse before turning the GC on (default 10000)335 --file-list-queue-size int the size of the queue of files found and ready to be read into memory (default 8)336 --file-process-job-workers int number of goroutine workers that process files collecting stats (default 8)337 --file-summary-job-queue-size int the size of the queue used to hold processed file statistics before formatting (default 8)338 --find-root-config discover the project .sccconfig by walking up to the repository root instead of using ./.sccconfig339 -f, --format string set output format [tabular, wide, json, json2, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics] (default "tabular")340 --format-multi string have multiple format output overriding --format [e.g. tabular:stdout,csv:file.csv,json:file.json]341 --gen identify generated files342 --generated-markers strings string markers in head of generated files (default [do not edit,<auto-generated />])343 -h, --help help for scc344 --hotspots render the hotspots report (files ranked by complexity × change frequency over recent git history)345 --ignore-file stringArray path to an additional gitignore-format ignore file, applied from the scan root; repeat to add more, later files and any in-tree ignore files take precedence346 -i, --include-ext strings limit to file extensions [comma separated list: e.g. go,java,js]347 --include-symlinks if set will count symlink files348 -l, --languages print supported languages and extensions349 --large-byte-count int number of bytes a file can contain before being removed from output (default 1000000)350 --large-line-count int number of lines a file can contain before being removed from output (default 40000)351 --locomo enable LOCOMO (LLM Output COst MOdel) cost estimation352 --locomo-config string LOCOMO power-user config "tokensPerLine,inputPerLine,complexityWeight,iterations,iterationWeight"353 --locomo-cycles float override estimated LLM iteration cycles (default: calculated from complexity)354 --locomo-input-price float LOCOMO cost per 1M input tokens in dollars (overrides preset)355 --locomo-output-price float LOCOMO cost per 1M output tokens in dollars (overrides preset)356 --locomo-preset string LOCOMO model preset [large, medium, small, local] (default "medium")357 --locomo-review float human review minutes per line of code for LOCOMO estimate (default 0.01)358 --locomo-tps float LOCOMO output tokens per second (overrides preset)359 --mcp start as an MCP (Model Context Protocol) server over stdio360 --min identify minified files361 -z, --min-gen identify minified or generated files362 --min-gen-line-length int number of bytes per average line for file to be considered minified or generated (default 255)363 --no-cocomo remove COCOMO calculation output364 -c, --no-complexity skip calculation of code complexity365 --no-config disable auto-discovery of the SCC_CONFIG_PATH global and the project ./.sccconfig config366 -d, --no-duplicates remove duplicate files from stats and output367 --no-fold-authors disable the name+email-domain identity folding fallback for git author reports (mailmap still applied)368 --no-gen ignore generated files in output (implies --gen)369 --no-gitignore disables .gitignore file logic370 --no-gitmodule disables .gitmodules file logic371 --no-hborder remove horizontal borders between sections372 --no-ignore disables .ignore file logic373 --no-large ignore files over certain byte and line size set by large-line-count and large-byte-count374 --no-min ignore minified files in output (implies --min)375 --no-min-gen ignore minified or generated files in output (implies --min-gen)376 --no-scc-ignore disables .sccignore file logic377 --no-size remove size calculation output378 -M, --not-match stringArray ignore files and directories matching regular expression379 -o, --output string output filename (default stdout)380 --overhead float set the overhead multiplier for corporate overhead (facilities, equipment, accounting, etc.) (default 2.4)381 -p, --percent include percentage values in output382 --remap-all string inspect every file and remap by checking for a string and remapping the language [e.g. "-*- C++ -*-":"C Header"]383 --remap-unknown string inspect files of unknown type and remap by checking for a string and remapping the language [e.g. "-*- C++ -*-":"C Header"]384 --report string[="scc-report.html"] write a self-contained HTML report; bare flag writes scc-report.html and prompts before overwriting, --report=path/out.html overwrites silently385 --report-skip string comma-separated sections to omit (cocomo,locomo,hotspots,coupling,authors,timeline,files,uloc,linelength,card)386 --report-title string override the repo name shown in the report banner387 --size-unit string set size unit [si, binary, mixed, xkcd-kb, xkcd-kelly, xkcd-imaginary, xkcd-intel, xkcd-drive, xkcd-bakers] (default "si")388 --sloccount-format print a more SLOCCount like COCOMO calculation389 -s, --sort string column to sort by [files, name, lines, blanks, code, comments, complexity] (default "files")390 --sql-project string use supplied name as the project identifier for the current run. Only valid with the --format sql or sql-insert option391 --timeline render an over-time view of recent git history; with --by-author runs the author timeline, alone runs the languages timeline392 -t, --trace enable trace output (not recommended when processing multiple files)393 -u, --uloc calculate the number of unique lines of code (ULOC) for the project394 -v, --verbose verbose output395 --version version for scc396 -w, --wide wider output with additional statistics (implies --complexity)397```398399Output should look something like the below for the redis project400401```text402$ scc redis 403───────────────────────────────────────────────────────────────────────────────404Language Files Lines Blanks Comments Code Complexity405───────────────────────────────────────────────────────────────────────────────406C 437 267,353 31,103 45,998 190,252 48,269407JSON 406 25,392 4 0 25,388 0408C Header 288 48,831 5,648 11,302 31,881 3,097409TCL 215 66,943 7,330 4,651 54,962 3,816410Shell 75 1,626 239 343 1,044 185411Python 34 4,802 694 498 3,610 621412Markdown 26 4,647 1,226 0 3,421 0413Autoconf 22 11,732 1,124 1,420 9,188 1,016414Lua 20 525 69 71 385 89415Makefile 20 1,956 368 170 1,418 85416YAML 20 2,696 147 53 2,496 0417MSBuild 11 1,995 2 0 1,993 160418Plain Text 10 1,773 313 0 1,460 0419Ruby 9 817 73 105 639 123420C++ 8 546 85 43 418 43421HTML 5 9,658 2,928 12 6,718 0422License 3 90 17 0 73 0423CMake 2 298 49 5 244 12424CSS 2 107 16 0 91 0425Systemd 2 80 6 0 74 0426BASH 1 143 16 5 122 38427Batch 1 28 2 0 26 3428C++ Header 1 9 1 3 5 0429Extensible Styleshe… 1 10 0 0 10 0430JavaScript 1 31 1 0 30 5431Module-Definition 1 11,375 2,116 0 9,259 167432SVG 1 1 0 0 1 0433Smarty Template 1 44 1 0 43 5434m4 1 951 218 64 669 0435───────────────────────────────────────────────────────────────────────────────436Total 1,624 464,459 53,796 64,743 345,920 57,734437───────────────────────────────────────────────────────────────────────────────438Estimated Cost to Develop (organic) $12,517,562439Estimated Schedule Effort (organic) 35.93 months440Estimated People Required (organic) 30.95441───────────────────────────────────────────────────────────────────────────────442Processed 16601962 bytes, 16.602 megabytes (SI)443───────────────────────────────────────────────────────────────────────────────444```445446Note that you don't have to specify the directory you want to run against. Running `scc` will assume you want to run against the current directory.447448You can also run against multiple files or directories `scc directory1 directory2 file1 file2` with the results aggregated in the output.449450Since `scc` writes to standard output, there are many ways to easily share the results. For example, using [netcat](https://manpages.org/nc)451and [one of many pastebins](https://paste.c-net.org/) gives a public URL:452453```bash454$ scc | nc paste.c-net.org 9999455https://paste.c-net.org/Example456```457458### Ignore Files459460`scc` supports .ignore files inside directories that it scans. This is similar to how ripgrep, ag and tokei work. 461.ignore files are 100% the same as .gitignore files with the same syntax, and as such `scc` will ignore files and 462directories listed in them. You can add .ignore files to ignore things like vendored dependency checked in files and 463such. The idea is allowing you to add a file or folder to git and have ignored in the count.464465It also supports its own ignore file `.sccignore` if you want `scc` to ignore things while having ripgrep, ag, tokei 466and others support them.467468You can also supply additional ignore files from outside the scanned tree with `--ignore-file`. The file uses the 469same gitignore syntax and its patterns are anchored at the scan root (so `/build` matches only the top-level `build`). 470This is handy for applying a shared ruleset such as a `.dockerignore` or a personal global ignore:471472```473scc --ignore-file ~/.gitignore --ignore-file ./.dockerignore474```475476The flag can be repeated and order matters: a later file can re-include something an earlier one ignored (via a `!` 477negation), and any `.gitignore`, `.ignore` or `.sccignore` discovered inside the scanned tree takes precedence over 478everything supplied with `--ignore-file`.479480If you want to apply your global git excludes file, point `--ignore-file` at it directly (for example 481`--ignore-file ~/.config/git/ignore`). `scc` deliberately does not shell out to `git` to discover it for you, but you 482can make it automatic by putting the flag in a `.sccconfig` configuration file and pointing the `SCC_CONFIG_PATH` environment 483variable at it, so every run picks it up without typing:484485```486# ~/.config/scc/global.sccconfig487--ignore-file /home/me/.config/git/ignore488```489490```491export SCC_CONFIG_PATH=~/.config/scc/global.sccconfig492scc # now applies your global ignore on every run493```494495### Configuration Files496497`scc` can read default flags from a configuration file to avoid creating shell aliases. 498The format is an *opts-list* in the style of ripgrep and bat: the file is simply a list of the same command-line flags 499you would otherwise type, and anything valid on the command line is valid in the file, with the exception500of output flags.501502Format rules:503504- One flag per line is the recommended style, but multiple whitespace-separated tokens per line are allowed (`--exclude-dir vendor`).505- Lines use the normal `--` prefix, e.g. `--no-cocomo`.506- `#` begins a comment. Whole-line and inline trailing comments are stripped.507- Blank lines are ignored.508- Tokenization is quote-aware, so both `--exclude-dir vendor` and `--count-as 'jsp:html'` work. Quotes (single or double) are the only grouping mechanism; to include a literal quote, switch quote style (`--count-as "a'b"`).509- Backslash is an ordinary literal, not an escape character, so a Windows path such as `--exclude-dir C:\build\out` survives verbatim.510- A line whose first token does not start with `-` (a bare positional such as `src/`) is skipped with a warning, so a config file cannot inject extra count targets.511512Example `.sccconfig`:513514```515# count the way I like it516--no-cocomo517--exclude-dir vendor,node_modules518--format wide # default to the wider table519```520521#### Sources and discovery522523There are two configuration tiers:524525- **Global** — there is no fixed default location and no per-run home-directory stat. The global source is consulted only when set explicitly via the `SCC_CONFIG_PATH` environment variable or the `--config <path>` flag. `--config` which overrides `SCC_CONFIG_PATH`.526- **Project** — a file named `.sccconfig` in the current working directory (`./.sccconfig`), found with a single stat and **no walk-up**. `cd project && scc` picks up `project/.sccconfig`; running `scc` from a subdirectory does **not** pick up an ancestor's `.sccconfig`. Path arguments do not move the anchor — `scc ./project` still reads `./.sccconfig`, not `./project/.sccconfig`.527528To read the repository root's `.sccconfig` from a subdirectory, pass `--find-root-config`, which walks back from the current directory to the git/hg root. It is off by default and affects config discovery only - it changes which `.sccconfig` is read, not which directory is counted. Outside a repository it degrades to `./.sccconfig`.529530#### Precedence531532Lowest to highest, later wins: **global config < project config < command line**. Scalar and boolean flags follow last-wins, so the command line always overrides config.533534Slice flags (`--exclude-dir`, `--exclude-file`, `--exclude-ext`, `--include-ext`, `--not-match`) **union** instead of overriding:535536```537config: --exclude-dir vendor538CLI: --exclude-dir dist539result: vendor, dist540```541542The three slice flags that ship with built-in defaults — `--exclude-dir` (`.git`, `.hg`, `.svn`), `--exclude-file` (the lockfile set) and `--generated-markers` — keep those defaults as a non-removable safety net: a config or CLI value is *added* to the defaults rather than replacing them, so putting `vendor` in `.sccconfig` never stops `scc` skipping `.git`.543544#### Config can never write a file545546A configuration file can change how `scc` counts and formats, including selecting a stdout format such as `--format json`, but it can **never** cause `scc` to write a file. The file-output flags — `--output` / `-o`, `--report` and `--format-multi` — are honoured only from the command line; the same flags supplied by config are ignored (output goes to stdout, the default). This is because a project `.sccconfig` is auto-discovered, so a cloned repository could otherwise silently overwrite one of your files. Only the command line can make `scc` write to disk.547548#### Control flags549550| Flag | Effect |551|------|--------|552| `--no-config` | Disable auto-discovery: skip the `SCC_CONFIG_PATH` global and the project `.sccconfig`. |553| `--config <path>` | Load this file as the global source. Always honoured, even with `--no-config`; overrides `SCC_CONFIG_PATH`. |554| `--find-root-config` | Discover the project `.sccconfig` by walking up to the repository root instead of using `./.sccconfig`. No-op under `--no-config`. |555556`--config test.sccconfig --no-config` loads exactly `test.sccconfig` and nothing else — a clean isolated-config mode. A `--config` or `--no-config` written *inside* a config file is inert (a config file cannot chain-load another config file).557558#### The `@file` argument bundle559560`scc @flags.txt` expands the contents of `flags.txt` as if its lines had been typed on the command line. It uses the same opts-list tokenizer as config files (comments, quotes, backslash-literal), but unlike config files it **keeps positional paths** and **may write files** — an `@file` is an explicit, user-supplied argument bundle equivalent to typing the flags, so it is trusted like the command line (including a `--config` inside it being honoured). `@file` expansion fires only when `@file` is the sole argument.561562Note that because config discovery now runs on the post-`@file` arguments, `scc @flags.txt` in a directory containing `./.sccconfig` loads **both** — the `@file` tokens sit above the config in precedence. To get the old "exactly these args, nothing else" behaviour, add `--no-config`.563564### Interesting Use Cases565566Used inside Intel Nemu Hypervisor to track code changes between revisions <https://github.com/intel/nemu/blob/topic/virt-x86/tools/cloc-change.sh#L9>567Appears to also be used inside both <http://codescoop.com/> <https://pinpoint.com/> <https://github.com/chaoss/grimoirelab-graal>568569It also is used to count code and guess language types in <https://searchcode.com/> which makes it one of the most frequently run code counters in the world.570571You can also hook scc into your gitlab pipeline <https://gitlab.com/guided-explorations/ci-cd-plugin-extensions/ci-cd-plugin-extension-scc>572573Used by the following products and services,574575- [GitHub CodeQL](https://github.com/boyter/scc/pull/317) - The CodeQL engine uses `scc` for line counting576- [JetBrains Qodana](https://github.com/JetBrains/qodana-cli) - The Qodana CLI leverages `scc` as a command-line helper for code analysis577- [Scaleway](https://twitter.com/Scaleway/status/1488087029476995074?s=20&t=N2-z6O-ISDdDzULg4o4uVQ) - Cloud provider using `scc`578- [Linux Foundation LFX Insights](https://docs.linuxfoundation.org/lfx/insights/v3-beta-version-current/getting-started/landing-page/cocomo-cost-estimation-simplified) - COCOMO cost estimation579- [OpenEMS](https://openems.io/)580581### Features582583`scc` uses a small state machine in order to determine what state the code is when it reaches a newline `\n`. As such it is aware of and able to count584585- Single Line Comments586- Multi Line Comments587- Strings588- Multi Line Strings589- Blank lines590591Because of this it is able to accurately determine if a comment is in a string or is actually a comment.592593It also attempts to count the complexity of code. This is done by checking for branching operations in the code. For example, each of the following `for if switch while else || && != ==` if encountered in Java would increment that files complexity by one.594595### Complexity Estimates596597Let's take a minute to discuss the complexity estimate itself.598599The complexity estimate is really just a number that is only comparable to files in the same language. It should not be used to compare languages directly without weighting them. The reason for this is that its calculated by looking for branch and loop statements in the code and incrementing a counter for that file.600601Because some languages don't have loops and instead use recursion they can have a lower complexity count. Does this mean they are less complex? Probably not, but the tool cannot see this because it does not build an AST of the code as it only scans through it.602603Generally though the complexity there is to help estimate between projects written in the same language, or for finding the most complex file in a project `scc --by-file -s complexity` which can be useful when you are estimating on how hard something is to maintain, or when looking for those files that should probably be refactored.604605As for how it works.606607It's my own definition, but tries to be an approximation of cyclomatic complexity <https://en.wikipedia.org/wiki/Cyclomatic_complexity> although done only on a file level.608609The reason it's an approximation is that it's calculated almost for free from a CPU point of view (since its a cheap lookup when counting), whereas a real cyclomatic complexity count would need to parse the code. It gives a reasonable guess in practice though even if it fails to identify recursive methods. The goal was never for it to be exact.610611In short when scc is looking through what it has identified as code if it notices what are usually branch conditions it will increment a counter.612613The conditions it looks for are compiled into the code and you can get an idea for them by looking at the JSON inside the repository. See <https://github.com/boyter/scc/blob/master/languages.json#L3869> for an example of what it's looking at for a file that's Java.614615The increment happens for each of the matching conditions and produces the number you see.616617### Unique Lines of Code (ULOC)618619ULOC stands for Unique Lines of Code and represents the unique lines across languages, files and the project itself. This idea was taken from620<https://cmcenroe.me/2018/12/14/uloc.html> where the calculation is presented using standard Unix tools `sort -u *.h *.c | wc -l`. This metric is621there to assist with the estimation of complexity within the project. Quoting the source622623> In my opinion, the number this produces should be a better estimate of the complexity of a project. Compared to SLOC, not only are blank lines discounted, but so are close-brace lines and other repetitive code such as common includes. On the other hand, ULOC counts comments, which require just as much maintenance as the code around them does, while avoiding inflating the result with license headers which appear in every file, for example.624625You can obtain the ULOC by supplying the `-u` or `--uloc` argument to `scc`.626627It has a corresponding metric `DRYness %` which is the percentage of ULOC to CLOC or `DRYness = ULOC / SLOC`. The628higher the number the more DRY (don't repeat yourself) the project can be considered. In general a higher value629here is a better as it indicates less duplicated code. The DRYness metric was taken from a comment by minimax <https://lobste.rs/s/has9r7/uloc_unique_lines_code>630631To obtain the DRYness metric you can use the `-a` or `--dryness` argument to `scc`, which will implicitly set `--uloc`.632633Note that there is a performance penalty when calculating the ULOC metrics which can double the runtime.634635Running the uloc and DRYness calculations against C code a clone of redis produces an output as follows.636637```bash638$ scc -a -i c redis 639───────────────────────────────────────────────────────────────────────────────640Language Files Lines Blanks Comments Code Complexity641───────────────────────────────────────────────────────────────────────────────642C 437 267,353 31,103 45,998 190,252 48,269643(ULOC) 149892644───────────────────────────────────────────────────────────────────────────────645Total 437 267,353 31,103 45,998 190,252 48,269646───────────────────────────────────────────────────────────────────────────────647Unique Lines of Code (ULOC) 149892648DRYness % 0.56649───────────────────────────────────────────────────────────────────────────────650Estimated Cost to Develop (organic) $6,681,762651Estimated Schedule Effort (organic) 28.31 months652Estimated People Required (organic) 20.97653───────────────────────────────────────────────────────────────────────────────654Processed 9390815 bytes, 9.391 megabytes (SI)655───────────────────────────────────────────────────────────────────────────────656```657658Further reading about the ULOC calculation can be found at <https://boyter.org/posts/sloc-cloc-code-new-metic-uloc/>659660Interpreting Dryness,661662- 75% (High Density): Very terse, expressive code. Every line counts. (Example: Clojure, Haskell)663- 60% - 70% (Standard): A healthy balance of logic and structural ceremony. (Example: Java, Python)664- < 55% (High Boilerplate): High repetition. Likely due to mandatory error handling, auto-generated code, or verbose configuration. (Example: C#, CSS)665666See <https://boyter.org/posts/boilerplate-tax-ranking-popular-languages-by-density/> for more details.667668### COCOMO669670The COCOMO statistics displayed at the bottom of any command line run can be configured as needed.671672```text673Estimated Cost to Develop (organic) $664,081674Estimated Schedule Effort (organic) 11.772217 months675Estimated People Required (organic) 5.011633676```677678To change the COCOMO parameters, you can either use one of the default COCOMO models.679680```text681scc --cocomo-project-type organic682scc --cocomo-project-type semi-detached683scc --cocomo-project-type embedded684```685686You can also supply your own parameters if you are familiar with COCOMO as follows,687688```text689scc --cocomo-project-type "custom,1,1,1,1"690```691692See below for details about how the model choices, and the parameters they use.693694Organic – A software project is said to be an organic type if the team size required is adequately small, the695problem is well understood and has been solved in the past and also the team members have a nominal experience696regarding the problem.697698`scc --cocomo-project-type "organic,2.4,1.05,2.5,0.38"`699700Semi-detached – A software project is said to be a Semi-detached type if the vital characteristics such as team-size,701experience, knowledge of the various programming environment lie in between that of organic and Embedded.702The projects classified as Semi-Detached are comparatively less familiar and difficult to develop compared to703the organic ones and require more experience and better guidance and creativity. Eg: Compilers or704different Embedded Systems can be considered of Semi-Detached type.705706`scc --cocomo-project-type "semi-detached,3.0,1.12,2.5,0.35"`707708Embedded – A software project with requiring the highest level of complexity, creativity, and experience709requirement fall under this category. Such software requires a larger team size than the other two models710and also the developers need to be sufficiently experienced and creative to develop such complex models.711712`scc --cocomo-project-type "embedded,3.6,1.20,2.5,0.32"`713714### LOCOMO715716LOCOMO (LLM Output COst MOdel) estimates the cost to regenerate a codebase using a large language model. It is the LLM-era counterpart to COCOMO - a rough ballpark estimator, not a project planning tool.717718Note: LOCOMO was developed as part of `scc` and is not an industry-standard model. Unlike COCOMO, which is based on decades of empirical research by Barry Boehm, LOCOMO is an experimental heuristic designed to give a useful order-of-magnitude estimate for LLM-assisted development costs. Treat its output as a conversation starter, not a definitive answer.719720**Important distinction:** LOCOMO estimates the cost to **regenerate** known code - essentially "given this exact codebase, how much would it cost to have an LLM produce it?" This is fundamentally different from the cost to **create** something from scratch, which involves exploration, architectural decisions, dead ends, debugging, and iteration that can cost orders of magnitude more. COCOMO estimates the human *creation* cost; LOCOMO estimates the LLM *regeneration* cost. They answer different questions.721722LOCOMO is opt-in. Enable it with `--locomo` or use `--cost-comparison` to display both COCOMO and LOCOMO side by side.723724```725$ scc --locomo .726...727LOCOMO LLM Cost Estimate (medium)728 Tokens Required (in/out) 3.0M / 0.7M729 Cost to Generate $20730 Estimated Cycles 2.1731 Generation Time (serial) 3.9 hours732 Human Review Time 5.9 hours733 Disclaimer: rough ballpark for regenerating code using a LLM.734 Does not account for context reuse, test generation, or heavy debugging.735```736737#### How it works738739LOCOMO uses SLOC and complexity data that `scc` already computes. The model works per-file and aggregates:7407411. **Output tokens** - each line of code maps to ~10 LLM output tokens (configurable).7422. **Input tokens** - estimated prompting cost, scaled by code complexity. More complex code (higher branch density) requires more detailed prompts. Scales to prevent runaway estimates.7433. **Iteration factor** - LLMs rarely produce correct code on the first try. A retry multiplier scales with complexity, also scales.7444. **Dollar cost** - input and output tokens multiplied by per-token pricing.7455. **Generation time** - total serial output tokens divided by tokens-per-second throughput.7466. **Human review time** - estimated per-line overhead for planning, review, testing, and integration.747748#### Model presets749750Presets are tier-based rather than tied to specific models, so they don't go stale as models are retired or renamed. Use `--locomo-preset` to select a tier:751752| Preset | Represents | Input $/1M | Output $/1M | TPS |753|--------|-----------|-----------|-------------|-----|754| `large` | Frontier models (Opus, GPT-5.3, Gemini 3.1 Pro, etc.) | 10.00 | 30.00 | 30 |755| `medium` (default) | Balanced models (Sonnet, Gemini Flash, etc.) | 3.00 | 15.00 | 50 |756| `small` | Fast/cheap models (Haiku, GPT-4o-mini, etc.) | 0.50 | 2.00 | 100 |757| `local` | Self-hosted models (Llama, Mistral, Qwen etc.) | 0.00 | 0.00 | 15 |758759For `local`, cost is $0 but generation time is still reported to capture the compute/time investment. Preset pricing reflects approximate tier rates as of early 2026 and can be overridden with explicit flags.760761```762scc --locomo --locomo-preset large .763scc --locomo --locomo-preset local .764```765766#### Overriding preset values767768You can override individual preset values for pricing or throughput:769770```771scc --locomo --locomo-input-price 1.0 --locomo-output-price 5.0 .772scc --locomo --locomo-tps 100 .773```774775#### Human review time776777The `--locomo-review` flag controls estimated human review minutes per line of code (default: 0.01, i.e. 0.6 seconds per line). This is intentionally optimistic and assumes light oversight.778779For mission-critical, security-sensitive, or complex algorithmic code you should increase this:780781```782scc --locomo --locomo-review 0.05 .783scc --locomo --locomo-review 0.1 .784```785786#### Power-user configuration787788The five internal model parameters can be overridden with a single comma-separated config string:789790```791scc --locomo --locomo-config "tokensPerLine,inputPerLine,complexityWeight,iterations,iterationWeight"792```793794The defaults are `"10,20,5,1.5,2"`. Here is what each parameter controls:795796| Position | Name | Default | Description |797|----------|------|---------|-------------|798| 1 | tokensPerLine | 10 | Average LLM output tokens per line of code |799| 2 | inputPerLine | 20 | Base LLM input (prompt) tokens per output line |800| 3 | complexityWeight | 5 | How much complexity density scales input tokens: `inputFactor = 1 + sqrt(density) * weight` |801| 4 | iterations | 1.5 | Base iteration/retry cycles before complexity adjustment |802| 5 | iterationWeight | 2 | How much complexity density adds extra cycles: `cycles = iterations + sqrt(density) * weight` |803804The iteration factor (cycles) scales both input and output tokens - it represents how many generation attempts the LLM needs. Simple code (~0.05 complexity density) produces ~1.9 cycles; complex code (~0.3 density) produces ~2.6 cycles. Use `--locomo-cycles` to override this with a fixed value.805806For example, to model a cheaper/faster LLM that needs fewer tokens but more retries:807808```809scc --locomo --locomo-config "8,15,3,2.0,1.5"810```811812#### Comparing COCOMO and LOCOMO813814Use `--cost-comparison` to show both estimates side by side. This enables COCOMO (if it was disabled) and LOCOMO together:815816```817scc --cost-comparison .818```819820#### What LOCOMO does not account for821822LOCOMO is a rough estimator with known limitations:823824- **No context reuse.** Real LLM-assisted development shares context across files. The per-file model overestimates input tokens for large projects with shared patterns.825- **Boilerplate vs algorithmic code.** A 500-line CRUD controller and a 500-line compression algorithm have very different real costs, but the model only differentiates them via complexity density.826- **Code that LLMs can't write well.** Complex concurrency, platform-specific edge cases, and security-critical crypto need human authoring, not just review.827- **No test generation cost.** The model estimates source code generation only, not test suites.828- **Pricing changes.** LLM pricing drops rapidly. Preset defaults will become stale - use explicit price flags for current estimates.829830#### All LOCOMO flags831832| Flag | Default | Description |833|------|---------|-------------|834| `--locomo` | false | Enable LOCOMO output |835| `--cost-comparison` | false | Show COCOMO + LOCOMO side by side |836| `--locomo-preset` | medium | Model tier preset for pricing and throughput |837| `--locomo-input-price` | (preset) | Override: cost per 1M input tokens ($) |838| `--locomo-output-price` | (preset) | Override: cost per 1M output tokens ($) |839| `--locomo-tps` | (preset) | Override: output tokens per second |840| `--locomo-review` | 0.01 | Human review minutes per line of code |841| `--locomo-cycles` | (calculated) | Override estimated LLM iteration cycles |842| `--locomo-config` | 10,20,5,1.5,2 | Power-user config: tokensPerLine, inputPerLine, complexityWeight, iterations, iterationWeight |843844### Git Insight Reports845846In addition to counting the working tree, `scc` can run five git-aware reports over recent commit history. Each is selected by a flag and rendered as `tabular` (default), `csv`, or `json` via `--format`. All are derived from one in-process walk of the repository - there is no `exec("git")`, so the `git` binary does not need to be on `PATH`.847848> **Note:** these reports are **slower** than a normal `scc` run. They walk the repository history (one diff per commit using pure-Go Myers diff via [go-git](https://github.com/go-git/go-git)) instead of just counting the current working tree. Runtime scales with `--depth` (the commit window size, default `1000`; `0` means entire history). On large repositories with deep history, expect runtimes measured in seconds to minutes rather than the millisecond-scale you get from a plain `scc` run. Use `--depth` to bound the window.849850When no report flag is set, `scc` behaves exactly as today, these flags are strictly opt-in.851852| Flag | Report | Answers |853|---|---|---|854| `--hotspots` | Hotspots | Which files are defect-prone - high complexity × high churn. |855| `--coupling` / `--coupling-for FILE` | Change coupling | Which files change together - hidden dependencies and blast radius. |856| `--by-author` | Author rollup | Bus factor - who last-touched the surviving code. |857| `--by-author --timeline` | Author timeline | How each author's activity rises and falls over time. |858| `--timeline` | Languages over time | How the language mix shifts - rewrites, migrations. |859860Shared flags for these reports:861862| Flag | Default | Purpose |863|---|---|---|864| `--depth N` | 1000 | Commit window size (newest N commits). `0` walks the entire history (slow on big repos). Negative values are rejected. |865| `--buckets N` | 60 | Time-bucket resolution for timeline reports. Must be `>= 1` when `--timeline` is set. CSV/JSON always emit full-resolution; tabular sparklines downsample to fit. |866| `-w, --wide` | - | 109-column variant of any report (extra columns where applicable). |867| `--no-fold-authors` | off | Disable the name + email-domain identity folding fallback applied after `.mailmap`. |868869Each report is standalone: `--hotspots`, `--coupling` (or `--coupling-for`), and `--by-author` / `--timeline` are mutually exclusive, and combining them is an error. `--coupling-for FILE` implies `--coupling`. With `--by-author` set, `--timeline` switches from the author rollup to the author timeline. Alone, `--timeline` renders the languages timeline.870871#### Hotspots - `--hotspots`872873Ranks files by defect-proneness: complexity × change frequency over the window. Surfaces *where to review*, not a defect probability.874875```text876$ scc --hotspots877───────────────────────────────────────────────────────────────────────────────878Hotspots · last 500 commits · 2024-01-09 → 2026-05-20879───────────────────────────────────────────────────────────────────────────────880File Lang Cmplx Commits Lines± Authrs Hotspot881───────────────────────────────────────────────────────────────────────────────882processor/workers.go Go 488 62 7,240 9 100.0883processor/processor.go Go 402 41 3,910 7 71.4884processor/formatters.go Go 233 38 2,980 6 51.8885main.go Go 180 44 2,510 8 48.2886───────────────────────────────────────────────────────────────────────────────887 complexity × change-frequency, normalised · 20 of 142 files shown888───────────────────────────────────────────────────────────────────────────────889```890891Tabular output shows the top files (≈20). `--wide` adds a hotspot bar and an added-lines code-vs-comment split (`+Code%`). `--format csv|json` emits every file with a positive score along with the full per-file detail and window metadata.892893#### Change coupling - `--coupling` / `--coupling-for`894895Which files tend to change together in the same commit I.E. *temporal* coupling.896Surfaces the "if you edit A you probably need to edit B" relationships. `Shared Commits` is how897many commits touched both files; `Coupling` is the share of commits touching *either* file that898touched *both*, so 100% means they never move apart. Pairs are ranked strongest first,899and only pairs sharing at least 2 commits are reported.900901```text902$ scc --coupling903───────────────────────────────────────────────────────────────────────────────904Change Coupling · last 1000 commits · 2019-07-24 → 2026-07-20905───────────────────────────────────────────────────────────────────────────────906File A File B Shared Commits Coupling907───────────────────────────────────────────────────────────────────────────────908languages.json processor/constants.go 196 67.6%909LANGUAGES.md languages.json 166 61.3%910LANGUAGES.md processor/constants.go 152 58.2%911main.go processor/processor.go 65 33.9%912───────────────────────────────────────────────────────────────────────────────913top 15 of 492 pairs · sharing ≥2 commits914───────────────────────────────────────────────────────────────────────────────915```916917`--coupling-for FILE` narrows to a single file's and what history says tends to move with it.918919```text920$ scc --coupling-for processor/workers.go921───────────────────────────────────────────────────────────────────────────────922Change Coupling · last 1000 commits · 2019-07-24 → 2026-07-20923───────────────────────────────────────────────────────────────────────────────924Related File Shared Commits Coupling925───────────────────────────────────────────────────────────────────────────────926processor/structs.go 27 25.2%927processor/workers_test.go 17 17.7%928processor/processor.go 34 15.7%929main.go 23 13.7%930───────────────────────────────────────────────────────────────────────────────931```932933#### Author rollup - `--by-author`934935Bus factor and last-toucher attribution. Lines untouched in the window collect under the sentinel `(before window)` so percentages reconcile to 100%.936937```text938$ scc --by-author939───────────────────────────────────────────────────────────────────────────────940Authors · last 500 commits · 2024-01-09 → 2026-05-20941───────────────────────────────────────────────────────────────────────────────942Author Code Cmplx Files Owns Last seen943───────────────────────────────────────────────────────────────────────────────944Alice Smith 24,110 4,180 118 38.6% 2026-05-22945Bob Jones 15,447 1,902 74 24.7% 2026-03-14946Carol Lee 9,205 3,640 51 14.7% 2026-05-19947(before window) 6,540 810 29 10.4% -948others (12) 1,300 190 - 2.1% -949───────────────────────────────────────────────────────────────────────────────950Bus factor 2 · Alice + Bob last-touched 63% of in-window code951───────────────────────────────────────────────────────────────────────────────952```953954Bus factor is the fewest authors whose combined share of *in-window* code exceeds 50%. The `(before window)` sentinel is excluded from that denominator so the footer reflects who could realistically pick up recent work, not who's stamped on long-frozen lines. The `Owns` column on each row still uses the share-of-all denominator (sentinel included; rows reconcile to 100%).955956Identity folding is layered: `.mailmap` is honoured first; then, by default, two commits sharing a lowercased name *and* an email domain collapse to one author (a fallback for repos without a mailmap). Generic names (`root`, `admin`, `unknown`, …) are excluded from the heuristic to avoid false merges. Disable the fallback with `--no-fold-authors` if you'd rather see every email as its own row. `--wide` adds a Comment column.957958#### Author timeline - `--by-author --timeline`959960How each author's activity rises and falls across the window. The Activity column is a Unicode sparkline normalised per row; the trailing tag is `quiet Nmo` (recently silent) or `↑` (currently near peak).961962```text963$ scc --by-author --timeline964───────────────────────────────────────────────────────────────────────────────965Authors · last 500 commits · 2024-01-09 → 2026-05-20966───────────────────────────────────────────────────────────────────────────────967Author Activity Commits Code±968───────────────────────────────────────────────────────────────────────────────969Alice Smith ▂▃▅▇█▇▆▅▄▄▃▃ 210 +38k970Bob Jones ▇█▆▄▂▁▁▁▁▁▁▁ 142 +21k quiet 2mo971Carol Lee ▁▁▁▁▂▃▄▅▆▇██ 96 +14k ↑972───────────────────────────────────────────────────────────────────────────────973```974975CSV is long format (one row per `(author, bucket)`); JSON includes per-author full-resolution series. Under `--ci` or non-TTY output the sparkline falls back to ASCII.976977#### Languages over time - `--timeline`978979How the language mix shifts: rewrites, migrations (e.g. JS → TS), gradual additions. The Trend sparkline plots each language's **absolute** trajectory, not deltas - so "rising" means "more code in this language now than at window-start".980981```text982$ scc --timeline983───────────────────────────────────────────────────────────────────────────────984Languages · last 500 commits · 2024-01-09 → 2026-05-20985───────────────────────────────────────────────────────────────────────────────986Language Trend Code Share Change987───────────────────────────────────────────────────────────────────────────────988TypeScript ▁▁▂▃▄▅▆▇████ 36,840 58.0% +36,840989Go ▃▃▄▄▅▅▅▆▆▆▆▆ 24,110 38.0% +9,205990JavaScript ██▇▆▅▄▃▂▁▁▁▁ 2,540 4.0% -18,300991Markdown ▂▃▃▄▄▅▅▆▆▆▇▇ 1,204 1.9% +994992───────────────────────────────────────────────────────────────────────────────993```994995Totals reconcile with a plain `scc` against the current HEAD tree. CSV/JSON include every non-empty language with the full per-bucket series.996997#### Output format and caveats998999- Tabular is for humans (sparklines, bars, ASCII fallback under `--ci`). CSV/JSON carry raw numbers only - no presentation glyphs - and include a `window` object (depth, commit count, date range) so downstream tools can reproduce the slice.1000- `.gitignore` is already applied by git when each commit was recorded; `.ignore` / `.sccignore` are honoured by the engine (disable with `--no-ignore` / `--no-scc-ignore`).1001- Merge commits are diffed against their first parent (`git log --first-parent` semantics).1002- Rename detection uses go-git's similarity heuristic; large renames may inflate hotspot churn and reset blame attribution. Shallow clones produce a clear error rather than a panic.1003- `Lines±` is the sum of added and removed lines, so files rewritten in place count twice the displaced size.1004- Symlinks are skipped (v1). Binary detection is unchanged.10051006### HTML Report10071008`scc --report` writes a self-contained, infographic-style HTML page summarising the codebase: overview metrics, language breakdown, line-length histogram, hotspots, change coupling, author rollup, language and author timelines, COCOMO / LOCOMO cost estimates, and a per-file table. The page bundles its own CSS and inline SVG — no external network requests, no JavaScript runtime dependencies — so it can be opened locally, committed to a repo, attached to a release, or hosted as a static artifact.10091010```text1011$ scc --report # writes scc-report.html (prompts before overwriting)1012$ scc --report=docs/code.html # explicit path; overwrites silently1013```10141015A bare `--report` is non-destructive: if `scc-report.html` already exists in the current directory, `scc` prompts before clobbering it. Naming the file explicitly (`--report=path/out.html`) is treated as consent and overwrites without asking.10161017| Flag | Purpose |1018|---|---|1019| `--report[=path]` | Write the HTML report. Bare flag writes `scc-report.html`; explicit path overwrites silently. |1020| `--report-title NAME` | Override the repo name shown in the report banner. Defaults to the `origin` remote name or the directory basename. |1021| `--report-skip LIST` | Comma-separated sections to omit: `cocomo`, `locomo`, `hotspots`, `authors`, `timeline`, `files`, `uloc`, `linelength`, `card`. |10221023The git-history sections (hotspots, coupling, authors, timelines) only render when the directory is a git repository; outside a repo they're omitted gracefully. The report embeds an OpenGraph share card as a `data:` URL so links unfurl on most social platforms — pass `--report-skip card` to drop it.10241025### Large File Detection10261027You can have `scc` exclude large files from the output.10281029The option to do so is `--no-large` which by default will exclude files over 1,000,000 bytes or 40,000 lines.10301031You can control the size of either value using `--large-byte-count` or `--large-line-count`.10321033For example to exclude files over 1,000 lines and 50kb you could use the following,10341035`scc --no-large --large-byte-count 50000 --large-line-count 1000`10361037### Minified/Generated File Detection10381039You can have `scc` identify and optionally remove files identified as being minified or generated from the output.10401041You can do so by enabling the `-z` flag like so `scc -z` which will identify any file with an average line byte size >= 255 (by default) as being minified.10421043Minified files appear like so in the output.10441045```text1046$ scc --no-cocomo -z ./examples/minified/jquery-3.1.1.min.js1047───────────────────────────────────────────────────────────────────────────────1048Language Files Lines Blanks Comments Code Complexity1049───────────────────────────────────────────────────────────────────────────────1050JavaScript (min) 1 4 0 1 3 171051───────────────────────────────────────────────────────────────────────────────1052Total 1 4 0 1 3 171053───────────────────────────────────────────────────────────────────────────────1054Processed 86709 bytes, 0.087 megabytes (SI)1055───────────────────────────────────────────────────────────────────────────────1056```10571058Minified files are indicated with the text `(min)` after the language name.10591060Generated files are indicated with the text `(gen)` after the language name.10611062You can control the average line byte size using `--min-gen-line-length` such as `scc -z --min-gen-line-length 1`. Please note you need `-z` as modifying this value does not imply minified detection.10631064You can exclude minified files from the count totally using the flag `--no-min-gen`. Files which match the minified check will be excluded from the output.10651066### Remapping10671068Some files may not have an extension. They will be checked to see if they are a #! file. If they are then the language will be remapped to the1069correct language. Otherwise, it will not process.10701071However, you may have the situation where you want to remap such files based on a string inside it. To do so you can use `--remap-unknown`10721073```bash1074 scc --remap-unknown "-*- C++ -*-":"C Header"1075```10761077The above will inspect any file with no extension looking for the string `-*- C++ -*-` and if found remap the file to be counted using the C Header rules.1078You can have multiple remap rules if required,10791080```bash1081 scc --remap-unknown "-*- C++ -*-":"C Header","other":"Java"1082```10831084There is also the `--remap-all` parameter which will remap all files.10851086Note that in all cases if the remap rule does not apply normal #! rules will apply.10871088### Counting files as a custom category10891090Sometimes you want to break out a subset of files into their own reporting category without changing how they are counted.1091A common example is test files such as Ruby specs (`*_spec.rb`) or JavaScript tests (`*.test.js`), which are still Ruby or1092JavaScript but which you would like to see called out separately.10931094The `--count-as-pattern` flag matches files by their path and counts them as a new named category, while borrowing the1095counting rules (comments, strings, complexity) of an existing base language. The format is `[engine:]pattern:name:baselang`.10961097**Patterns are globs by default**, so you usually do not need a prefix:10981099```bash1100 scc --count-as-pattern '*_spec.rb:Ruby Spec:Ruby'1101```11021103The above counts every file whose path matches the glob `*_spec.rb` as a new `Ruby Spec` category, counted using the Ruby1104rules. The original Ruby files are unaffected and remain in the `Ruby` row. Globs support `*` (any characters) and `?`1105(single character) and are matched as a full match against the path.11061107For more control you can opt into a regular expression with the `re:` prefix, which is matched anywhere in the path (use `^`1108and `$` to anchor it yourself). You can also write `glob:` explicitly if you prefer:11091110```bash1111 scc --count-as-pattern 're:\.test\.js$:JavaScript Tests:JavaScript'1112```11131114Glob and regex are kept as separate modes rather than being inferred, because the same pattern can be valid in both with1115different meaning (for example `foo.rb` matches only `foo.rb` as a glob, but also `fooXrb` as a regex), so guessing the engine1116could silently match the wrong files.11171118The flag is repeatable, with the first matching rule winning:11191120```bash1121 scc --count-as-pattern 'glob:*_spec.rb:Ruby Spec:Ruby' --count-as-pattern 'glob:*.test.js:JavaScript Tests:JavaScript'1122```11231124The pattern is matched against the path exactly as supplied to `scc`, with no normalisation, so on Windows you must account1125for the path separators yourself. A rule with an unknown base language, an invalid pattern, or missing fields is reported on1126stderr and skipped.11271128If you want to break a monorepo down by sub-project directory, run `scc` once per directory and combine the results yourself1129using the `csv`, `json`, or `sql` output formats.11301131### Output Formats11321133By default `scc` will output to the console. However, you can produce output in other formats if you require.11341135The different options are `tabular, wide, json, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics`.11361137Note that you can write `scc` output to disk using the `-o, --output` option. This allows you to specify a file to1138write your output to. For example `scc -f html -o output.html` will run `scc` against the current directory, and output1139the results in html to the file `output.html`.11401141You can also write to multiple output files, or multiple types to stdout if you want using the `--format-multi` option. This is1142most useful when working in CI/CD systems where you want HTML reports as an artifact while also displaying the counts in stdout.11431144```bash1145scc --format-multi "tabular:stdout,html:output.html,csv:output.csv"1146```11471148The above will run against the current directory, outputting to standard output the default output, as well as writing1149to output.html and output.csv with the appropriate formats.11501151#### Tabular11521153This is the default output format when scc is run.11541155#### Wide11561157Wide produces some additional information which is the complexity/lines metric. This can be useful when trying to1158identify the most complex file inside a project based on the complexity estimate.11591160#### JSON11611162JSON produces JSON output. Mostly designed to allow `scc` to feed into other programs.11631164Note that this format will give you the byte size of every file `scc` reads allowing you to get a breakdown of the1165number of bytes processed.11661167#### CSV11681169CSV as an option is good for importing into a spreadsheet for analysis.11701171Note that this format will give you the byte size of every file `scc` reads allowing you to get a breakdown of the1172number of bytes processed. Also note that CSV respects `--by-file` and as such will return a summary by default.11731174#### CSV-Stream11751176csv-stream is an option useful for processing very large repositories where you are likely to run into memory issues. It's output format is 100% the same as CSV.11771178Note that you should not use this with the `format-multi` option as it will always print to standard output, and because of how it works will negate the memory saving it normally gains.1179savings that this option provides. Note that there is no sort applied with this option.11801181#### cloc-yaml11821183Is a drop in replacement for cloc using its yaml output option. This is quite often used for passing into other1184build systems and can help with replacing cloc if required.11851186```text1187$ scc -f cloc-yml processor1188# https://github.com/boyter/scc/1189header:1190 url: https://github.com/boyter/scc/1191 version: 2.11.01192 elapsed_seconds: 0.0081193 n_files: 211194 n_lines: 65621195 files_per_second: 26251196 lines_per_second: 8202501197Go:1198 name: Go1199 code: 51861200 comment: 2731201 blank: 11031202 nFiles: 211203SUM:1204 code: 51861205 comment: 2731206 blank: 11031207 nFiles: 2112081209$ cloc --yaml processor1210 21 text files.1211 21 unique files.1212 0 files ignored.12131214---1215# http://cloc.sourceforge.net1216header :1217 cloc_url : http://cloc.sourceforge.net1218 cloc_version : 1.601219 elapsed_seconds : 0.1969728469848631220 n_files : 211221 n_lines : 65621222 files_per_second : 106.6136796084071223 lines_per_second : 33314.23645668411224Go:1225 nFiles: 211226 blank: 11371227 comment: 6061228 code: 48191229SUM:1230 blank: 11371231 code: 48191232 comment: 6061233 nFiles: 211234```12351236#### HTML and HTML-TABLE12371238The HTML output options produce a minimal html report using a table that is either standalone `html` or as just a table `html-table`1239which can be injected into your own HTML pages. The only difference between the two is that the `html` option includes1240html head and body tags with minimal styling.12411242The markup is designed to allow your own custom styles to be applied. An example report1243[is here to view](SCC-OUTPUT-REPORT.html).12441245Note that the HTML options follow the command line options, so you can use `scc --by-file -f html` to produce a report with every1246file and not just the summary.12471248Note that this format if it has the `--by-file` option will give you the byte size of every file `scc` reads allowing you to get a breakdown of the1249number of bytes processed.12501251#### SQL and SQL-Insert12521253The SQL output format "mostly" compatible with cloc's SQL output format <https://github.com/AlDanial/cloc#sql->12541255While all queries on the cloc documentation should work as expected, you will not be able to append output from `scc` and `cloc` into the same database. This is because the table format is slightly different1256to account for scc including complexity counts and bytes.12571258The difference between `sql` and `sql-insert` is that `sql` will include table creation while the latter will only have the insert commands.12591260Usage is 100% the same as any other `scc` command but sql output will always contain per file details. You can compute totals yourself using SQL, however COCOMO calculations will appear against the metadata table as the columns `estimated_cost` `estimated_schedule_months` and `estimated_people`.12611262The below will run scc against the current directory, name the output as the project scc and then pipe the output to sqlite to put into the database code.db12631264```bash1265scc --format sql --sql-project scc . | sqlite3 code.db1266```12671268Assuming you then wanted to append another project12691270```bash1271scc --format sql-insert --sql-project redis . | sqlite3 code.db1272```12731274You could then run SQL against the database,12751276```bash1277sqlite3 code.db 'select project,file,max(nCode) as nL from t1278 group by project order by nL desc;'1279```12801281See the cloc documentation for more examples.12821283#### OpenMetrics12841285[OpenMetrics](https://openmetrics.io/) is a metric reporting format specification extending the Prometheus exposition text format.12861287The produced output is natively supported by [Prometheus](https://prometheus.io/) and [GitLab CI](https://docs.gitlab.com/ee/ci/testing/metrics_reports.html)12881289Note that OpenMetrics respects `--by-file` and as such will return a summary by default.12901291The output includes a metadata header containing definitions of the returned metrics:12921293```text1294# TYPE scc_files count1295# HELP scc_files Number of sourcecode files.1296# TYPE scc_lines count1297# UNIT scc_lines lines1298# HELP scc_lines Number of lines.1299# TYPE scc_code count1300# HELP scc_code Number of lines of actual code.1301# TYPE scc_comments count1302# HELP scc_comments Number of comments.1303# TYPE scc_blanks count1304# HELP scc_blanks Number of blank lines.1305# TYPE scc_complexity count1306# HELP scc_complexity Code complexity.1307# TYPE scc_bytes count1308# UNIT scc_bytes bytes1309# HELP scc_bytes Size in bytes.1310```13111312The header is followed by the metric data in either language summary form:13131314```text1315scc_files{language="Go"} 11316scc_lines{language="Go"} 10001317scc_code{language="Go"} 10001318scc_comments{language="Go"} 10001319scc_blanks{language="Go"} 10001320scc_complexity{language="Go"} 10001321scc_bytes{language="Go"} 10001322```13231324or, if `--by-file` is present, in per file form:13251326```text1327scc_lines{language="Go",file="./bbbb.go"} 10001328scc_code{language="Go",file="./bbbb.go"} 10001329scc_comments{language="Go",file="./bbbb.go"} 10001330scc_blanks{language="Go",file="./bbbb.go"} 10001331scc_complexity{language="Go",file="./bbbb.go"} 10001332scc_bytes{language="Go",file="./bbbb.go"} 10001333```13341335### Performance13361337Generally `scc` will the fastest code counter compared to any I am aware of and have compared against. The below comparisons are taken from the fastest alternative counters. See `Other similar projects` above to see all of the other code counters compared against. It is designed to scale to as many CPU's cores as you can provide.13381339However, if you want greater performance and you have RAM to spare you can disable the garbage collector like the following on Linux `GOGC=-1 scc .` which should speed things up considerably. For some repositories turning off the code complexity calculation via `-c` can reduce runtime as well.13401341Benchmarks are run on fresh 32 Core CPU Optimised Vultr Ocean Virtual Machine 2026/03/05 all done using [hyperfine](https://github.com/sharkdp/hyperfine).13421343See <https://github.com/boyter/scc/blob/master/benchmark.sh> to see how the benchmarks are run.13441345#### Valkey <https://github.com/valkey-io/valkey>13461347```shell1348Benchmark 1: scc valkey1349 Time (mean ± σ): 27.7 ms ± 2.1 ms [User: 175.7 ms, System: 87.0 ms]1350 Range (min … max): 23.1 ms … 32.1 ms 96 runs1351 1352Benchmark 2: scc -c valkey1353 Time (mean ± σ): 23.0 ms ± 1.5 ms [User: 131.7 ms, System: 84.0 ms]1354 Range (min … max): 19.5 ms … 31.4 ms 130 runs1355 1356Benchmark 3: tokei valkey1357 Time (mean ± σ): 74.0 ms ± 13.0 ms [User: 394.2 ms, System: 245.1 ms]1358 Range (min … max): 49.1 ms … 92.5 ms 37 runs1359 1360Benchmark 4: polyglot valkey1361 Time (mean ± σ): 41.1 ms ± 1.2 ms [User: 54.2 ms, System: 103.3 ms]1362 Range (min … max): 37.5 ms … 47.0 ms 69 runs1363 1364Summary1365 scc -c valkey ran1366 1.20 ± 0.12 times faster than scc valkey1367 1.78 ± 0.13 times faster than polyglot valkey1368 3.21 ± 0.61 times faster than tokei valkey1369```13701371#### CPython <https://github.com/python/cpython>13721373```shell1374Benchmark 1: scc cpython1375 Time (mean ± σ): 80.8 ms ± 2.6 ms [User: 751.1 ms, System: 265.6 ms]1376 Range (min … max): 75.7 ms … 87.4 ms 36 runs1377 1378Benchmark 2: scc -c cpython1379 Time (mean ± σ): 70.5 ms ± 2.4 ms [User: 592.6 ms, System: 254.7 ms]1380 Range (min … max): 66.2 ms … 77.6 ms 40 runs1381 1382Benchmark 3: tokei cpython1383 Time (mean ± σ): 450.2 ms ± 36.1 ms [User: 1822.0 ms, System: 1246.9 ms]1384 Range (min … max): 378.6 ms … 491.2 ms 10 runs1385 1386Benchmark 4: polyglot cpython1387 Time (mean ± σ): 149.9 ms ± 5.8 ms [User: 199.2 ms, System: 326.2 ms]1388 Range (min … max): 138.3 ms … 164.1 ms 19 runs1389 1390Summary1391 scc -c cpython ran1392 1.15 ± 0.05 times faster than scc cpython1393 2.13 ± 0.11 times faster than polyglot cpython1394 6.39 ± 0.56 times faster than tokei cpython1395```13961397#### Linux Kernel <https://github.com/torvalds/linux>13981399```shell1400Benchmark 1: scc linux1401 Time (mean ± σ): 907.2 ms ± 17.1 ms [User: 13764.7 ms, System: 2957.0 ms]1402 Range (min … max): 878.2 ms … 925.0 ms 10 runs1403 1404Benchmark 2: scc -c linux1405 Time (mean ± σ): 842.5 ms ± 17.2 ms [User: 9363.3 ms, System: 2977.0 ms]1406 Range (min … max): 819.4 ms … 874.0 ms 10 runs1407 1408Benchmark 3: tokei linux1409 Time (mean ± σ): 1.422 s ± 0.089 s [User: 13.292 s, System: 9.582 s]1410 Range (min … max): 1.176 s … 1.471 s 10 runs1411 1412Benchmark 4: polyglot linux1413 Time (mean ± σ): 1.862 s ± 0.046 s [User: 3.802 s, System: 3.543 s]1414 Range (min … max): 1.800 s … 1.935 s 10 runs1415 1416Summary1417 scc -c linux ran1418 1.08 ± 0.03 times faster than scc linux1419 1.69 ± 0.11 times faster than tokei linux1420 2.21 ± 0.07 times faster than polyglot linux1421```14221423#### Sourcegraph <https://github.com/SINTEF/sourcegraph.git>14241425Sourcegraph has gone dark since I last ran these benchmarks hence using a clone taken before this occurred.1426The reason for this is to track what appears to be a performance regression in tokei.14271428```shell1429Benchmark 1: scc sourcegraph1430 Time (mean ± σ): 108.2 ms ± 3.5 ms [User: 559.4 ms, System: 323.6 ms]1431 Range (min … max): 100.5 ms … 115.9 ms 26 runs1432 1433Benchmark 2: scc -c sourcegraph1434 Time (mean ± σ): 99.7 ms ± 4.2 ms [User: 503.1 ms, System: 316.8 ms]1435 Range (min … max): 91.4 ms … 109.4 ms 29 runs1436 1437Benchmark 3: tokei sourcegraph1438 Time (mean ± σ): 21.359 s ± 1.025 s [User: 57.252 s, System: 411.480 s]1439 Range (min … max): 19.371 s … 22.741 s 10 runs1440 1441Benchmark 4: polyglot sourcegraph1442 Time (mean ± σ): 135.1 ms ± 5.0 ms [User: 198.6 ms, System: 543.7 ms]1443 Range (min … max): 126.0 ms … 144.8 ms 21 runs1444 1445Summary1446 scc -c sourcegraph ran1447 1.08 ± 0.06 times faster than scc sourcegraph1448 1.36 ± 0.08 times faster than polyglot sourcegraph1449 214.26 ± 13.64 times faster than tokei sourcegraph1450```14511452If you enable duplicate detection expect performance to fall by about 20% in `scc`.14531454Performance is tracked for some releases and presented below.14551456[]1457The decrease in performance from the 3.3.0 release was due to accurate .gitignore, .ignore and .gitmodule support.1458Current work is focussed on resolving this.14591460### CI/CD Support14611462Some CI/CD systems which will remain nameless do not work very well with the box-lines used by `scc`. To support those systems better there is an option `--ci` which will change the default output to ASCII only.14631464```text1465$ scc --ci main.go1466-------------------------------------------------------------------------------1467Language Files Lines Blanks Comments Code Complexity1468-------------------------------------------------------------------------------1469Go 1 272 7 6 259 41470-------------------------------------------------------------------------------1471Total 1 272 7 6 259 41472-------------------------------------------------------------------------------1473Estimated Cost to Develop $6,5391474Estimated Schedule Effort 2.268839 months1475Estimated People Required 0.3414371476-------------------------------------------------------------------------------1477Processed 5674 bytes, 0.006 megabytes (SI)1478-------------------------------------------------------------------------------1479```14801481The `--format-multi` option is especially useful in CI/CD where you want to get multiple output formats useful for storage or reporting.14821483### Development14841485If you want to hack away feel free! PR's are accepted. Some things to keep in mind. If you want to change a language definition you need to update `languages.json` and then run `go generate` which will convert it into the `processor/constants.go` file.14861487For all other changes ensure you run all tests before submitting. You can do so using `go test ./...`. However, for maximum coverage please run `test-all.sh` which will run `gofmt`, unit tests, race detector and then all of the integration tests. All of those must pass to ensure a stable release.14881489### API Support14901491The core part of `scc` which is the counting engine is exposed publicly to be integrated into other Go applications. See <https://github.com/pinpt/ripsrc> for an example of how to do this.14921493It also powers all of the code calculations displayed in <https://searchcode.com/> such as <https://searchcode.com/file/169350674/main.go/> making it one of the more used code counters in the world.14941495However as a quick start consider the following,14961497Note that you must pass in the number of bytes in the content in order to ensure it is counted!14981499```go1500package main15011502import (1503 "fmt"1504 "io/ioutil"15051506 "github.com/boyter/scc/v4/processor"1507)15081509type statsProcessor struct{}15101511func (p *statsProcessor) ProcessLine(job *processor.FileJob, currentLine int64, lineType processor.LineType) bool {1512 switch lineType {1513 case processor.LINE_BLANK:1514 fmt.Println(currentLine, "lineType", "BLANK")1515 case processor.LINE_CODE:1516 fmt.Println(currentLine, "lineType", "CODE")1517 case processor.LINE_COMMENT:1518 fmt.Println(currentLine, "lineType", "COMMENT")1519 }1520 return true1521}15221523func main() {1524 bts, _ := ioutil.ReadFile("somefile.go") 1525 t := &statsProcessor{}1526 filejob := &processor.FileJob{1527 Filename: "test.go",1528 Language: "Go",1529 Content: bts,1530 Callback: t,1531 Bytes: int64(len(bts)),1532 } 1533 processor.ProcessConstants() // Required to load the language information and need only be done once1534 processor.CountStats(filejob)1535}1536```15371538#### Per-Byte Content Classification15391540For library consumers who need finer granularity than per-line classification, `scc` supports opt-in per-byte content classification. When enabled, `CountStats` populates a byte slice classifying every byte in the file as code, comment, string, or blank. This is useful for stripping comments from source files, extracting only comments, or building syntax-aware tools without reimplementing language parsing.15411542To enable it, set `ClassifyContent: true` on the `FileJob` before calling `CountStats`. When disabled (the default), there is zero performance impact.15431544```go1545package main15461547import (1548 "fmt"1549 "os"15501551 "github.com/boyter/scc/v4/processor"1552)15531554func main() {1555 processor.ProcessConstants()15561557 bts, _ := os.ReadFile("main.go")1558 filejob := &processor.FileJob{1559 Filename: "main.go",1560 Language: "Go",1561 Content: bts,1562 Bytes: int64(len(bts)),1563 ClassifyContent: true, // Enable per-byte classification1564 }1565 processor.CountStats(filejob)15661567 // ContentByteType has one entry per byte with values:1568 // processor.ByteTypeBlank (0) - blank lines / leading whitespace1569 // processor.ByteTypeCode (1) - code1570 // processor.ByteTypeComment (2) - comments (including docstrings)1571 // processor.ByteTypeString (3) - string literals15721573 // Example: extract only code, replacing everything else with spaces1574 codeOnly := filejob.FilterContentByType(processor.ByteTypeCode)1575 fmt.Println(string(codeOnly))15761577 // Example: extract only comments1578 commentsOnly := filejob.FilterContentByType(processor.ByteTypeComment)1579 fmt.Println(string(commentsOnly))15801581 // Example: keep both code and strings, strip comments1582 noComments := filejob.FilterContentByType(processor.ByteTypeCode, processor.ByteTypeString)1583 fmt.Println(string(noComments))1584}1585```15861587`FilterContentByType` returns a copy of the content with non-matching bytes replaced by spaces. Newlines are always preserved regardless of type, so the output maintains the same line structure as the original file. It returns `nil` if classification was not enabled.15881589Note that at syntax marker boundaries (e.g., `//`, `/*`, `"`), the first byte of the marker may be classified as the preceding state. This is a 1-byte approximation that is acceptable for content filtering use cases.15901591### MCP Server Mode15921593`scc` can run as an [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server over stdio, allowing LLM tools like Claude Desktop, Claude Code, Cursor, and others to use it as a code analysis tool.15941595```shell1596scc --mcp1597```15981599#### Claude Code Configuration16001601Run in your terminal for the current project:16021603```shell1604claude mcp add scc -- scc --mcp1605```16061607Or globally for all projects:16081609```shell1610claude mcp add scc --scope user -- scc --mcp1611```16121613Alternatively, add to your `.mcp.json`:16141615```json1616{1617 "mcpServers": {1618 "scc": {1619 "command": "scc",1620 "args": ["--mcp"]1621 }1622 }1623}1624```16251626#### Claude Desktop Configuration16271628Add to your `claude_desktop_config.json`:16291630```json1631{1632 "mcpServers": {1633 "scc": {1634 "command": "/path/to/scc",1635 "args": ["--mcp"]1636 }1637 }1638}1639```16401641#### Exposed Tools16421643The MCP server exposes three tools:16441645**`analyze`** - Count lines of code, comments, blanks and estimate complexity for a project directory or file.16461647| Parameter | Type | Required | Description |1648|---|---|---|---|1649| `path` | string | no | Directory or file path to analyze. Defaults to current directory. |1650| `sort` | string | no | Column to sort by: `files`, `name`, `lines`, `blanks`, `code`, `comments`, `complexity`, `bytes`. Default: `files`. |1651| `by_file` | boolean | no | If true, return per-file results instead of per-language summary. |1652| `include_ext` | string | no | Comma-separated file extensions to include (e.g. `go,java,js`). |1653| `exclude_ext` | string | no | Comma-separated file extensions to exclude (e.g. `json,xml`). |1654| `no_duplicates` | boolean | no | Remove duplicate files from stats. |1655| `no_min_gen` | boolean | no | Ignore minified or generated files. |1656| `locomo` | boolean | no | Include LOCOMO (LLM cost) estimation in results. |1657| `locomo_preset` | string | no | LOCOMO model preset: `large`, `medium`, `small`, `local`. Default: `medium`. |16581659Results are returned as JSON with per-language breakdown (files, lines, code, comments, blanks, complexity, bytes), totals, and COCOMO cost/schedule estimates. When `locomo` is enabled, LOCOMO estimates (token counts, cost, generation time, review hours) are also included.16601661**`hotspots`** - Rank the files in a git repository by hotspot score (complexity × change-frequency over recent history), surfacing the files most likely to need refactoring or close review.16621663| Parameter | Type | Required | Description |1664|---|---|---|---|1665| `path` | string | no | Directory inside the git repository to analyze. Defaults to current directory. |1666| `depth` | number | no | Maximum number of recent commits to walk. Default: `1000`. Set to `0` for unlimited. |1667| `limit` | number | no | Maximum number of files to return, highest-scoring first. Default: `50`. Set to `-1` for unlimited. |16681669Results are returned as JSON with the history window walked (depth, commit count, date range) and a per-file list (file, language, complexity, commits, lines changed, authors, code/comment churn, and a normalised 0–100 score). Requires `path` to be inside a git repository.16701671**`coupling`** - Report change coupling from a git repository's history: files that historically change together. Has two modes, selected by whether `file` is set. With `file`, returns that file's blast radius - the other files that change together with it. Without `file`, returns the repo-wide all-pairs overview.16721673| Parameter | Type | Required | Description |1674|---|---|---|---|1675| `path` | string | no | Directory inside the git repository to analyze. Defaults to current directory. |1676| `file` | string | no | Target file (as it appears at HEAD). Set it for the per-file blast-radius view; omit it for the repo-wide all-pairs report. |1677| `depth` | number | no | Maximum number of recent commits to walk. Default: `1000`. Set to `0` for unlimited. |1678| `limit` | number | no | Maximum rows to return, strongest first - coupled files in per-file mode, file pairs in all-pairs mode. Default: `50`. Set to `-1` for unlimited. |16791680Results are returned as JSON with the history window walked. With `file`, each partner carries its shared-commit count and the directional probabilities `couple` (given you changed the target, how often the partner follows) and `reverse` (the other direction). Without `file`, each pair carries its shared-commit count and symmetric coupling degree. Requires `path` to be inside a git repository.16811682### Adding/Modifying Languages16831684To add or modify a language you will need to edit the `languages.json` file in the root of the project, and then run `go generate` to build it into the application. You can then `go install` or `go build` as normal to produce the binary with your modifications.16851686### Issues16871688Its possible that you may see the counts vary between runs. This usually means one of two things. Either something is changing or locking the files under scc, or that you are hitting ulimit restrictions. To change the ulimit see the following links.16891690- <https://superuser.com/questions/261023/how-to-change-default-ulimit-values-in-mac-os-x-10-6#306555>1691- <https://unix.stackexchange.com/questions/108174/how-to-persistently-control-maximum-system-resource-consumption-on-mac/221988#221988>1692- <https://access.redhat.com/solutions/61334>1693- <https://serverfault.com/questions/356962/where-are-the-default-ulimit-values-set-linux-centos>1694- <https://www.tecmint.com/increase-set-open-file-limits-in-linux/>16951696To help identify this issue run scc like so `scc -v .` and look for the message `too many open files` in the output. If it is there you can rectify it by setting your ulimit to a higher value.16971698### Low Memory16991700If you are running `scc` in a low memory environment < 512 MB of RAM you may need to set `--file-gc-count` to a lower value such as `0` to force the garbage collector to be on at all times.17011702A sign that this is required will be `scc` crashing with panic errors.17031704### Tests17051706scc is pretty well tested with many unit, integration and benchmarks to ensure that it is fast and complete.17071708### Package17091710Packaging as of version v3.1.0 is done through <https://goreleaser.com/>17111712### Containers17131714Note if you plan to run `scc` in Alpine containers you will need to build with CGO_ENABLED=0.17151716See the below Dockerfile as an example on how to achieve this based on this issue <https://github.com/boyter/scc/issues/208>17171718```Dockerfile1719FROM golang as scc-get17201721ENV GOOS=linux \1722GOARCH=amd64 \1723CGO_ENABLED=017241725ARG VERSION1726RUN git clone --branch $VERSION --depth 1 https://github.com/boyter/scc1727WORKDIR /go/scc1728RUN go build -ldflags="-s -w"17291730FROM alpine1731COPY --from=scc-get /go/scc/scc /bin/1732ENTRYPOINT ["scc"]1733```17341735### Badges17361737You can use `scc` to provide badges on your github/bitbucket/gitlab/sr.ht/codeberg open repositories. For example, [](https://github.com/boyter/scc/)1738 The format to do so is,17391740<https://sloc.xyz/PROVIDER/USER/REPO>17411742An example of the badge for `scc` is included below, and is used on this page.17431744```Markdown1745[](https://github.com/boyter/scc/)1746```17471748By default the badge will show the repo's lines count. You can also specify for it to show a different category, by using the `?category=` query string.17491750Valid values include `code, blanks, lines, comments, cocomo, effort` and examples of the appearance are included below.17511752[](https://github.com/boyter/scc/)1753[](https://github.com/boyter/scc/)1754[](https://github.com/boyter/scc/)1755[](https://github.com/boyter/scc/)1756[](https://github.com/boyter/scc/)1757[](https://github.com/boyter/scc/)17581759For `cocomo` you can also set the `avg-wage` value similar to `scc` itself. For example,17601761<https://sloc.xyz/github/boyter/scc/?category=cocomo&avg-wage=1>1762<https://sloc.xyz/github/boyter/scc/?category=cocomo&avg-wage=100000>17631764Note that the avg-wage value must be a positive integer otherwise it will revert back to the default value of 56286.17651766You can also configure the look and feel of the badge using the following parameters,17671768- ?lower=true will lower the title text, so "Total lines" would be "total lines"17691770The below can control the colours of shadows, fonts and badges. Colors can be specified as either hex codes or named colors (similar to shields.io):17711772- ?font-color=fff1773- ?font-shadow-color=0101011774- ?top-shadow-accent-color=bbb1775- ?title-bg-color=5551776- ?badge-bg-color=4c117771778##### Named Colors17791780For convenience, you can use named colors instead of hex codes. The following named colors are supported:17811782**Shields.io colors:** `brightgreen`, `green`, `yellowgreen`, `yellow`, `orange`, `red`, `blue`, `lightgrey`, `blueviolet`17831784**Semantic aliases:** `success`, `important`, `critical`, `informational`, `inactive`17851786**CSS colors:** `white`, `black`, `silver`, `gray`, `maroon`, `purple`, `fuchsia`, `lime`, `olive`, `navy`, `teal`, `aqua`, `cyan`, `magenta`, `pink`, `coral`, `salmon`, `gold`, `khaki`, `violet`, `indigo`, `crimson`, `turquoise`, `tan`, `brown`, and many more standard CSS color names.17871788For example, instead of `?badge-bg-color=007ec6` you can use `?badge-bg-color=blue`.17891790An example of using some of these parameters to produce an admittedly ugly result17911792[](https://github.com/boyter/scc/)17931794An example using named colors for as a slightly nicer result17951796[](https://github.com/boyter/scc/)17971798*NB* it may not work for VERY large repositories (has been tested on Apache hadoop/spark without issue).17991800You can find the source code for badges in the repository at <https://github.com/boyter/scc/blob/master/cmd/badges/main.go>18011802#### A example for each supported provider18031804- Github - <https://sloc.xyz/github/boyter/scc/>1805- sr.ht - <https://sloc.xyz/sr.ht/~nektro/magnolia-desktop/>1806- Bitbucket - <https://sloc.xyz/bitbucket/boyter/decodingcaptchas>1807- Gitlab - <https://sloc.xyz/gitlab/esr/loccount>1808- Codeberg - <https://sloc.xyz/codeberg/NextBroomTeam/NextBroom>18091810### Languages18111812List of supported languages. The master version of `scc` supports 322 languages at last count. Note that this is always assumed that you built from master, and it might trail behind what is actually supported. To see what your version of `scc` supports run `scc --languages`18131814[Click here to view all languages supported by master](LANGUAGES.md)18151816### Citation18171818Please use the following Bib**La**TeX entry to cite scc in a publication:18191820```bib1821@Software{scc,1822 author = {Ben Boyter and {Contributors}},1823 title = {scc},1824 version = {vx.y.z},1825 year = {...},1826 month = {...},1827 repository = {https://github.com/boyter/scc},1828}1829```18301831You may need to check the release page <https://github.com/boyter/scc/releases> to find the correct year and month for the release you are using.18321833### Release Checklist18341835- Update version1836- Push code with release number1837- Tag off1838- Release via goreleaser1839- Update dockerfile
Findings
✓ No findings reported for this file.