This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
CodeGraph is a local-first code intelligence system that builds a semantic knowledge graph from any codebase. It provides structural understanding of code relationships using tree-sitter for AST parsing and SQLite for storage.
Key characteristics:
.codegraph/ directory# Build
npm run build # Compile TypeScript and copy assets
# Test
npm test # Run all tests once
npm run test:watch # Run tests in watch mode
# Clean
npm run clean # Remove dist/ directory
npx vitest run __tests__/extraction.test.ts # Run specific test file
npx vitest run __tests__/extraction.test.ts -t "TypeScript" # Run tests matching pattern
src/
├── index.ts # Main CodeGraph class - public API entry point
├── types.ts # All TypeScript interfaces and types
├── db/ # SQLite database layer
│ ├── index.ts # DatabaseConnection class
│ ├── queries.ts # QueryBuilder with prepared statements
│ └── schema.sql # Table definitions with FTS5 search
├── extraction/ # Tree-sitter AST parsing
│ ├── index.ts # ExtractionOrchestrator
│ ├── tree-sitter.ts # Universal parser wrapper
│ └── grammars.ts # Language detection and grammar loading
├── resolution/ # Reference resolver
│ ├── index.ts # ReferenceResolver orchestrator
│ ├── import-resolver.ts
│ ├── name-matcher.ts
│ └── frameworks/ # Framework-specific patterns (React, Express, Laravel, etc.)
├── graph/ # Graph traversal and queries
│ ├── index.ts # GraphQueryManager
│ ├── traversal.ts # GraphTraverser (BFS/DFS, impact radius)
│ └── queries.ts # High-level graph queries
├── context/ # Context building for AI assistants
│ ├── index.ts # ContextBuilder
│ └── formatter.ts # Markdown/JSON output formatting
├── sync/ # Incremental update system
│ ├── index.ts
│ └── git-hooks.ts # Post-commit hook management
├── installer/ # Interactive installer
│ ├── index.ts # Installer orchestrator
│ ├── banner.ts # ASCII art banner
│ ├── claude-md-template.ts # CLAUDE.md template generator
│ ├── config-writer.ts # Configuration file writing
│ └── prompts.ts # User prompts
├── mcp/ # Model Context Protocol server
│ ├── index.ts # MCPServer class
│ ├── tools.ts # MCP tool definitions
│ └── transport.ts # Stdio transport
└── bin/codegraph.ts # CLI entry point
CodeGraph (src/index.ts): Main entry point. Lifecycle methods (init, open, close), indexing (indexAll, sync), graph queries (traverse, getCallGraph, getImpactRadius), context building (buildContext)
ExtractionOrchestrator (src/extraction/index.ts): Coordinates file scanning, parsing, and storing. Uses tree-sitter native bindings for each supported language
GraphTraverser (src/graph/traversal.ts): BFS/DFS traversal, call graph construction, impact radius calculation, path finding
ReferenceResolver (src/resolution/index.ts): Resolves unresolved references after full indexing using framework patterns, import resolution, and name matching
SQLite database with:
nodes: Code symbols (functions, classes, methods, etc.)edges: Relationships (calls, imports, extends, contains, etc.)files: Tracked source files with content hashesunresolved_refs: References pending resolutionnodes_fts: FTS5 virtual table for full-text searchTypeScript, JavaScript, TSX, JSX, Svelte, Python, Go, Rust, Java, C, C++, C#, PHP, Ruby, Swift, Kotlin, Dart, Liquid, Pascal
NodeKind: file, module, class, struct, interface, trait, protocol, function, method, property, field, variable, constant, enum, enum_member, type_alias, namespace, parameter, import, export, route, component
EdgeKind: contains, calls, imports, exports, extends, implements, references, type_of, returns, instantiates, overrides, decorates
codegraph init [path] # Initialize in project
codegraph index [path] # Full index
codegraph sync [path] # Incremental update
codegraph status [path] # Show statistics
codegraph query <search> # Search symbols
codegraph context <task> # Build context for AI
codegraph hooks install # Install git auto-sync
codegraph serve --mcp # Start MCP server
Use these tools directly in the main session for fast code exploration (replaces the need for Explore agents in most cases):
| Tool | Use For |
|---|---|
codegraph_explore |
Deep exploration — comprehensive context for a topic in ONE call |
codegraph_context |
Quick context for a task (lighter than explore) |
codegraph_search |
Find symbols by name (functions, classes, types) |
codegraph_callers |
Find what calls a function |
codegraph_callees |
Find what a function calls |
codegraph_impact |
See what's affected by changing a symbol |
codegraph_node |
Get details + source code for a symbol |
CodeGraph provides code context, not product requirements. For new features, still ask the user about:
Releases are published to npm and mirrored as GitHub Releases on the
Releases page, which is
where most users look for change history. CHANGELOG.md at the repo root is
the source of truth — each GitHub Release's notes are extracted from it.
When the user asks for a changelog entry for a new version:
## [X.Y.Z] - YYYY-MM-DD block at the top of CHANGELOG.md
(directly under the intro, above the previous version).### Added, ### Changed, ### Fixed, ### Removed,
### Deprecated, ### Security — only include sections that have entries.[X.Y.Z]: https://github.com/colbymchenry/codegraph/releases/tag/vX.Y.ZAfter the changelog entry is written and the version is bumped in package.json:
git add package.json package-lock.json CHANGELOG.md
git commit -m "release: X.Y.Z (<one-line summary>)"
git push
npm publish
git tag vX.Y.Z
git push origin vX.Y.Z
gh release create vX.Y.Z \
--title "vX.Y.Z" \
--notes-file <(awk '/^## \[X.Y.Z\]/,/^## \[/{ if (/^## \[/ && !/X.Y.Z/) exit; print }' CHANGELOG.md)
Do not run npm publish, git tag, git push, or gh release create
yourself — these are publish actions that affect shared state. Write the file,
hand the user the commands.
Tests are in __tests__/ directory with files mirroring the module structure:
foundation.test.ts - Database, config, directory managementextraction.test.ts - Tree-sitter parsing for all languagesresolution.test.ts - Reference resolutiongraph.test.ts - Traversal and graph queriescontext.test.ts - Context buildingsync.test.ts - Incremental updates and git hooksTests use temporary directories created with fs.mkdtempSync and cleaned up after each test.