Skip to content

Latest commit

 

History

History
 
 

README.md

CodeGraph C# — User Guide

What is it?

CodeGraph C# (v0.8.0) is a .NET 10 local-first code intelligence tool. It parses source code with tree-sitter, stores all symbols, relationships, and files in a SQLite (FTS5) database, and exposes them to AI agents (Claude Code, Cursor, Codex CLI, opencode) via the MCP protocol.

No Node.js required. Runs as a standalone dotnet tool.


Installation

Locally (developer mode)

cd csharp/
dotnet build CodeGraph.slnx
dotnet run --project src/CodeGraph.Cli -- --help

As a global dotnet tool

dotnet tool install -g CodeGraph.Cli
codegraph --help

Getting started in a project

1. Initialize

codegraph init /path/to/your/project
# or in the current directory:
codegraph init .

Creates a .codegraph/ directory with the database.

2. Index

codegraph index /path/to/your/project

Reads all source files, extracts symbols and relationships from the AST, and writes them to the database.

3. Configure your AI agent

codegraph install

4. Check status

codegraph status /path/to/your/project
Nodes:  4 832   (functions, classes, methods …)
Edges:  12 041  (calls, imports, extends …)
Files:  318
DB:     2.4 MB

CLI commands

Command Description
init [path] Initialize the .codegraph/ database
uninit [path] Delete the .codegraph/ directory
index [path] Full re-index
sync [path] Update only changed files (based on git diff)
status [path] Statistics: node, edge, and file counts
query <search> Search symbols by name (e.g. query "getUserById")
files [path] List indexed files
context <task> Build a Markdown context for a task
affected <file> Show what breaks if this file changes
unlock [path] Release WAL lock if the database is stuck
install Register the MCP server into an AI agent
serve --mcp Start the MCP server (stdio JSON-RPC)

Examples

# Search by symbol name
codegraph query "parseToken" --path ./myproject

# List files
codegraph files --path ./myproject

# Build context
codegraph context "authentication flow" --path ./myproject

# Find files affected by a change
codegraph affected src/auth/token.ts --path ./myproject

# Incremental sync
codegraph sync --path ./myproject

As an MCP server — for AI agents

Once the MCP server is running, the agent can query the knowledge graph through 9 tools.

Manual start (for testing)

codegraph serve --mcp --path /path/to/project

Automatic registration

codegraph install

An interactive menu lets you choose which agent and scope (local/global) to register into:

? Choose agent:
  ● Claude Code
  ● Cursor
  ○ Codex CLI
  ○ opencode

MCP tools (from the AI agent's perspective)

Tool When to use
codegraph_search Search symbols by name → returns their location
codegraph_context Call first — assembles context for a task (code + relationships)
codegraph_callers Who calls this function?
codegraph_callees What does this function call?
codegraph_impact What would break if I change this?
codegraph_node Details of one symbol (signature, source, docstring)
codegraph_explore Source of multiple related symbols in one call
codegraph_files File list at a given path
codegraph_status Index health

Framework-aware routes

CodeGraph recognizes web-framework routing files and creates route nodes linked by references edges to handler classes or functions. This means the callers list of a controller action also includes the URL pattern that binds it.

Framework Recognized patterns
ASP.NET [HttpGet("/x")], [HttpPost] attributes on action methods
Django path(), re_path(), url(), include() in urls.py
Flask @app.route('/path', methods=[...]), blueprint routes
FastAPI @app.get(...), @router.post(...)
Express app.get(...), router.post(...)
NestJS @Controller + @Get/@Post/...
Laravel Route::get(), Route::resource()
Rails get '/x', to: 'users#index'
Spring @GetMapping, @PostMapping, @RequestMapping
Gin / chi r.GET(...), router.HandleFunc(...)
Axum / actix .route("/x", get(handler))
Vapor app.get("x", use: handler)
React Router / SvelteKit Route component nodes

Multiple projects

The MCP server can manage multiple project databases at once. Pass a projectPath parameter to any tool to query a specific project's index:

codegraph_search("parseToken", projectPath="/home/user/project-b")

Configuration

The .codegraph/config.json file controls indexing behavior:

{
  "version": 1,
  "languages": [],
  "exclude": ["bin/**", "obj/**", "node_modules/**", "*.min.js"],
  "maxFileSize": 1048576
}
Option Description Default
languages Languages to index (empty = auto-detect) []
exclude Glob patterns to exclude ["bin/**", "obj/**", ...]
maxFileSize Skip files larger than this (bytes) 1048576 (1 MB)

Supported languages

Language Extensions
TypeScript .ts, .tsx
JavaScript .js, .jsx, .mjs
C# .cs
Python .py
Go .go
Rust .rs
Java .java
Kotlin .kt, .kts
C / C++ .c, .h, .cpp, .cc, .cxx, .hpp
Ruby .rb
PHP .php
Swift .swift
Dart .dart
Scala .scala, .sc
Pascal / Delphi .pas, .dpr, .dpk, .lpr, .dfm, .fmx
SQL .sql

Troubleshooting

"CodeGraph not initialized" — Run codegraph init . in the project directory.

Database stuck / database is locked — Run codegraph unlock to remove WAL lock files.

Missing symbols — Check that the file's language is supported and not excluded by config. Run codegraph sync manually.

MCP server not connecting — Verify the project is initialized and indexed, and that codegraph serve --mcp starts with the correct --path argument.


Typical workflow

1. codegraph init .          ← once, on first use
2. codegraph index .         ← initial index (~a few seconds)
3. codegraph install         ← register with your AI agent
4. codegraph sync .          ← refresh after code changes

After that, the agent automatically uses the codegraph_* tools whenever you search for symbols, trace call chains, or find affected code.