Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

code-graph-llm

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code-graph-llm

Compact, language-agnostic codebase mapper for LLM token efficiency.

latest
Source
npmnpm
Version
5.1.0
Version published
Weekly downloads
132
Maintainers
1
Weekly downloads
 
Created
Source

CODE-GRAPH (v5.1.0)

Inspired by Andrej Karpathy skills, juliusbrussee/caveman, and the community's work building better agent workflows.

A language-agnostic, ultra-compact codebase mapper and agent memory system for LLM agents. Code-Graph gives agents a compact file, symbol, and dependency index, then pairs it with persistent project learnings so agents can avoid repeating mistakes across sessions.

New in v5.1.0

  • MCP Tools (3 new): Added get_project_graph (reads full llm-code-graph.md — use instead of Read), search_symbols (symbol search across all files — use instead of Grep), and trace_dependencies (upstream/downstream blast radius for a file — use instead of manual EDGES parsing). Server now exposes 8 tools total.
  • MCP Structured Errors: All tool handlers return { isError: true, content: [{ type: "text", text: JSON.stringify({ error_type, message, retryable, suggested_action }) }] }. Error types: GRAPH_NOT_FOUND, FILE_NOT_IN_GRAPH, INVALID_PATH, INVALID_INPUT, TOOL_TIMEOUT, UNKNOWN_TOOL, INTERNAL_ERROR. Agents can branch on error_type and use suggested_action to self-correct.
  • MCP Timeouts: All tool calls are wrapped in Promise.race with a timeout. Default: 30s. generate_graph: 300s (5 min). Timeout returns TOOL_TIMEOUT with retryable: true.
  • Agent Descriptions (WHEN/INSTEAD): All sub-agent descriptions for Claude Code, Gemini, Kiro, Antigravity, and generic platforms now follow the WHEN/INSTEAD pattern — describing trigger conditions and what they replace (Read, Grep, manual EDGES parsing) rather than abstract capability labels.
  • Skills (MCP awareness): ProjectMap and Reflections skills now include conditional MCP tool guidance for all 40+ supported platforms: get_project_graph instead of Read, search_symbols instead of Grep, add_reflection/get_reflections instead of CLI and direct file reads.
  • Generated rules (MCP section): llm-agent-rules.md scaffolded by code-graph init now includes a full MCP tools section listing all 8 tools with INSTEAD guidance.
  • Gitignore (generated platform files): Added all generated platform output files to .gitignore (GEMINI.md, AGENTS.md, .clinerules, .roorules, .kiro/, .opencode/, .roo/, .cursor/rules/, llm-agent-rules.md, llm-agent-project-learnings.md, and others) to prevent machine-specific paths from being committed.
  • Tests: Fixed 2 broken error tests (new structured error format), added 13 new tests for handleGetProjectGraph, handleSearchSymbols, handleTraceDependencies, INVALID_PATH validation, and GRAPH_NOT_FOUND with suggested_action. 24 tests total in mcp-server.test.js.

See RELEASE_NOTES.md for full history.

Installation

# Global installation (recommended for CLI usage)
npm install -g code-graph-llm

# Project-level installation
npm install --save-dev code-graph-llm

Quick Start

# 0. Check version and help
code-graph --version
code-graph --help

# 1. Initialize rules and memory
code-graph init

# 2. Build the graph
code-graph generate

# 3. Install all bundled skills for one agent
code-graph install-skills claude

# 4. Or install globally for all projects
code-graph install-skills -g claude

Every install prints each target it writes:

[Code-Graph v5.0.0] Installed/updated: /absolute/path/to/AGENTS.md
[Code-Graph v5.0.0] Installed/updated: /absolute/path/to/.codex/hooks.json

Core Concepts

Code-Graph operates in two modes: Passive Skills and Active Agents.

ModeParadigmBenefitCommand
UnifiedBothInstalls skills and the active agent together.code-graph install <platform>
SkillsPassive ContextInjects the graph and memory rules into the agent's normal workflow.code-graph install-skills <platform>
AgentsActive DelegationRegisters code-graph as a specialized sub-agent.code-graph install-agent <platform>

Unified Installation

Get the full Code-Graph experience by installing both skills and the active sub-agent in one command.

code-graph install gemini

Uninstall with:

code-graph uninstall <platform>

Passive Skills

