Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

kg-extract — Claude Code skill: knowledge graph from source code

Extracts entities and relations from source files to build a knowledge graph in AgentDB. Use it to map codebase structure, analyze dependencies, and assess change impact.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add ruvnet/ruflo --skill kg-extract -a claude-code
Open on GitHub

What kg-extract does

kg-extract scans files at a given path, identifies entities (classes, functions, modules, types, config references), and maps their relations: imports, inheritance, interface implementations, constructor dependencies, function calls. The result is stored as a graph in AgentDB with metadata for each entity.

The skill critically distinguishes TypeScript value imports from type-only imports. Type imports (import type { Foo }) are erased at compile time and do not create runtime cycles; misclassifying them produces phantom dependencies. Relations carry weights: value imports 0.9, type imports 0.1, inheritance 0.9, constructor dependencies 0.8, calls 0.7, documentation references 0.3.

Tools available: file reading (Read, Glob, Grep), AgentDB storage for entities and edges, and CLI commands to persist and query entities by namespace.

What it helps with

  • map the dependency graph across a codebase
  • detect circular dependencies and phantom type imports
  • assess the blast radius of a change
  • document architecture as a queryable entity graph

Example prompts for the agent

  • Extract entities and relations from src/ into the knowledge graph
  • Build a dependency graph for the entire project in ./
  • Find all entities that depend on the auth module

How to install kg-extract

1Skills CLI (Vercel)

npx skills add ruvnet/ruflo --skill kg-extract -a claude-code

2Manually: put the files in place

~/.claude/skills/kg-extract/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/kg-extract/

From the same set104

The whole set →
ruflo ruvnet This skill adds multi-agent orchestration, memory, routing, and MCP tools to a project. Use it for swarm tasks and multi-step workflows. Claude Code CX Codex Cursor +1 4,000installs Swarm Orchestration ruvnet Skill for managing agent swarms with parallel execution, dynamic topology, and automatic load balancing. Use when a single agent is not enough and you need to orchestrate specialists of different types. Claude Code CX Codex Cursor +1 2,100installs github-project-management ruvnet Turns issue triage and board upkeep into gh and ruv-swarm calls: labels, subtasks, duplicate lookup. Useful when the tracker holds more tickets than order. Claude Code CX Codex Cursor +1 1,400installs github-workflow-automation ruvnet Automates GitHub Actions with AI agent coordination. Generates optimised pipelines, manages pull requests, analyzes failed runs, and deploys updates with risk assessment. Claude Code CX Codex Cursor +1 1,300installs github-code-review ruvnet Runs a swarm of specialized AI agents to inspect GitHub pull requests for security, performance, and architecture issues. Claude Code CX Codex Cursor +1 1,300installs stream-chain ruvnet Chains sequential agent steps together using streaming JSON flow and provides ready-to-run pipelines. Claude Code CX Codex Cursor +1 1,200installs flow-nexus-swarm ruvnet Deploy cloud-based AI agent swarms and define event-driven workflows with message queues. Use it to coordinate tasks, inspect runs, and scale a swarm. Claude Code CX Codex Cursor +1 1,200installs performance-analysis ruvnet Detects bottlenecks in Claude Flow swarms, profiles agent operations, and generates reports with actionable optimization recommendations. Claude Code CX Codex Cursor +1 1,200installs

Similar

Questions about kg-extract

How do I install kg-extract in Claude Code?

Run npx skills add ruvnet/ruflo --skill kg-extract -a claude-code. The skill will be available at ~/.claude/skills/kg-extract/SKILL.md.

What does kg-extract do?

It scans source files, extracts classes, functions, modules and their relations (imports, inheritance, dependencies), then stores the graph in AgentDB for architecture and dependency analysis.

Why does it distinguish value imports from type imports?

TypeScript type imports are erased at compile time and do not create runtime cycles. Without this distinction, you get false circular dependencies and wrong impact assessments.

Source text

SKILL.md · MIT
---
name: kg-extract
description: Extract entities and relations from source files to build a knowledge graph
argument-hint: "<path>"
allowed-tools: Read Glob Grep mcp__plugin_ruflo-core_ruflo__agentdb_hierarchical-store mcp__plugin_ruflo-core_ruflo__agentdb_causal-edge mcp__plugin_ruflo-core_ruflo__agentdb_pattern-store mcp__plugin_ruflo-core_ruflo__embeddings_generate Bash
---

# KG Extract

Extract entities (classes, functions, modules, types, concepts) and their relations (imports, extends, implements, depends-on, calls) from source files, then store them as a knowledge graph in AgentDB.

## When to use

When you need to build or update a knowledge graph from source code or documentation. Useful for understanding codebase structure, dependency analysis, and impact assessment.

## Steps

1. **Scan files** -- use `Glob` and `Read` to enumerate and read source files at the given path
2. **Identify entities** -- extract classes, functions, modules, types, and config references from each file
3. **Map relations** -- for each entity, determine its relations to other entities. **Critical: TypeScript `import type` and inline `type` specifiers (`import { type Foo, bar }`) are erased at compile time and MUST NOT be counted as value imports** -- they're a separate, weaker relation. Misclassifying them produces phantom runtime cycles (see ruvnet/ruflo#2049).
   - `imports`: value imports (`import { x } from '...'`, `require(...)`) -- weight `0.9`
   - `type-depends-on`: TypeScript type-only imports (`import type { Foo } from '...'` and `import { type Foo, value } from '...'`) -- weight `0.1`, **never used for cycle detection or runtime impact analysis**
   - `extends`: class inheritance -- weight `0.9`
   - `implements`: interface implementations -- weight `0.7`
   - `depends-on`: constructor dependencies, injected services -- weight `0.8`
   - `calls`: function/method invocations -- weight `0.7`
   - `references`: documentation mentions, comments -- weight `0.3`

   **Regex hint for classifying TS imports** (so a naive `from '...'` grep doesn't conflate the two):
   ```
   ^\s*import\s+type\s+               → type-depends-on (entire import is type-only)
   ^\s*import\s*\{[^}]*\btype\s+\w+   → split: type specifiers → type-depends-on, value specifiers → imports
   ^\s*import\s+[^{]*\bfrom\s+        → imports (value)
   ```
4. **Store in AgentDB** -- call `mcp__plugin_ruflo-core_ruflo__agentdb_hierarchical-store` for each entity with metadata (name, type, file, line, description)
5. **Create edges** -- call `mcp__plugin_ruflo-core_ruflo__agentdb_causal-edge` for each relation with source, target, relation type, and weight
6. **Report** -- summarize: total entities by type, total relations by type, files scanned

## CLI alternative

```bash
npx @claude-flow/cli@latest memory store --namespace knowledge-graph --key "entity-NAME" --value "METADATA_JSON"
npx @claude-flow/cli@latest memory search --query "entities in auth module" --namespace knowledge-graph
```

© ruvnet · MIT · ruvnet/ruflo

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor