Skip to content

How to analyze a monorepo

Goal

Run Codefang against a single large repository that holds many languages and services, and get a clean per-service report without drowning in vendored or generated noise.

Prerequisites

  • codefang and uast installed. See Installation.
  • A monorepo checked out locally, with full Git history (history analyzers need every commit, not a shallow clone).
  • jq if you want to post-process the JSON output.

Steps

  1. Run static analysis across the whole tree first. By default Codefang already excludes vendored dependencies (vendor/, node_modules/, third_party/, testdata/) and generated files, so the report covers your own code only:
codefang run -a 'static/*' --format json --silent .
  1. Narrow a noisy polyglot repo to the languages you care about. The --languages filter applies to both the static and history phases and skips non-matching files before they are parsed:
codefang run -a 'static/*' --languages go,typescript,python --format json .
  1. Scope a run to a single service directory instead of the whole repo by passing its path (or --path):
codefang run -a 'static/complexity,static/cohesion' --format json ./services/api
  1. Add extra exclusion prefixes for tooling directories that Linguist's heuristics do not catch, such as a Python virtualenv or a Rust target dir:
codefang run -a '*' --extra-excluded-prefixes '.venv/,target/,build/' --format json .
  1. Constrain memory on a large monorepo so the streaming pipeline auto-tunes worker count and spill thresholds rather than consuming all available RAM:
codefang run -a 'history/*' --memory-budget 4GB --workers 4 --format json --silent .
  1. If you need only a subset of the history, limit the commit range with --since or --limit to keep the run bounded:
codefang run -a 'history/devs' --since 2025-01-01 --format json .

Result

You have a JSON report scoped to your own source code (vendored and generated files excluded) and, when you narrow by --languages or path, scoped to the service you care about. Confirm the scope by inspecting the report — for example, count the files Codefang actually analyzed:

codefang run -a 'static/complexity' --languages go --format json . | jq '.["static/complexity"] | length'

See also