# How to Access the Egonex-AI Understand Anything Plugin API: A Complete Guide

> Access the Egonex-AI Understand Anything plugin API with this complete guide. Learn to import skill builders and load knowledge graphs to programmatically drive chat, diff, and explanation workflows.

- Repository: [Egonex/Understand-Anything](https://github.com/Egonex-AI/Understand-Anything)
- Tags: how-to-guide
- Published: 2026-06-26

---

**Import the skill builders from `@understand-anything/plugin` and load the knowledge graph with `GraphBuilder` from the core package to programmatically drive chat, diff, and explanation workflows.**

The Egonex-AI Understand Anything plugin provides a TypeScript-based API for integrating code understanding capabilities into custom tools and CI pipelines. This guide covers how to access the Egonex-AI Understand Anything plugin API using the barrel exports from the plugin entry point and the core package utilities. All public functions are re-exported from [`understand-anything-plugin/src/index.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/index.ts), providing a clean interface for building LLM prompts and analyzing codebases.

## Plugin API Entry Point and Core Exports

The plugin exposes its functionality through a barrel file that aggregates builders from individual skill modules. This design allows you to import everything from the top-level module while maintaining tree-shaking compatibility.

### Barrel File Structure

The main entry point at [`understand-anything-plugin/src/index.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/index.ts) re-exports high-level builder functions for each skill:

| Export | Purpose | Source File |
|--------|---------|-------------|
| `buildChatContext` / `formatContextForPrompt` / `ChatContext` | Build structured context for the `/understand-chat` skill | [`src/context-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/context-builder.ts) |
| `buildChatPrompt` | Assemble the final prompt string for chat interactions | [`src/understand-chat.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/understand-chat.ts) |
| `buildDiffContext` / `formatDiffAnalysis` / `DiffContext` | Generate diff-aware context for the `/understand-diff` skill | [`src/diff-analyzer.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/diff-analyzer.ts) |
| `buildExplainContext` / `formatExplainPrompt` / `ExplainContext` | Create file-explanation context for `/understand-explain` | [`src/explain-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/explain-builder.ts) |
| `buildOnboardingGuide` | Produce onboarding tours for new developers | [`src/onboard-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/onboard-builder.ts) |

Import these functions in a single statement:

```typescript
import {
  buildChatContext,
  buildChatPrompt,
  buildDiffContext,
  formatDiffAnalysis,
  buildExplainContext,
  formatExplainPrompt,
  buildOnboardingGuide,
} from "@understand-anything/plugin";

```

### Core Package Sub-Paths

The **core package** (`understand-anything-plugin/packages/core`) provides shared utilities via sub-path exports (`@understand-anything/core/*`). This architecture allows browser environments to import only browser-safe modules without pulling in Node-specific code.

Key core utilities include:

- **Graph schema validation** – [`src/schema.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/schema.ts) exports `KnowledgeGraphSchema` and `validateGraph`
- **Tree-sitter parsing** – [`src/plugins/tree-sitter-plugin.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/plugins/tree-sitter-plugin.ts) handles deterministic AST extraction
- **Language detection** – [`src/languages/index.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/languages/index.ts) auto-detects project languages and frameworks
- **Semantic search** – [`src/search.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/search.ts) and [`src/embedding-search.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/src/embedding-search.ts) power vector-based code search

## Loading the Knowledge Graph

Before invoking any skill builders, you must load the persisted knowledge graph generated by the `/understand` command. The `GraphBuilder` class in the core package handles this operation.

```typescript
import { GraphBuilder } from "@understand-anything/core";

const graph = await GraphBuilder.loadFromFile(
  "./.understand-anything/knowledge-graph.json"
);

```

This method returns a graph instance that serves as the primary input for all skill builder functions. The graph contains nodes and edges representing your codebase's structure, dependencies, and semantic relationships.

## Skill Builder Functions

Each skill in the Understand Anything ecosystem corresponds to a specific builder function that transforms the knowledge graph into LLM-ready prompts or structured outputs.

### Chat Context and Prompt Building

The `buildChatContext` function creates a structured context object containing relevant code snippets and relationships based on your query. The `buildChatPrompt` function then formats this context into a prompt string suitable for any LLM.

```typescript
const chatCtx = await buildChatContext({ graph, query: "How does the payment flow work?" });
const prompt = buildChatPrompt(chatCtx);
// Send `prompt` to Claude, OpenAI, or your preferred model

```

### Diff Analysis

For analyzing code changes, use `buildDiffContext` to identify affected nodes and edges in the knowledge graph, then `formatDiffAnalysis` to generate human-readable impact reports.

```typescript
const diffCtx = await buildDiffContext({ graph, changedFiles: ["src/auth.ts"] });
const report = formatDiffAnalysis(diffCtx);

```

### File Explanation

The `buildExplainContext` and `formatExplainPrompt` functions create detailed explanations of specific files or modules by extracting relevant subgraphs and formatting them for LLM consumption.

### Onboarding Generation

The `buildOnboardingGuide` function generates step-by-step tours through the codebase tailored for new team members, utilizing the graph's module hierarchy and dependency information.

## Complete Implementation Examples

### Running a Chat Query Against the Codebase

This example demonstrates loading the graph and executing a natural language query:

```typescript
import {
  buildChatContext,
  buildChatPrompt,
} from "@understand-anything/plugin";
import { GraphBuilder } from "@understand-anything/core";

async function askQuestion(question: string) {
  // Load the persisted knowledge graph
  const graph = await GraphBuilder.loadFromFile(
    "./.understand-anything/knowledge-graph.json"
  );

  // Build the LLM-ready context
  const ctx = await buildChatContext({ graph, query: question });

  // Assemble the final prompt string
  const prompt = buildChatPrompt(ctx);

  // Pass `prompt` to your LLM
  console.log("Prompt for LLM:", prompt);
}

askQuestion("How does the authentication flow work?");

```

### Generating a Diff Impact Report

Analyze the impact of code changes by passing modified file paths to the diff analyzer:

```typescript
import {
  buildDiffContext,
  formatDiffAnalysis,
} from "@understand-anything/plugin";
import { GraphBuilder } from "@understand-anything/core";

async function diffReport(changedFiles: string[]) {
  const graph = await GraphBuilder.loadFromFile(
    "./.understand-anything/knowledge-graph.json"
  );

  // Build a diff-aware context (provides affected nodes & edges)
  const diffCtx = await buildDiffContext({ graph, changedFiles });

  // Human-readable analysis
  const report = formatDiffAnalysis(diffCtx);
  console.log(report);
}

// Example usage
diffReport(["src/auth/login.ts", "src/services/payment.ts"]);

```

### Creating an Onboarding Tour

Generate automated onboarding documentation for new developers:

```typescript
import { buildOnboardingGuide } from "@understand-anything/plugin";
import { GraphBuilder } from "@understand-anything/core";

async function generateTour() {
  const graph = await GraphBuilder.loadFromFile(
    "./.understand-anything/knowledge-graph.json"
  );

  const tour = await buildOnboardingGuide({ graph });
  console.log("Onboarding steps:", tour);
}

generateTour();

```

## Key Source Files and Architecture

Understanding the internal file structure helps when debugging or extending the API:

| File Path | Role |
|-----------|------|
| [`understand-anything-plugin/src/index.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/index.ts) | Public API barrel – re-exports all skill builders |
| [`understand-anything-plugin/src/context-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/context-builder.ts) | Generates chat contexts from the knowledge graph |
| [`understand-anything-plugin/src/diff-analyzer.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/diff-analyzer.ts) | Diff-aware context creation and formatting |
| [`understand-anything-plugin/src/explain-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/explain-builder.ts) | File-explanation context and prompt formatting |
| [`understand-anything-plugin/src/onboard-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/onboard-builder.ts) | Generates onboarding tours |
| [`understand-anything-plugin/packages/core/src/index.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/packages/core/src/index.ts) | Core utilities (graph loading, schema validation) |
| [`understand-anything-plugin/packages/core/src/schema.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/packages/core/src/schema.ts) | Knowledge-graph schema definitions |
| [`understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts) | Deterministic AST extraction using Web-Tree-Sitter |
| [`understand-anything-plugin/packages/core/src/languages/index.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/packages/core/src/languages/index.ts) | Language and framework detection |

## Summary

- **Import from the barrel file**: Use `@understand-anything/plugin` to access `buildChatContext`, `buildDiffContext`, `buildOnboardingGuide`, and other skill builders.
- **Load the graph first**: Always call `GraphBuilder.loadFromFile()` from `@understand-anything/core` to initialize the knowledge graph before running queries.
- **Core vs. Plugin separation**: The core package provides low-level graph operations and parsing, while the plugin package provides high-level LLM prompt builders.
- **Type-safe API**: All exports include TypeScript definitions for `ChatContext`, `DiffContext`, and `ExplainContext` to ensure compile-time safety.
- **Sub-path imports**: Use `@understand-anything/core/*` imports to access browser-safe modules without Node dependencies.

## Frequently Asked Questions

### What is the difference between `@understand-anything/plugin` and `@understand-anything/core`?

`@understand-anything/plugin` provides the high-level skill builders like `buildChatContext` and `buildDiffContext` that create LLM prompts. `@understand-anything/core` contains the underlying utilities such as `GraphBuilder`, schema validation, and Tree-sitter parsers. The core package supports sub-path imports so you can import only the specific utilities you need without bundling Node-only code.

### Do I need to run the `/understand` command before using the API?

Yes. The skill builders require a persisted knowledge graph generated by the `/understand` multi-agent pipeline. This command creates [`.understand-anything/knowledge-graph.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/knowledge-graph.json), which you must load using `GraphBuilder.loadFromFile()` before passing the graph instance to any builder functions.

### Can I use the Understand Anything API in a browser environment?

Yes, but you must import only browser-safe modules from the core package using sub-path imports like `@understand-anything/core/graph` or `@understand-anything/core/schema`. Avoid importing the full core package or plugin package in browsers, as these may include Node-specific dependencies like file system utilities.

### How do I customize the prompts generated by the skill builders?

The skill builders return context objects (e.g., `ChatContext`, `DiffContext`) that contain structured data about your codebase. You can either use the provided prompt formatters like `buildChatPrompt()` or extract the context data and format it according to your own prompt templates. The context objects expose the raw nodes, edges, and code snippets discovered in the knowledge graph.