Graph API
@contextlint/core exposes a set of functions that build a dependency graph from parsed documents and let you query impact sets, related documents, dependency order, and more. The Graph API is the programmatic interface for calling these functions directly.
Use it when you want to work with relationships between documents from scripts or tooling rather than using contextlint as a linter. The MCP context-graph / context-slice / impact-analysis tools call this API internally as well (see AI Agents).
For the design philosophy and the reasoning behind why the Context Graph exists, see Context Graph. This category focuses on how to use the API.
What this category covers
Section titled “What this category covers”buildContextGraph— Build a dependency graph from parsed documentsgetImpactSet— Get the list of files affected by changing a given filegetContextSlice— Extract the minimal set of documents relevant to a querytopologicalSort— Order files by dependencygetComponents— Get connected components (clusters of documents)classifyImpact— Classify impact as direct vs transitiveformatContextGraphSummary— Format a human-readable summary of the graph