Skills are always-on configurations that tell your agent how to use the project map and memory files. code-graph install-skills <platform> installs all bundled skills by default for every supported platform.

  • ProjectMap: Reads llm-code-graph.md, the canonical file, symbol, and dependency index, before raw file searches.
  • Reflections: Reads and updates llm-agent-project-learnings.md so agents retain project-specific lessons.
  • ThinkBeforeCoding: Surfaces assumptions, ambiguity, tradeoffs, and simpler options before non-trivial work.
  • Simplicity: Keeps changes limited to what the task actually requires.
  • SurgicalChanges: Prevents unrelated refactors, style churn, and scope creep while allowing cleanup caused by your own diff.
  • GoalDriven: Forces explicit success criteria and verification before completion.
  • FreshDeps: Forces latest stable compatible dependencies and current, non-deprecated APIs.
  • ContextBudget: Periodically condenses working context to reduce token load and stale detail.
# Install all bundled skills
code-graph install-skills gemini

# Install one skill
code-graph install-skills cursor projectmap

# Install only dependency freshness rules
code-graph install-skills codex freshdeps

# Install surgical diff rules (CLI alias remains changelimit-compatible)
code-graph install-skills claude surgicalchanges

# Uninstall one skill
code-graph uninstall-skills claude reflections

# Uninstall all skills for a platform
code-graph uninstall-skills claude

Active Agents

Agents are specialized personas. Instead of only reading project files, a main orchestrator such as Gemini CLI or Claude Code can delegate mapping and analysis work to the Code-Graph agent.

# Register code-graph as a sub-agent
code-graph install-agent claude

# Example delegation:
# "Hey code-graph, analyze the dependency chain of the auth module."

Uninstall with:

code-graph uninstall-agent <platform>

Claude Code receives focused sub-agents when available:

  • code-graph: Use INSTEAD of reading source files for architectural overviews, refreshing the map, or persisting lessons after failures.
  • code-graph-locator: Use INSTEAD of Read/Grep when finding relevant files before exploring source. Trigger: "which files relate to X", "where is Y defined".
  • code-graph-tracer: Use INSTEAD of manual import tracing when assessing change impact. Trigger: "what depends on X", "what breaks if I change Y".
  • code-graph-reviewer: Use AFTER making changes to verify Code-Graph protocol compliance. Trigger: "check code-graph protocol", "is the map stale".

Supported Platforms

Use -g before the platform to install skills globally. Without -g, skills are installed for the current project when the platform supports project-level instructions.

AgentCommandInstall Target
AdaLcode-graph install-skills adal~/.adal/skills/
AiderDeskcode-graph install-skills aider-desk~/.aider-desk/skills/
Aidercode-graph install-skills aider~/.aider/skills/
Ampcode-graph install-skills amp~/.config/agents/skills/
Antigravitycode-graph install-skills antigravity~/.gemini/antigravity/skills/
Augmentcode-graph install-skills augment~/.augment/skills/
Claude Codecode-graph install-skills claude~/.claude/skills/
Cline / Warpcode-graph install-skills cline or code-graph install-skills warp~/.agents/skills/
Codexcode-graph install-skills codex~/.codex/skills/
CodeArts Agentcode-graph install-skills codearts-agent~/.codeartsdoer/skills/
CodeBuddycode-graph install-skills codebuddy~/.codebuddy/skills/
Codemakercode-graph install-skills codemaker~/.codemaker/skills/
Code Studiocode-graph install-skills codestudio~/.codestudio/skills/
Command Codecode-graph install-skills command-code~/.commandcode/skills/
Continuecode-graph install-skills continue~/.continue/skills/
Cortex Codecode-graph install-skills cortex~/.snowflake/cortex/skills/
Crushcode-graph install-skills crush~/.config/crush/skills/
Cursorcode-graph install-skills cursor~/.cursor/skills/
Deep Agentscode-graph install-skills deepagents~/.deepagents/agent/skills/
Devin for Terminalcode-graph install-skills devin~/.config/devin/skills/
Droidcode-graph install-skills droid~/.factory/skills/
Firebendercode-graph install-skills firebender~/.firebender/skills/
ForgeCodecode-graph install-skills forgecode~/.forge/skills/
Gemini CLIcode-graph install-skills gemini or code-graph install-skills gemini-cli~/.gemini/skills/
Generic Agentcode-graph install-skills generic~/.generic/skills/
GitHub Copilotcode-graph install-skills copilot or code-graph install-skills github-copilot~/.copilot/skills/
Goosecode-graph install-skills goose~/.config/goose/skills/
Hermescode-graph install-skills hermes~/.hermes/skills/
IBM Bobcode-graph install-skills bob~/.bob/skills/
IntelliJ / JetBrainscode-graph install-skills intellijAGENTS.md or ~/.intellij/skills/ with -g
iFlow CLIcode-graph install-skills iflow-cli~/.iflow/skills/
Juniecode-graph install-skills junie~/.junie/skills/
Kilo Codecode-graph install-skills kilo~/.kilocode/skills/
Kimi Code CLIcode-graph install-skills kimi-cli~/.config/agents/skills/
Kiro IDE/CLIcode-graph install-skills kiro or code-graph install-skills kiro-cli~/.kiro/skills/
Kodecode-graph install-skills kode~/.kode/skills/
MCPJamcode-graph install-skills mcpjam~/.mcpjam/skills/
Mistral Vibecode-graph install-skills mistral-vibe~/.vibe/skills/
Muxcode-graph install-skills mux~/.mux/skills/
Neovatecode-graph install-skills neovate~/.neovate/skills/
OpenClawcode-graph install-skills openclaw~/.openclaw/skills/
OpenCodecode-graph install-skills opencode~/.config/opencode/skills/
OpenHandscode-graph install-skills openhands~/.openhands/skills/
Picode-graph install-skills pi~/.pi/agent/skills/
Pochicode-graph install-skills pochi~/.pochi/skills/
Qodercode-graph install-skills qoder~/.qoder/skills/
Qwen Codecode-graph install-skills qwen-code~/.qwen/skills/
Replitcode-graph install-skills replit~/.config/agents/skills/
Roo Codecode-graph install-skills roocode or code-graph install-skills roo~/.roo/skills/
Rovo Devcode-graph install-skills rovodev~/.rovodev/skills/
Tabnine CLIcode-graph install-skills tabnine-cli~/.tabnine/agent/skills/
Traecode-graph install-skills trae~/.trae/skills/
Trae CNcode-graph install-skills trae-cn~/.trae-cn/skills/
Universalcode-graph install-skills universal~/.config/agents/skills/
VS Code Copilot Chatcode-graph install-skills vscode.github/copilot-instructions.md or ~/.vscode/skills/ with -g
Windsurfcode-graph install-skills windsurf~/.codeium/windsurf/skills/
Zencodercode-graph install-skills zencoder~/.zencoder/skills/

