Evidence-backed graph indexing for technical collections.
codegraph builds a durable graph from source code, documentation, research
folders, configuration, logs, and mixed technical collections. It is designed to
give both humans and AI agents a strong first map of a target without writing
artifacts into that target by default.
It is not a wrapper around another graph tool, not tied to TypeScript, and not limited to software repositories.
codegraph optimizes for trustworthy orientation, not decorative diagrams.
- Every scan requires an explicit output directory.
- The target repository or collection is read-only by default.
- Generated output is written outside the target unless explicitly allowed.
- Freshness is inspectable before a graph is trusted.
- Every meaningful non-containment edge should have evidence.
- Incomplete extraction is reported as
partialoruntrusted, not hidden. - Obsidian is a human export layer;
graph.jsonandmanifest.jsonare the canonical machine artifacts.
Each scan writes:
graph.json: canonical nodes, edges, evidence, confidence, and provenance.manifest.json: scan options, ignore policy, fingerprints, freshness, and quality gates.report.md: human-readable quality summary..ready: marker written only after the graph is fully generated.obsidian/: optional human navigation export when--export-obsidianis passed.
Optional project behavior can be configured with codegraph.toml in the target
root or with --config <path>.
From this repository:
python3 -m pip install -e .Or run without installing:
PYTHONPATH=src python3 -m codegraph --helpCreate a new graph. --out is required and should normally point outside the
target.
codegraph scan /path/to/target --out /path/to/output --export-obsidianUseful options:
--export-obsidian: generate the human-facing Obsidian vault export.--replace-output: delete and recreate the entire output directory before scanning. Use only when that directory is known to be disposable.--include <path>: deliberately include a path that ignore policy would normally skip.--disable-default-ignore <name>: disable one built-in default ignore such asnode_modules.--no-default-ignores: disable all built-in default ignores.--allow-output-inside-target: explicitly permit generated output inside the analyzed target.--config <path>: load an explicitcodegraph.toml.
Check whether an existing graph is current.
codegraph status /path/to/output
codegraph status /path/to/output --jsonStatus compares target membership, file size, and modification time. It is meant to be cheap enough for repeated checks.
Rebuild an existing graph using the stored manifest contract.
codegraph refresh /path/to/outputRefresh keeps the managed output directory and reuses cached per-file extraction results when it is safe to do so. It falls back to a full rebuild when target membership, config, ignore policy, or import alias resolution changes.
The graph is marked not ready while refresh is rebuilding, then marked ready
only after graph.json, manifest.json, reports, and optional exports are
written.
Poll an existing graph and refresh when it becomes stale.
codegraph watch /path/to/output --interval 2This keeps a graph alive for long-running work. Consumers should still check
.ready or use status before relying on the output.
Print an architecture-first JSON summary for agents and operators.
codegraph overview /path/to/output --limit 12Use this before broad code investigation. It returns:
- freshness and quality
- node and edge kind counts
- top areas, domains, layers, roles, and features
- important files ranked by semantic graph degree
- important external modules
- stable agent entrypoints such as
layer:screensorfeature:LoginScreen - warnings when coverage is partial
Return a focused evidence-backed subgraph.
codegraph query /path/to/output --node feature:LoginScreen --direction in --depth 1
codegraph query /path/to/output --node src/screens/LoginScreen.tsx --depth 2Defaults are intentionally compact:
- traversal is outgoing-only
- containment edges are skipped
- all confidence classes are allowed
Use broader traversal only when intentional:
codegraph query /path/to/output --node layer:screens --direction in --depth 1
codegraph query /path/to/output --node src --direction both --include-containment --depth 2
codegraph query /path/to/output --node SomeNode --confidence PROVEN --confidence DERIVEDValidate graph integrity, freshness, quality, and Obsidian export consistency.
codegraph doctor /path/to/output
codegraph doctor /path/to/output --jsonUse doctor after generation, before opening a graph for serious work, or after
a watch/refresh cycle.
Rebuild the human export from an existing ready graph.
codegraph export /path/to/outputPrint the Obsidian export path, or open it with the system default handler.
codegraph open /path/to/output
codegraph open /path/to/output --systemDelete a managed graph output directory. This is intentionally explicit and
refuses to delete without --yes.
codegraph clean /path/to/output --yesclean only deletes directories that look like codegraph outputs.
codegraph.toml is optional. Scans remain useful without it.
Example:
[scan]
include = ["fixtures"]
disable_default_ignore = ["node_modules"]
[imports.aliases]
"@/*" = "src/*"
"@components/*" = "src/components/*"
[architecture]
feature_markers = ["domains", "packages"]
generic_feature_names = ["internal"]Supported sections:
[scan] include: paths that should override ignore policy.[scan] disable_default_ignore: built-in ignore names to disable.[scan] no_default_ignores: disable every built-in ignore.[imports.aliases]: import path aliases.*wildcards are supported.[architecture] feature_markers: path segments whose next segment should be treated as a feature name.[architecture] generic_feature_names: additional names that should not become feature nodes.
The manifest records the config path, effective config, and config fingerprint.
Changing the config makes status report the graph as stale.
Scans also derive internal package aliases from discovered package.json files.
For example, a package named @repo/ui can make imports from @repo/ui
resolve to that package's source entrypoint instead of appearing as an external
module.
The graph has two complementary layers.
The evidence layer stores direct extracted facts:
- files and directories
- symbols and sections
- imports, exports, renders, definitions, references, and simple citations
- Python AST structure including class methods, relative import levels, safe local method call resolution, and evidenced decorator/base-class links
- JS/TS module forms including type imports, re-exports,
require, dynamicimport(),require.resolve(), and CommonJS export signals - internal package imports derived from
package.jsonnames - Markdown concepts and claim signals as inferred research/documentation edges, with concept-hub suppression and simple reference/footnote capture
- config files and keys
- logs and log statements
- assets and generated artifacts as metadata-backed nodes
- external modules and imported symbols
The architecture layer adds inferred orientation:
area: top-level target area such assrc,docs, orassetsdomain: material type such as code, documentation, configuration, asset, or observabilitylayer: structural layer such as screens, components, hooks, networking, state, models, tests, utilities, docs, or configrole: file role such as screen, component, hook, api, state, style, type, test, model, documentation, or configurationfeature: product or topic grouping inferred from meaningful path segments
Architecture edges are INFERRED. They are meant for discovery and orientation,
while parser and lexical facts remain the stronger evidence for final changes.
The manifest includes extractor declarations so agents can see which node kinds and edge kinds each extractor is expected to produce. Quality summaries also record observed node and edge kinds by extractor and content domain for auditability across code, docs, config, log, asset, and artifact-heavy collections.
When --export-obsidian is enabled, codegraph writes a navigable vault under
<output>/obsidian.
Important sections:
index.md: freshness, quality, totals, and navigation.Dashboards/Architecture.md: ranked architecture summary.Dashboards/Entrypoints.md: recommended starts for humans and agents.Dashboards/Domains.md: material-domain hubs with linked file reasons.Dashboards/Roles.md: role hubs with linked file reasons.Dashboards/Features.md: ranked feature summary.Dashboards/Layers.md: ranked layer summary.Dashboards/Graph Views.md: human-readable graph search presets.Dashboards/Research.md: concepts and claims from documentation/research.Indexes/Architecture.md: high-level architecture nodes.Indexes/Features.md: product/topic groupings.Indexes/Layers.md: structural layers.Indexes/Roles.md: file roles.Indexes/Domains.md: material domains.Indexes/Files.md: source files.Indexes/Concepts.md: inferred documentation/research concepts.Indexes/Claims.md: inferred documentation/research claim signals.Indexes/Assets.md: asset metadata nodes.Indexes/Artifacts.md: generated or artifact metadata nodes.Indexes/Config.md: configuration files and keys.Indexes/Observability.md: log files and statements.
The default graph view search is tuned toward Architecture and Files so the
first visual impression is structural instead of a dense cloud of every symbol.
Dashboards/Graph Views.md also records human-readable filter presets without
depending on undocumented Obsidian vault schema beyond the generated
.obsidian/graph.json.
Architecture dashboards include trust notes and now surface top linked files
with visible belongs_to / categorized_as reasons plus semantic edge counts.
Treat those hubs as orientation for where to look next, then confirm the linked
source note or file before making edits.
For an AI agent using an existing graph:
- Run
codegraph status <output> --json. - If stale, run
codegraph refresh <output>or ask the operator. - Run
codegraph doctor <output> --json. - Run
codegraph overview <output> --limit 20. - Pick stable entrypoints from
agent_entrypoints. - Use
queryto inspect focused subgraphs before falling back to direct file search. - Treat
INFERREDedges as orientation andPROVEN/DERIVEDedges as stronger planning evidence.
For the full protocol, see AGENT_PROTOCOL.md.
This workflow is meant to reduce broad grep passes, not ban source inspection. The graph should answer "where should I look first?" and "what is connected to this?" before deeper implementation work begins.
For a human reading a target:
- Generate with
--export-obsidian. - Open
<output>/obsidianas a vault or copy/link it into an existing vault. - Start from
index.md. - Open the graph view; the default filter emphasizes Architecture and Files.
- Use
Dashboards/Features.md,Dashboards/Layers.md,Dashboards/Domains.md, andDashboards/Roles.mdto pivot from hubs into concrete files with visible reasons and counts. - Check the trust notes before treating inferred architecture as planning proof.
passed means the graph met the current integrity and coverage gates.
partial means the graph is useful but should not be treated as complete. Common
causes:
- unsupported assets or binary files
- unknown file types
- extractor failures
- supported files with too little semantic information
- coverage below configured thresholds
untrusted means critical integrity or very low coverage made the graph unsafe
as a planning artifact.
Default ignores protect scans from generated, vendored, dependency, cache, and build surfaces. Examples include dependency folders, VCS metadata, build outputs, and generated graph artifacts.
Use explicit override flags when those paths are intentionally part of the
analysis. Overrides are recorded in manifest.json.
Run tests:
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src python3 -m unittest discover -s testsThe test suite includes benchmark fixtures for:
- alias-heavy TypeScript application structure
- non-code research notes
- configuration, logs, assets, and generated artifacts
Generate a disposable fixture graph:
PYTHONPATH=src python3 -m codegraph scan ./tests --out /tmp/codegraph-tests --export-obsidian
PYTHONPATH=src python3 -m codegraph overview /tmp/codegraph-tests
PYTHONPATH=src python3 -m codegraph doctor /tmp/codegraph-tests