MCPcopy Index your code
hub / github.com/LegacyCodeHQ/clarity-cli

github.com/LegacyCodeHQ/clarity-cli @v0.28.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.28.1 ↗ · + Follow
2,096 symbols 7,779 edges 265 files 574 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Clarity

Built with Clarity License Release npm version Go Report Card

See the structure of a code change before you commit it.

Clarity builds dependency impact graphs from source code. It shows how files, modules, tests, and documentation connect so developers and coding agents can reason about design changes with evidence instead of intuition.

Use it when you want to know:

  • What does this change touch?
  • Who depends on this file?
  • Why are these two areas connected?
  • Did this refactor cross a boundary?
  • Did we introduce a cycle?
  • What does this branch look like structurally?

Clarity works at file granularity. It recovers coupling shape, not runtime behavior or full API contracts.

Quick Start

Install with npm:

npm install -g @legacycodehq/clarity

Or on macOS/Linux with Homebrew:

brew install LegacyCodeHQ/tap/clarity

Keep a live graph open while you code:

clarity watch

Show the structural impact of your uncommitted work:

clarity show

Find what depends on a file before changing it:

clarity show path/to/file.go --reach up

Review the structural footprint of a branch:

clarity show -c main...HEAD

The Model

Every graph answers four questions.

Question Meaning Examples
Which snapshot? working tree, commit, or range clarity show, -c HEAD, -c main...HEAD
What anchor? changed files, paths, modules, whole tree, paths between files src/auth, --module auth, --all, --between a,b
What lens? how much context or abstraction to apply --reach up, --reach down, --depth 2, --collapse
What rendering? how to output the graph DOT, Mermaid, browser URL, live UI

This makes Clarity useful for both quick local checks and repeatable agent workflows.

Core Use Cases

Review a Change Before Commit

clarity show

Shows the dependency graph around your uncommitted work.

Use it to check:

  • whether the change stayed inside the intended area
  • which neighboring files are affected
  • whether tests are connected to the changed code
  • whether new coupling appeared

Review a Commit, Branch, or PR

clarity show -c HEAD
clarity show -c main...HEAD

Use commit and range snapshots to review structural impact after the fact. This is useful for pull requests, regression windows, release reviews, and agent-generated changes.

Refactor Safely

clarity show path/to/file.go --reach up
clarity show path/to/file.go --reach both --depth 2

Use upstream reach to answer "who imports this?" before changing a file. Use bounded reach to estimate blast radius.

Understand a Codebase

clarity show src/auth
clarity show src/auth --reach both
clarity show --all --collapse

Use scoped graphs to explore unfamiliar code. Collapse configured modules when the file-level graph is too noisy.

Trace Unexpected Coupling

clarity show --between ui/login.ts,server/session.go

Shows the dependency paths connecting two files. Use this when you need to explain why two areas are coupled or decide where to cut a dependency.

Audit Module Boundaries

clarity modules
clarity show --module auth --reach both
clarity show --all --collapse

Declare modules in .clarity/modules.json, inspect a module in context, or collapse modules into architecture-level nodes.

Find Circular Dependencies

clarity cycles src
clarity cycles src --url

Lists circular dependencies within a scope and can produce focused visualizations for each cycle.

Keep Feedback Live While Coding

clarity watch
clarity watch src/auth --reach both

Runs a local live graph that updates as files change. Use it during refactors or large agent edits to keep structural feedback visible.

Support Coding Agents

clarity setup

Adds repository instructions so coding agents can use Clarity as part of their normal loop.

Good agent patterns:

  • inspect dependents before refactoring with --reach up
  • run clarity show -f mermaid after edits
  • generate clarity show -u for a shareable review artifact
  • use the graph to catch unexpected coupling before commit

Output

clarity show -f dot
clarity show -f mermaid
clarity show -u

DOT is the default. Mermaid works well in docs, IDEs, and agent UIs. -u creates a browser-friendly visualization URL.

Language Support

Clarity supports dependency extraction for:

  • C, C++, C#
  • Dart
  • Go
  • Java, Kotlin, Scala
  • JavaScript, TypeScript, Svelte
  • Markdown
  • Python, Ruby
  • Rust
  • Swift
  • Zig

Support quality varies by language. Run:

clarity languages

to see the current maturity and extension list.

Experimental Surfaces

clarity cycles
clarity workspace

cycles reports circular file dependencies.

workspace builds Go module and Rust crate relationship graphs.

These surfaces are useful, but their output may change.

What Clarity Is Not

Clarity is not a replacement for tests, type checks, linters, or code review.

It does not provide:

  • full symbol-level call graphs
  • runtime behavior analysis
  • API contract verification
  • semantic correctness guarantees

It is a structural verification tool: it shows coupling, impact, boundaries, cycles, and change shape.

License

This project is licensed under the GNU Affero General Public License v3.0.

Copyright (c) 2026-present, Legacy Code Headquarters (OPC) Private Limited. All rights reserved.

Extension points exported contracts — how you extend this code

Provider (Interface)
Provider describes pluggable language support. [18 implementers]
depgraph/moduleapi/provider.go
PythonImport (Interface)
PythonImport represents an import in a Python file. [8 implementers]
depgraph/languages/python/parser_python.go
DependencyResolver (Interface)
DependencyResolver resolves project imports per file and can finalize graph-wide dependencies. [2 implementers]
depgraph/dependency_resolver.go
Renderer (Interface)
Renderer translates a Scene's primitives into a concrete output syntax (DOT, Mermaid, ...). It is the contract that keep [2 …
cmd/show/formatters/renderer.go
ContentReader (FuncType)
ContentReader is a function that reads file content given a file path. This allows the caller to control how files are r
vcs/content_reader.go
RepoDescriptor (Interface)
(no doc)
cmd/watch/web/src/lib/protocol/viewerProtocol.ts
Resolver (Interface)
Resolver resolves project imports for one language and can finalize graph-wide state. [20 implementers]
depgraph/moduleapi/resolver.go
GoImport (Interface)
GoImport represents an import in a Go file [22 implementers]
depgraph/languages/golang/parser_golang.go

Core symbols most depended-on inside this repo

gitAdd
called by 115
vcs/git/git_test_helpers.go
Name
called by 107
depgraph/moduleapi/provider.go
createFile
called by 100
vcs/git/git_test_helpers.go
setupGitRepo
called by 86
vcs/git/git_test_helpers.go
String
called by 81
cmd/show/path_resolver.go
FilesystemContentReader
called by 77
vcs/content_reader.go
gitCommitAndGetSHA
called by 62
vcs/git/git_test_helpers.go
add
called by 39
depgraph/languages/javascript/testdata/sample.mjs

Shape

Function 1,603
Method 304
Struct 136
Interface 25
TypeAlias 14
Class 10
Enum 2
FuncType 2

Languages

Go95%
TypeScript3%
C++1%
C1%
Java1%

Modules by API surface

cmd/show/show_cmd.go55 symbols
cmd/watch/watch_cmd_test.go54 symbols
cmd/show/show_cmd_test.go54 symbols
vcs/git/git_diff_test.go38 symbols
depgraph/languages/java/parser_java.go37 symbols
depgraph/languages/kotlin/parser_kotlin.go36 symbols
vcs/git/git_test.go35 symbols
depgraph/languages/typescript/parser_typescript_test.go34 symbols
depgraph/languages/scala/parser_scala.go34 symbols
depgraph/languages/rust/parser_rust.go34 symbols
depgraph/languages/rust/dependency_resolver_rust.go34 symbols
cmd/show/formatters/formatter_mermaid_test.go31 symbols

For agents

$ claude mcp add clarity-cli \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact