Skip to content

CLI Reference

All commands accept these options:

FlagDefaultDescription
-p, --project <path>.Project root directory
-d, --db <path>.code-bearings/bearings.dbDatabase path

Index a TypeScript project and build the code graph.

Terminal window
code-bearings analyze [options]
FlagDescription
-t, --tsconfig <path>Path to tsconfig.json (auto-detected if omitted)

The indexer uses ts-morph to parse your project’s AST. It extracts:

  • Files — path, line count
  • Symbols — functions, classes, interfaces, types, variables, enums, constants
  • Edges — imports, calls, called_by, references, implements, extends, reads, writes, exposes, verified_by
  • Tests — test records linked to the symbols they exercise
  • Entrypoints — exports, CLI entry points, API routes, jobs, event handlers
  • Modules — boundary detection using a priority chain: override, package, barrel, directory, file

Generate a change brief from a git diff.

Terminal window
code-bearings review [target] [options]
FlagDescription
--stagedReview staged changes only
--stdinRead diff from stdin
--jsonOutput as JSON
--format <mode>Output format: full, compact, markdown, html
--mode <lens>Purpose mode: general, bug-hunter, learning, architecture, exploration
-o, --output <path>Write output to file

Examples:

Terminal window
code-bearings review # staged + unstaged vs HEAD
code-bearings review --staged # staged only
code-bearings review HEAD~1..HEAD # last commit
code-bearings review main..feature # branch comparison
git diff main | code-bearings review --stdin # piped diff

Compare two branches or commits.

Terminal window
code-bearings compare [base] [head] [options]

Auto-detects the base branch (main, master, or develop) if not specified.

Terminal window
code-bearings compare # current vs auto-detected base
code-bearings compare main # current vs main
code-bearings compare main feature # explicit base and head
code-bearings compare HEAD~5 HEAD # last 5 commits

Show the module card for a named module.

Terminal window
code-bearings module <name> [options]
FlagDescription
--jsonOutput as JSON

Includes: public surface, internal structure, dependencies, reverse dependencies, metrics, and evidence.

Show the function card for a named function.

Terminal window
code-bearings function <name> [options]
FlagDescription
-f, --file <path>Filter by file path
--jsonOutput as JSON

Show the system map overview.

Terminal window
code-bearings overview [options]
FlagDescription
--jsonOutput as JSON

List all indexed modules with their metrics.

Terminal window
code-bearings modules [options]

Generate review artifacts for CI/CD pipelines.

Terminal window
code-bearings ci [options]
FlagDefaultDescription
--base <ref>auto-detectBase branch or commit
--head <ref>HEADHead commit
--out <dir>.code-bearings/ciOutput directory
--fail-on-risk <level>Exit non-zero if risk exceeds: high, medium, low

Risk thresholds:

LevelScore
low>= 5
medium>= 15
high>= 30

Output files:

  • change-brief.md — full Markdown report
  • change-brief.json — machine-readable JSON
  • change-brief.html — interactive HTML report
  • change-brief-compact.txt — one-line-per-module summary
CodeMeaning
0Success
1Error (missing database, failed diff, risk threshold exceeded)