scc (Sloc Cloc and Code)

repository·master·Indexed 27 days ago

https://github.com/boyter/scc

A high-performance code intelligence tool for counting lines of code (SLOC), blank lines, and comment lines across many programming languages. scc provides advanced metrics including code complexity, COCOMO and LOCOMO (LLM-based) cost estimations, and git history analysis for hotspots, coupling, and timelines. It supports multiple output formats such as JSON, CSV, and HTML reports, and can be configured via .sccconfig files or environment variables.

Tokens
11.8K
Snippets
37
Records
74
Agent score
91%

What's inside scc

  1. Overview of Sloc Cloc and Code (scc)

    master

    scc is a high-performance tool designed for counting lines of code (SLOC), blank lines, comment lines, and physical lines of source code across many programming languages. It is intended to be a faster alternative to cloc, sloccount, and tokei.

    Beyond simple counting, scc provides:

    • COCOMO calculations (similar to sloccount)
    • LOCOMO estimation for LLM-based development costs
    • Code complexity estimation
    • Unique lines of code and DRYness metrics
  2. Configure Claude Desktop with scc MCP

    master

    To add scc to Claude Desktop, add the following entry to your claude_desktop_config.json file. Ensure you provide the absolute path to the scc binary.

    {
      "mcpServers": {
        "scc": {
          "command": "/path/to/scc",
          "args": ["--mcp"]
        }
      }
    }
  3. Configure Claude Code with scc MCP

    master

    To add scc as an MCP server to Claude Code, use the following commands:

    For the current project:

    claude mcp add scc -- scc --mcp

    Globally for all projects:

    claude mcp add scc --scope user -- scc --mcp

    Via .mcp.json: Add the following configuration to your .mcp.json file:

    {
      "mcpServers": {
        "scc": {
          "command": "scc",
          "args": ["--mcp"]
        }
      }
    }
  4. Understand complexity estimation in scc

    master

    scc provides a complexity estimate by scanning for branching and loop operations (e.g., for, if, switch, while, else, ||, &&, !=, ==).

    Key considerations:

    • The estimate is an approximation of cyclomatic complexity performed at the file level without building a full AST.
    • It is best used to compare files or projects within the same language.
    • It may not identify complexity from recursive methods since it does not parse the code structure.

    You can find the most complex files in a project using the --by-file flag with the -s complexity sort option.

    scc --by-file -s complexity
  5. Run Git Insight Reports

    master

    scc can generate five git-aware reports based on commit history. These reports are opt-in and are slower than standard runs because they walk the repository history.

    Available Reports:

    • --hotspots: Ranks files by defect-proneness (complexity × churn).
    • --coupling or --coupling-for FILE: Identifies files that change together (temporal coupling).
    • --by-author: Shows author rollup (bus factor).
    • --by-author --timeline: Shows author activity over time.
    • --timeline: Shows how language mix shifts over time.

    Note: Report flags are mutually exclusive. Combining them is an error.

  6. Build scc for Alpine containers

    master

    If you plan to run scc in Alpine-based containers, you must build it with CGO_ENABLED=0 to ensure compatibility. Use the following Dockerfile pattern:

    FROM golang as scc-get
    
    ENV GOOS=linux \
    GOARCH=amd64 \
    CGO_ENABLED=0
    
    ARG VERSION
    RUN git clone --branch $VERSION --depth 1 https://github.com/boyter/scc
    WORKDIR /go/scc
    RUN go build -ldflags="-s -w"
    
    FROM alpine
    COPY --from=scc-get /go/scc/scc /bin/
    ENTRYPOINT ["scc"]
  7. Calculate Unique Lines of Code (ULOC) and DRYness

    master

    ULOC (Unique Lines of Code) represents the unique lines across languages, files, and the project. It helps estimate project complexity by discounting repetitive code like license headers and close-brace lines while including comments.

    Metrics:

    • ULOC: Total unique lines.
    • DRYness %: The ratio of ULOC / SLOC. A higher value indicates a more 'DRY' (Don't Repeat Yourself) project with less duplication.

    Usage:

    • Use -u or --uloc to show ULOC.
    • Use -a or --dryness to show the DRYness percentage (this implicitly enables --uloc).

    Note: Calculating ULOC metrics may double the runtime due to the performance penalty.

    scc -a -i c redis
  8. Configure file ignoring with .ignore and .sccignore

    master

    scc supports .ignore files (which use the same syntax as .gitignore) and its own .sccignore files located within scanned directories. These files allow you to exclude specific files or directories from the count.

    You can also provide external ignore files using the --ignore-file flag. This flag can be repeated. Note that patterns in --ignore-file are anchored at the scan root. Files discovered inside the scanned tree take precedence over those provided via --ignore-file.

    scc --ignore-file ~/.gitignore --ignore-file ./.dockerignore
  9. Configure scc repository badges

    master

    You can display scc statistics as badges on GitHub, Bitbucket, GitLab, etc., using the format: https://sloc.xyz/PROVIDER/USER/REPO.

    Customization Options:

    • ?category=: Choose what to display. Valid values: code, blanks, lines, comments, cocomo, effort.
    • ?avg-wage=: (For cocomo category) Set a positive integer for average wage. Default is 56286.
    • ?lower=true: Lowercase the title text.
    • Colors: Use hex codes (e.g., ?font-color=fff) or named colors (e.g., ?badge-bg-color=blue).

    Supported Named Colors:

    • Shields.io: brightgreen, green, yellowgreen, yellow, orange, red, blue, lightgrey, blueviolet.
    • Semantic: success, important, critical, informational, inactive.
    • CSS: 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.
  10. Run scc in Docker

    master

    To run the latest release of scc on your current working directory using Docker, navigate to the target directory and execute the following command:

    docker run --rm -it -v "$PWD:/pwd:ro" --network none ghcr.io/boyter/scc:master scc /pwd
  11. Estimate LLM development costs with LOCOMO

    master

    LOCOMO is an estimation model within scc that predicts the cost and time required for LLM-assisted development based on SLOC and code complexity. It calculates output tokens, input tokens (scaled by complexity), iteration factors (retries), dollar costs, generation time, and human review time.

    To use LOCOMO, enable it with the --locomo flag. You can select model tiers using --locomo-preset to automatically configure pricing and throughput.

    scc --locomo --locomo-preset large .
    scc --locomo --locomo-preset local .