Platform Integration Details

Every supported platform receives all bundled skills when installing all skills. Platforms with native skill or rule formats get native artifacts; the rest receive the same mandatory instructions through their project instruction file, usually AGENTS.md.

PlatformAction TakenDirectory / Files
Claude CodeInjects instructions and installs PreToolUse hooks for Read, Grep, and Glob; agent install creates split Code-Graph sub-agents.CLAUDE.md, .claude/settings.json, .claude/agents/
CursorWrites always-on .mdc rule files for each bundled skill with alwaysApply: true..cursor/rules/
Gemini CLIInstalls global skills with YAML frontmatter and GEMINI.md memory imports.~/.gemini/skills/, GEMINI.md
AntigravityWrites always-on skills and rules locally, plus the specialized Code-Graph agent skill globally..agent/skills/, .agent/rules/, ~/.gemini/antigravity/skills/code-graph/
Kiro IDE/CLIWrites steering files locally; the specialized Code-Graph agent is registered globally..kiro/steering/, ~/.kiro/agents/code-graph/
CodexUpdates AGENTS.md and installs enabled nested PreToolUse hooks for Bash.AGENTS.md, .codex/hooks.json
OpenCodeRegisters per-skill plugins and preserves existing plugin entries.AGENTS.md, .opencode/plugins/, opencode.json
Roo CodeInjects instructions into project rule files..clinerules, .roorules
IntelliJ / JetBrainsAdds architectural context to a discoverable file.AGENTS.md
GitHub Copilot CLICopies skills globally for persistence.~/.copilot/skills/
VS Code CopilotWrites session-persistent instructions..github/copilot-instructions.md
Aider / Trae / OthersUpdates project instructions and copies skills globally when supported.AGENTS.md, ~/.<platform>/skills/

Agent Workflow

Instruct your agent to follow the strict protocol in llm-agent-rules.md:

  • Treat every bundled skill as mandatory: ProjectMap, Reflections, ThinkBeforeCoding, Simplicity, SurgicalChanges, GoalDriven, FreshDeps, and ContextBudget.
  • Read llm-agent-project-learnings.md before starting any task.
  • Read llm-code-graph.md before raw file searches or architecture analysis.
  • Surface assumptions and ambiguity before non-trivial work.
  • Define success criteria and report verification results or blockers.
  • Use latest stable compatible dependencies and current APIs; avoid deprecated packages, methods, functions, flags, and patterns.
  • Update reflections after failures, corrections, repeated mistakes, or non-obvious project behavior.
  • Regenerate llm-code-graph.md after structural code changes.

Recommended generic prompt:

Before acting, read llm-code-graph.md and follow llm-agent-rules.md. Treat all bundled skills as mandatory. Use latest stable compatible dependencies and current APIs; avoid deprecated choices. If you encounter a bug, environment quirk, or reusable project lesson, record it with code-graph reflect <CAT> <LESSON>.

Reading the Map

