GraphNav is an MIT-licensed, fully local code knowledge graph tool engineered to provide targeted context for AI coding agents within large Python codebases, particularly monorepos [S1, F2, F3]. It extracts a knowledge graph of a codebase, including cross-service call edges, and automatically updates this graph when source files change [S1, F5].
By default, GraphNav operates without requiring an API key, network access, or incurring any cost, ensuring that no data leaves the user's machine [S1, F3]. This design makes it suitable for environments with strict data privacy and security requirements, while enhancing the effectiveness of AI agents like Claude Code, OpenAI Codex, and GitHub Copilot by supplying them with precise, up-to-date code context [S1, F2, F12].
Overview
GraphNav addresses the challenge of understanding complex dependencies in large Python codebases, a problem often faced by developers and AI coding agents alike. Traditional tools like grep can identify mentions of a function but fail to map actual call relationships, leading to incomplete or inaccurate context 1. AI agents, which often rely on similar text-based search mechanisms, can inherit these limitations.
By building and maintaining a code knowledge graph, GraphNav provides a structural understanding of the codebase. This allows developers to quickly ascertain the impact of changes and enables AI agents to receive highly relevant, token-budgeted context packs, improving their ability to generate accurate code suggestions and refactorings [S1, F6]. Its local-first and MIT-licensed nature ensures accessibility and control for developers [S1, F1, F3].
Core Features and How It Works
Local-First and MIT-Licensed Operation
GraphNav is distributed under the MIT license, with its source code publicly available on GitHub [S1, F1]. Crucially, it operates fully locally by default, meaning it requires no API key, network access, or external services, and no user data ever leaves the local machine [S1, F3]. This design choice prioritizes privacy, security, and cost-free operation.
Monorepo Support and Cross-Service Links
Designed for modern development environments, GraphNav supports monorepos by building a comprehensive knowledge graph that includes cross-service call edges [S1, F2]. This capability allows developers and AI agents to understand dependencies that span multiple services within a single repository, providing a holistic view of the codebase structure.
Automatic Graph Updates on File Changes
Maintaining an up-to-date knowledge graph is critical for accuracy. GraphNav automates this process: when source files change, the tool detects these modifications and rebuilds the graph in the background before the next query [S1, F5]. This eliminates the need for manual re-runs or a persistent daemon for basic operation, ensuring the context provided is always current [S1, F5]. For eager, real-time updates, a watch command is available [S1, F14].
Token-Budgeted Context Packs
For efficient use with AI agents, GraphNav provides token-budgeted context packs. The graphnav context "<task>" command returns only the code relevant to the specified task, inline, without making an LLM call [S1, F6]. This minimizes token usage and focuses the AI agent on the most pertinent information.
Graph-Aware Ranking and Fuzzy Symbol Search
GraphNav employs a graph-aware ranking algorithm that combines BM25 text matching with relation-weighted call-edge expansion and a git-recency factor [S1, F8]. This approach helps surface the most relevant files, even if their text content doesn't directly match the query, by considering the code's structural relationships and recent modifications [S1, F8]. Additionally, find, neighbors, and impact commands feature fuzzy symbol search, which can identify closest-match symbols even when there are typos in the query [S1, F9].
Integration with AI Agents via MCP
GraphNav integrates with AI agents through the Model Context Protocol (MCP). The graphnav serve command runs an MCP server over standard I/O, allowing AI agents to natively call GraphNav's tools [S1, F7]. This server loads and caches the graph, automatically reloading it whenever graph.json changes, ensuring agents always work with the latest codebase representation [S1, F7].
Getting Started with GraphNav
Setting up GraphNav is a straightforward process, designed to get developers and their AI agents working with a code knowledge graph quickly.
Installation
GraphNav requires Python 3.11 or newer [S1, F13]. To install GraphNav, use pip:
pip install graphnavInitial Setup and Graph Building
After installation, navigate to your project's root directory (or a service subfolder within a monorepo) and run the graphnav command:
graphnavThis command automatically detects your project structure, builds the knowledge graph from your code's Abstract Syntax Tree (AST), and generates the necessary agent instruction files [S1, F3, F10].
Generated Agent Instruction Files
Upon initial setup, GraphNav generates specific instruction files to enable various AI agents to leverage the knowledge graph:
CLAUDE.md: For Claude Code [S1, F12].AGENTS.md: For OpenAI Codex CLI [S1, F12]..github/copilot-instructions.md: For GitHub Copilot [S1, F12].
These files direct the AI agents on how to interact with the GraphNav tools and utilize the generated context.
Enabling Optional Semantic Links
While GraphNav operates locally by default, developers can opt-in to richer semantic links using Large Language Models (LLMs). This is done by running graphnav map --semantic [S1, F11]. This feature sends your source code to a chosen LLM backend (such as Anthropic, OpenAI, Gemini, DeepSeek, or Ollama) to enrich the graph [S1, F11]. An API key for the selected LLM backend must be provided via a .env file located anywhere up the directory tree from your project, or within any service subfolder [S1, F11].
Using GraphNav with AI Agents
GraphNav enhances AI agent capabilities by providing structured, relevant code context. This moves beyond simple text search, allowing agents to understand code relationships.
Agent Instruction Files
The generated instruction files (CLAUDE.md, AGENTS.md, .github/copilot-instructions.md) guide AI agents on how to use GraphNav's capabilities [S1, F12]. These files contain instructions that prompt the agent to query the knowledge graph for context relevant to the current task.
Leveraging the MCP Server for Native Tool Calls
For AI agents that support the Model Context Protocol (MCP), GraphNav can run a server that allows native tool calls. This means agents can directly invoke GraphNav commands to retrieve context without manual intervention [S1, F7].
To configure an AI agent like Claude Code to use the GraphNav MCP server, you might add a configuration similar to this (example for Claude Code):
{
"mcpServers": {
"graphnav": { "command": "graphnav", "args": ["serve", "--root", "."] }
}
}When the MCP server is running, the graph is loaded once and cached, then automatically reloaded whenever graph.json changes, ensuring the agent always has access to the most current graph data [S1, F7].
Examples of Agent Queries and Context Retrieval
Developers can also directly query GraphNav to retrieve context. For instance, to get a token-budgeted context pack for a specific task, you would use:
graphnav context "<task>"This command returns relevant code snippets directly to the console, which can then be fed into an AI agent's prompt or used by the developer [S1, F6]. When integrated via MCP, the AI agent can execute such commands automatically based on its understanding of the task and the instructions provided.
Advanced Usage and Maintenance
GraphNav offers additional commands for continuous maintenance and direct developer queries.
Eager, Real-Time Graph Updates with graphnav watch
For environments where immediate graph updates are critical, the graphnav watch command runs a long-running daemon [S1, F14]. This daemon monitors the repository for file changes in real-time and keeps all graphs, symbol maps, bridge notes, and agent instructions continuously updated [S1, F14]. This ensures that any query, whether from a developer or an AI agent, always reflects the absolute latest state of the codebase.
Diagnosing Setup Issues with graphnav doctor
To assist with troubleshooting, GraphNav includes a self-diagnosing command: graphnav doctor [S1, F15]. This command validates the entire GraphNav setup, helping users quickly identify and resolve any configuration or indexing issues in one step [S1, F15].
Direct CLI Queries for Developers
Developers can interact directly with the knowledge graph using several command-line interface (CLI) commands:
find: Locates symbols within the codebase.neighbors: Shows immediate connections to a given symbol.impact: Helps understand the potential ripple effect of changes to a symbol.
These commands benefit from fuzzy symbol search, which falls back to closest-match results if an exact lookup misses a typo [S1, F9]. This makes direct queries more robust and user-friendly.
System Requirements and Provenance
GraphNav is built with Python and requires Python version 3.11 or newer to operate [S1, F13]. The tool is open-source and licensed under the MIT License, with its source code publicly available on GitHub [S1, F1]. This licensing model supports broad adoption and community contributions, providing a flexible solution for code knowledge graph generation.