### Start MCP Server Source: https://colbymchenry.github.io/codegraph/reference/mcp-server Use this command to start the CodeGraph MCP server. Agents configured by the installer launch this automatically. ```bash codegraph serve --mcp ``` -------------------------------- ### Install Codegraph CLI Source: https://colbymchenry.github.io/codegraph Install the Codegraph command-line interface globally using npm. ```bash npx @colbymchenry/codegraph ``` -------------------------------- ### Install CodeGraph on Windows Source: https://colbymchenry.github.io/codegraph/getting-started/quickstart Use PowerShell's Invoke-RestMethod (irm) to download and execute the installation script for Windows. ```powershell irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex ``` -------------------------------- ### Install CodeGraph with npm Source: https://colbymchenry.github.io/codegraph/getting-started/quickstart Install CodeGraph globally using npm for projects that already have Node.js installed. This method supports zero-install or global installation. ```bash npx @colbymchenry/codegraph # zero-install, or: npm i -g @colbymchenry/codegraph ``` -------------------------------- ### Initialize and Index Project Source: https://colbymchenry.github.io/codegraph/guides/indexing Initializes the CodeGraph configuration and performs a full index of the project. Use this command when starting a new project with CodeGraph. ```bash cd your-project codegraph init -i # initialize + full index ``` -------------------------------- ### Initialize and Index Project Source: https://colbymchenry.github.io/codegraph/getting-started/your-first-graph Use `codegraph init -i` to create the .codegraph/ directory and build the full index for your project in one step. This is the starting point for new projects. ```bash cd your-project codegraph init -i # initialize + index in one step ``` -------------------------------- ### Install CodeGraph on macOS/Linux Source: https://colbymchenry.github.io/codegraph/getting-started/quickstart Use curl to download and execute the installation script for macOS and Linux. ```shell curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh ``` -------------------------------- ### CodeGraph CLI Commands Overview Source: https://colbymchenry.github.io/codegraph/reference/cli Provides a list of common CodeGraph CLI commands for installation, project management, indexing, and querying. ```bash codegraph # Run interactive installer codegraph install # Run installer (explicit) codegraph uninstall # Remove CodeGraph from your agents (inverse of install) codegraph init [path] # Initialize in a project (--index to also index) codegraph uninit [path] # Remove CodeGraph from a project (--force to skip prompt) codegraph index [path] # Full index (--force to re-index, --quiet for less output) codegraph sync [path] # Incremental update codegraph status [path] # Show statistics codegraph query # Search symbols (--kind, --limit, --json) codegraph files [path] # Show file structure (--format, --filter, --max-depth, --json) codegraph context # Build context for AI (--format, --max-nodes) codegraph callers # Find what calls a function/method (--limit, --json) codegraph callees # Find what a function/method calls (--limit, --json) codegraph impact # Analyze what code is affected by changing a symbol (--depth, --json) codegraph affected [files...] # Find test files affected by changes codegraph serve --mcp # Start MCP server ``` -------------------------------- ### Non-interactive CodeGraph Installation Source: https://colbymchenry.github.io/codegraph/getting-started/installation Install CodeGraph using command-line flags for scripting or CI environments. Options include auto-detection, explicit target lists, and project-local installations. ```bash codegraph install --yes # auto-detect agents, install global ``` ```bash codegraph install --target=cursor,claude --yes # explicit target list ``` ```bash codegraph install --target=auto --location=local # detected agents, project-local ``` ```bash codegraph install --print-config codex # print snippet, no file writes ``` -------------------------------- ### CodeGraph Status Output Source: https://colbymchenry.github.io/codegraph/guides/indexing Shows an example of the `codegraph_status` command output, specifically highlighting the 'Pending sync' section. This helps agents determine if the index is up-to-date. ```text codegraph_status → ## CodeGraph Status … ### Pending sync: - src/Widget.ts (edited 1200ms ago) ``` -------------------------------- ### Manage CodeGraph Watcher and Connection Source: https://colbymchenry.github.io/codegraph/reference/api Shows how to start and stop the file watcher for automatic synchronization and how to properly close the CodeGraph database connection. ```typescript cg.watch(); // auto-sync on file changes cg.unwatch(); // stop watching cg.close(); ``` -------------------------------- ### CI Hook Example Source: https://colbymchenry.github.io/codegraph/guides/affected-tests A bash script that captures affected tests from `codegraph affected --stdin --quiet` and runs them using `vitest`. ```bash #!/usr/bin/env bash AFFECTED=$(git diff --name-only HEAD | codegraph affected --stdin --quiet) if [ -n "$AFFECTED" ]; then npx vitest run $AFFECTED fi ``` -------------------------------- ### Get Impact Radius Source: https://colbymchenry.github.io/codegraph/reference/api Calculates the transitive impact of a change starting from a specific node up to a given depth. ```APIDOC ## getImpactRadius(id, depth) ### Description Calculates the transitive impact of a change from a given node up to a specified depth. ### Method `cg.getImpactRadius(id, depth)` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the node to start the impact analysis from. - **depth** (number) - Required - The maximum depth to traverse the call graph for impact analysis. ### Request Example ```typescript const impact = cg.getImpactRadius(results[0].node.id, 2); ``` ``` -------------------------------- ### Watch / Unwatch Source: https://colbymchenry.github.io/codegraph/reference/api Starts or stops the file watcher service, which automatically synchronizes the index on file changes. ```APIDOC ## watch() / unwatch() ### Description Starts or stops the file watcher for automatic synchronization on file changes. ### Method `cg.watch()` or `cg.unwatch()` ### Request Example ```typescript // Start watching for file changes cg.watch(); // Stop watching for file changes // cg.unwatch(); ``` ``` -------------------------------- ### Get Callers / Get Callees Source: https://colbymchenry.github.io/codegraph/reference/api Walks the call graph to find nodes that call a given node or are called by a given node. ```APIDOC ## getCallers(id) / getCallees(id) ### Description Walks the call graph to find callers or callees of a specific node. ### Method `cg.getCallers(id)` or `cg.getCallees(id)` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the node to find callers or callees for. ### Request Example ```typescript const callers = cg.getCallers(results[0].node.id); // const callees = cg.getCallees(results[0].node.id); ``` ``` -------------------------------- ### Staleness Banner Example Source: https://colbymchenry.github.io/codegraph/guides/indexing Displays the format of a staleness banner that CodeGraph prepends to agent responses when a referenced file has been edited but not yet indexed. This alerts the agent to potentially stale data. ```text ⚠️ Some files referenced below were edited since the last index sync — their codegraph entries may be stale: - src/Widget.ts (edited 800ms ago, pending sync) For accurate content of those specific files, Read them directly. The rest of this response is fresh. ``` -------------------------------- ### Initialize CodeGraph Project Source: https://colbymchenry.github.io/codegraph/getting-started/quickstart Navigate to your project directory and run the 'codegraph init -i' command to set up CodeGraph integration. ```bash cd your-project codegraph init -i ``` -------------------------------- ### Initialize and Index CodeGraph Project Source: https://colbymchenry.github.io/codegraph/reference/api Initializes a new CodeGraph project or opens an existing one, then indexes all files within the project. Includes an optional progress callback for the indexing process. ```typescript import CodeGraph from '@colbymchenry/codegraph'; const cg = await CodeGraph.init('/path/to/project'); // Or open an existing index: // const cg = await CodeGraph.open('/path/to/project'); await cg.indexAll({ onProgress: (p) => console.log(`${p.phase}: ${p.current}/${p.total}`), }); ``` -------------------------------- ### CodeGraph Query Commands with JSON Output Source: https://colbymchenry.github.io/codegraph/reference/cli Demonstrates how to use query commands like 'query', 'callers', and 'impact' with the '--json' flag for machine-readable output. ```bash codegraph query UserService --kind class --limit 10 ``` ```bash codegraph callers handleRequest --json ``` ```bash codegraph impact AuthMiddleware --depth 3 ``` -------------------------------- ### Index All Source: https://colbymchenry.github.io/codegraph/reference/api Performs a full indexing of all files within the project. Supports a progress callback to monitor the indexing status. ```APIDOC ## indexAll(opts) ### Description Performs a full index of the project, with an optional progress callback. ### Method `cg.indexAll(opts)` ### Parameters #### Request Body - **opts** (object) - Optional - Options for indexing. - **onProgress** (function) - Optional - A callback function that receives progress updates. It is called with an object containing `phase` and `current`/`total` counts. ### Request Example ```typescript await cg.indexAll({ onProgress: (p) => console.log(`${p.phase}: ${p.current}/${p.total}`), }); ``` ``` -------------------------------- ### Index Project Commands Source: https://colbymchenry.github.io/codegraph/guides/indexing Provides commands for managing the project index. Use `index` for a full re-index and `sync` for a fast, incremental update of changed files. ```bash codegraph index # full index of the whole project codegraph index --force # re-index from scratch codegraph sync # incremental — only changed files ``` -------------------------------- ### CodeGraph Initialization Source: https://colbymchenry.github.io/codegraph/reference/api Initializes a new CodeGraph project index or opens an existing one. This is the entry point for interacting with the CodeGraph API. ```APIDOC ## CodeGraph.init(path) / CodeGraph.open(path) ### Description Creates or opens a project index at the specified path. ### Method Static methods on the `CodeGraph` class. ### Parameters #### Path Parameters - **path** (string) - Required - The file system path to the project directory. ### Request Example ```typescript import CodeGraph from '@colbymchenry/codegraph'; // Initialize a new project index const cg = await CodeGraph.init('/path/to/project'); // Or open an existing index // const cg = await CodeGraph.open('/path/to/project'); ``` ``` -------------------------------- ### Re-index Project Source: https://colbymchenry.github.io/codegraph/getting-started/your-first-graph For existing projects, use `codegraph index` for a full re-index or `codegraph sync` for an incremental update of changed files. ```bash codegraph index # full index ``` ```bash codegraph sync # incremental update of changed files ``` -------------------------------- ### Run CodeGraph Queries Source: https://colbymchenry.github.io/codegraph/getting-started/your-first-graph Explore your code using `codegraph query` with various subcommands like `callers`, `callees`, `impact`, and `context`. Each query accepts `--json` for machine-readable output. ```bash codegraph query UserService # find symbols by name ``` ```bash codegraph callers handleRequest # what calls a function ``` ```bash codegraph callees handleRequest # what a function calls ``` ```bash codegraph impact AuthMiddleware # what a change would affect ``` ```bash codegraph context "fix the login flow" # build task-focused context ``` -------------------------------- ### CodeGraph Processing Stages Source: https://colbymchenry.github.io/codegraph/core-concepts/how-it-works Illustrates the sequential stages involved in CodeGraph's operation, from initial file parsing to context building for AI. ```text files → Extraction (tree-sitter) → DB (nodes/edges/files) ↓ Resolution (imports, name-matching, framework patterns) ↓ Graph queries (callers, callees, impact) ↓ Context building (markdown / JSON for AI consumption) ``` -------------------------------- ### Build Context Source: https://colbymchenry.github.io/codegraph/reference/api Generates contextual information, such as code snippets or markdown, for a given task, useful for AI integrations. ```APIDOC ## buildContext(task, opts) ### Description Builds contextual information for a given task, with options for format and depth. ### Method `cg.buildContext(task, opts)` ### Parameters #### Path Parameters - **task** (string) - Required - The description of the task for which context is needed. - **opts** (object) - Optional - Options for building context. - **maxNodes** (number) - Optional - The maximum number of nodes to include in the context. - **includeCode** (boolean) - Optional - Whether to include code snippets in the context. - **format** (string) - Optional - The desired output format ('markdown' or 'json'). ### Request Example ```typescript const context = await cg.buildContext('fix login bug', { maxNodes: 20, includeCode: true, format: 'markdown', }); ``` ``` -------------------------------- ### Sync Source: https://colbymchenry.github.io/codegraph/reference/api Performs an incremental update to the project index, reflecting recent file changes. ```APIDOC ## sync() ### Description Performs an incremental update to the project index. ### Method `cg.sync()` ### Request Example ```typescript await cg.sync(); ``` ``` -------------------------------- ### Check CodeGraph Index Status Source: https://colbymchenry.github.io/codegraph/getting-started/your-first-graph Run `codegraph status` to verify that the index is ready. It reports node/edge/file counts, the active SQLite backend, and the journal mode. ```bash codegraph status ``` -------------------------------- ### File Watcher Event Flow Source: https://colbymchenry.github.io/codegraph/guides/indexing Illustrates the sequence of events from a file modification to the index being updated, including the debounce mechanism. This process ensures the index stays synchronized with code changes during an agent session. ```text agent writes src/Widget.ts → watcher fires (event delivery: typically <100ms) → 2000ms debounce → sync runs; Widget.ts's nodes + edges are in the index → next agent query sees it ``` -------------------------------- ### Configure MCP Server for Codegraph Source: https://colbymchenry.github.io/codegraph/reference/integrations Add the MCP server configuration for Codegraph to your ~/.claude.json file. This specifies how Codegraph should be run as an MCP server. ```json { "mcpServers": { "codegraph": { "type": "stdio", "command": "codegraph", "args": ["serve", "--mcp"] } } } ``` -------------------------------- ### Uninstall CodeGraph Source: https://colbymchenry.github.io/codegraph/getting-started/installation Remove CodeGraph configuration, instructions, and permissions from all configured agents. Project indexes are left untouched and can be removed separately. ```bash codegraph uninstall ``` -------------------------------- ### Search and Analyze CodeGraph Data Source: https://colbymchenry.github.io/codegraph/reference/api Demonstrates searching for nodes, retrieving callers, building context for AI tasks, and determining the impact radius of a change within the CodeGraph. ```typescript const results = cg.searchNodes('UserService'); const callers = cg.getCallers(results[0].node.id); const context = await cg.buildContext('fix login bug', { maxNodes: 20, includeCode: true, format: 'markdown', }); const impact = cg.getImpactRadius(results[0].node.id, 2); ``` -------------------------------- ### Search Nodes Source: https://colbymchenry.github.io/codegraph/reference/api Searches for nodes within the project index using a full-text query. Returns an array of matching nodes. ```APIDOC ## searchNodes(query) ### Description Performs a full-text search for nodes within the project. ### Method `cg.searchNodes(query)` ### Parameters #### Path Parameters - **query** (string) - Required - The search term to find nodes. ### Request Example ```typescript const results = cg.searchNodes('UserService'); ``` ``` -------------------------------- ### Trace Affected Tests with Custom Filter Source: https://colbymchenry.github.io/codegraph/guides/affected-tests Use the `--filter` option with a glob pattern to specify which test files should be considered. ```bash codegraph affected src/auth.ts --filter "e2e/*" ``` -------------------------------- ### Auto-Allow Read-Only Tools Source: https://colbymchenry.github.io/codegraph/reference/integrations Optionally configure ~/.claude/settings.json to auto-allow specific read-only tools for Codegraph. This grants permissions for various Codegraph operations. ```json { "permissions": { "allow": [ "mcp__codegraph__codegraph_search", "mcp__codegraph__codegraph_callers", "mcp__codegraph__codegraph_callees", "mcp__codegraph__codegraph_impact", "mcp__codegraph__codegraph_node", "mcp__codegraph__codegraph_status", "mcp__codegraph__codegraph_files" ] } } ``` -------------------------------- ### Trace Affected Tests Source: https://colbymchenry.github.io/codegraph/guides/affected-tests Pass changed source files as arguments to `codegraph affected` to find relevant tests. ```bash codegraph affected src/utils.ts src/api.ts ``` -------------------------------- ### Close Source: https://colbymchenry.github.io/codegraph/reference/api Closes the database connection associated with the CodeGraph project index. ```APIDOC ## close() ### Description Closes the database connection. ### Method `cg.close()` ### Request Example ```typescript cg.close(); ``` ``` -------------------------------- ### Trace Affected Tests from Git Diff Source: https://colbymchenry.github.io/codegraph/guides/affected-tests Pipe the output of `git diff --name-only` to `codegraph affected --stdin` to process changed files. ```bash git diff --name-only | codegraph affected --stdin ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.