llm-code-graph.md is a compact index generated from the project. Each file entry is designed to help an agent decide which files matter before opening raw source:

  • * marks a core entry point or high-importance file.
  • (↑out ↓in) shows dependency counts. Outgoing dependencies are files or packages this file references; incoming dependencies are files that reference it.
  • d: is a short description extracted from file comments or nearby context.
  • s: lists important symbols found in the file, such as classes, functions, types, and exported values.
  • The ## EDGES section lists dependency relationships in the form [source] -> [targets].

For example:

- *src/auth.js (3↑ 5↓) [TODO:Add JWT rotation] | d: Handles user authentication.
  - s: [login [(username, password)], validateToken [(token: string)]]

## EDGES
[src/auth.js] -> [jwt-lib, db-connector]
[AdminUser] -> [BaseUser]

This means src/auth.js is a core file with 3 outgoing dependencies and 5 incoming references. It contains the login and validateToken symbols, has a TODO about JWT rotation, depends on jwt-lib and db-connector, and includes an inheritance relationship where AdminUser extends or implements BaseUser.

Sub-Agent Registration

Register code-graph as an active sub-agent to enable explicit delegation.

PlatformCommandAction Taken
Gemini CLIcode-graph install-agent geminiRegisters global agent in ~/.gemini/agents/code-graph.md.
Claude Codecode-graph install-agent claudeRegisters split sub-agents in .claude/agents/: code-graph, code-graph-locator, code-graph-tracer, and code-graph-reviewer.
Antigravitycode-graph install-agent antigravityRegisters agent skill in ~/.gemini/antigravity/skills/.
Kiro IDE/CLIcode-graph install-agent kiroRegisters agent in ~/.kiro/agents/.
Generic Agentcode-graph install-agent genericGenerates .code-graph-agent.md persona prompt.

MCP Server (Claude Code integration)

Any Claude Code project can connect to code-graph as an MCP tool server.

Add to your project's .mcp.json:

{
  "mcpServers": {
    "code-graph": {
      "command": "code-graph",
      "args": ["mcp"]
    }
  }
}

Or if using a local dev install:

{
  "mcpServers": {
    "code-graph": {
      "command": "node",
      "args": ["/absolute/path/to/code-graph/index.js", "mcp"]
    }
  }
}

Available tools

ToolWhen to useDescription
get_project_graphINSTEAD of Read on the graph fileRead full llm-code-graph.md — fastest way to get project structure
search_symbolsINSTEAD of Grep for symbol lookupSearch symbol names across all files (case-insensitive)
trace_dependenciesINSTEAD of manual EDGES parsingOutgoing + incoming deps for a file, plus blast_radius count
generate_graphWhen map is stale or missingBuild/refresh llm-code-graph.md for any project path
get_file_symbolsTargeted file lookupReturn symbols for one specific file from the graph
search_graphBroad searchSearch file paths, symbols, and descriptions together with scoring
add_reflectionINSTEAD of code-graph reflect CLIAppend a lesson to llm-agent-project-learnings.md
get_reflectionsINSTEAD of reading the reflections fileReturn all lessons, optionally filtered by category

All tools require project_path (absolute path) — one running server handles multiple projects.

Error format: All tools return structured errors with isError: true and JSON content: { error_type, message, retryable, suggested_action? }. Agents can branch on error_type (e.g. GRAPH_NOT_FOUND → call generate_graph first).

Implementation Details

Project Structure

index.js              CLI entry point and public re-exports
lib/
  config.js           Constants, regex patterns, shared utilities
  parser.js           CodeParser: symbol, edge, and tag extraction
  mapper.js           ProjectMapper: file walking and graph generation
  reflections.js      ReflectionManager: lesson persistence
  initializer.js      ProjectInitializer: rule and reflection scaffolding
  install-log.js      Shared versioned install target logging
  mcp-server.js       MCP stdio server: 8 tools, structured errors, per-tool timeouts
  skills.js           SkillManager: platform skill installation
  agents.js           AgentManager: sub-agent registration
test/
  index.test.js       Unit tests for parser, mapper, skills, and CLI behavior
  mcp-server.test.js  Unit tests for MCP server tool handlers
  platform-audit.js   Integration checks across supported platforms

Pipeline

  • File Scanning: Recursively walks the directory while respecting nested .gitignore patterns.
  • Context Extraction: Scans for classes, functions, variables, and comments while stripping literals to reduce false matches.
  • Graph Extraction: Identifies imports, requires, extends, and implements edges.
  • Tag Extraction: Captures TODO, FIXME, BUG, and DEPRECATED tags from comments.
  • Reflection Management: Deduplicates and persists agent learnings into a standardized Markdown file.
  • Compilation: Writes a compact llm-code-graph.md file with capped descriptions, symbols, tags, and a dedicated ## EDGES section.

Keywords

llm

FAQs

Package last updated on 20 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts