/understand on a large codebase from scratch can take several minutes. Incremental analysis eliminates most of that wait by re-analyzing only the files that changed since the last run, then merging the fresh results into the existing knowledge graph.
How it works
Read the last commit hash
When the pipeline starts, it reads the
gitCommitHash stored in .understand-anything/meta.json.Detect changed files
The If
isStale function compares the stored hash against HEAD using git diff:git diff returns no files, the pipeline reports “Graph is up to date” and exits immediately — no agents are launched.Re-analyze only changed files
The changed file list is batched and dispatched to
file-analyzer agents, just like a full analysis — but the batch contains only the modified files. Up to 3 agents run concurrently.Merge into the existing graph
The In order:
mergeGraphUpdate function surgically updates the existing graph:- Identify all nodes whose
filePathmatches any changed file — these are stale and will be replaced. - Remove stale nodes from the graph.
- Remove any edge whose
sourceortargetbelongs to a removed node. - Append the fresh nodes and edges from the new analysis.
- Update
project.gitCommitHashandproject.analyzedAtto reflect the current state.
Re-run architecture analysis
Even for incremental updates, the
architecture-analyzer always re-runs on the full merged node set. Layer assignments can shift when files change (for example, a new services/ directory could attract nodes away from Core). The agent is given the previous layer definitions and instructed to maintain the same names and IDs where possible.The AnalysisMeta type
Metadata about the last analysis run is stored inmeta.json and represented by the AnalysisMeta interface:
| Field | Description |
|---|---|
lastAnalyzedAt | ISO 8601 timestamp of the last successful analysis |
gitCommitHash | The git commit at which the graph was last fully built or incrementally updated |
version | Schema version — used to detect when a format migration is needed |
analyzedFiles | Number of files that were analyzed in the last run |
Decision table
The pipeline’s Phase 0 pre-flight applies this logic every time/understand is run:
| Condition | Result |
|---|---|
--full flag passed | Full analysis, ignores existing graph |
No meta.json or no knowledge-graph.json | Full analysis |
| Commit hash unchanged | ”Graph is up to date” — stops immediately |
| Commit hash changed, files differ | Incremental update (changed files only) |
git diff returns no files despite hash change | ”Graph is up to date” — stops immediately |
When to force a full re-analysis
Incremental analysis covers the common case — committed code changes. Use--full to force a complete rebuild when:
- You’ve made uncommitted changes that you want reflected in the graph. Git diff only tracks committed changes, so working-tree modifications are invisible to the staleness check.
- The schema version has changed. If you update the plugin and the graph format has evolved, the existing graph may not be compatible with the new dashboard.
- The graph seems wrong or incomplete. If incremental merges have accumulated errors, a fresh build is the cleanest fix.
- You’ve significantly restructured the project. Moving many files can leave orphaned nodes and stale layer assignments that are better resolved by a clean run.
Performance impact
For a typical project the time savings are significant:| Scenario | Analysis scope | Approximate time |
|---|---|---|
| First run, 50-file project | 50 files | ~2–3 minutes |
| Incremental, 3 files changed | 3 files | ~15–30 seconds |
| First run, 200-file project | 200 files | ~8–12 minutes |
| Incremental, 10 files changed | 10 files | ~45–90 seconds |