You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if [ -f"$CHECKED_LOG" ] && grep -qF "$REL_PATH""$CHECKED_LOG"2>/dev/null;then
45
+
exit 0
46
+
fi
47
+
48
+
# Record that we've reminded for this file
49
+
mkdir -p "$(dirname "$CHECKED_LOG")"
50
+
echo"$REL_PATH">>"$CHECKED_LOG"
51
+
52
+
# Check if graph exists
53
+
if [ !-f"${CLAUDE_PROJECT_DIR:-.}/.codegraph/graph.db" ];then
54
+
exit 0
55
+
fi
56
+
57
+
# Inject reminder as additionalContext
58
+
cat <<HOOK_OUTPUT
59
+
{
60
+
"hookSpecificOutput": {
61
+
"hookEventName": "PreToolUse",
62
+
"permissionDecision": "allow",
63
+
"additionalContext": "[codegraph reminder] You are about to edit ${REL_PATH}. Did you run codegraph first? Before editing, always: (1) 'node src/cli.js where <name>' to locate the symbol, (2) 'node src/cli.js explain ${REL_PATH}' to understand the file, (3) 'node src/cli.js context <name> -T' for full context, (4) 'node src/cli.js fn-impact <name> -T' to check blast radius. If you already did this, proceed."
Copy file name to clipboardExpand all lines: CLAUDE.md
+25-7Lines changed: 25 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
4
5
+
> **Use codegraph before editing code.** This project has a pre-built dependency graph at `.codegraph/graph.db`. Before modifying any function or file, run `node src/cli.js where <name>` to locate it, `node src/cli.js explain <target>` to understand the structure, `node src/cli.js context <name> -T` to gather full context, and `node src/cli.js fn-impact <name> -T` to check blast radius. After staging changes, run `node src/cli.js diff-impact --staged -T` to verify impact. This saves tokens, prevents blind edits, and catches breakage before it happens. See the [Dogfooding](#dogfooding--codegraph-on-itself) section for the full command reference.
6
+
5
7
## Project Overview
6
8
7
9
Codegraph (`@optave/codegraph`) is a local code dependency graph CLI. It parses codebases with tree-sitter (WASM), builds function-level dependency graphs stored in SQLite, and supports semantic search with local embeddings. No cloud services required.
@@ -97,18 +99,34 @@ The workflow can be overridden with a specific version via the `version-override
97
99
98
100
## Dogfooding — codegraph on itself
99
101
100
-
Codegraph is **our own tool**. Use it to analyze this repository before making changes:
102
+
Codegraph is **our own tool**. Use it to analyze this repository before making changes. If codegraph reports an error, crashes, or produces wrong results when analyzing itself, **fix the bug in the codebase** — don't just work around it.
103
+
104
+
### Before modifying code, always:
105
+
1.`node src/cli.js where <name>` — find where the symbol lives
106
+
2.`node src/cli.js explain <file-or-function>` — understand the structure
107
+
3.`node src/cli.js context <name> -T` — get full context (source, deps, callers)
If codegraph reports an error, crashes, or produces wrong results when analyzing itself, **fix the bug in the codebase** — don't just work around it. This is the best way to find and resolve real issues.
125
+
### Flags
126
+
-`-T` / `--no-tests` — exclude test files (use by default)
127
+
-`-j` / `--json` — JSON output for programmatic use
128
+
-`-f, --file <path>` — scope to a specific file (partial match)
129
+
-`-k, --kind <kind>` — filter by symbol kind (function, method, class, etc.)
Copy file name to clipboardExpand all lines: README.md
+30-13Lines changed: 30 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ Most code graph tools make you choose: **fast local analysis with no AI, or powe
93
93
|**⚡**|**Always-fresh graph**| Three-tier change detection: journal (O(changed)) → mtime+size (O(n) stats) → hash (O(changed) reads). Sub-second rebuilds even on large codebases. Competitors re-index everything from scratch; Merkle-tree approaches still require O(n) filesystem scanning |
94
94
|**🔓**|**Zero-cost core, LLM-enhanced when you want**| Full graph analysis with no API keys, no accounts, no cost. Optionally bring your own LLM provider for richer embeddings and AI-powered search — your code only goes to the provider you already chose |
95
95
|**🔬**|**Function-level, not just files**| Traces `handleAuth()` → `validateToken()` → `decryptJWT()` and shows 14 callers across 9 files break if `decryptJWT` changes |
96
-
|**🤖**|**Built for AI agents**|13-tool [MCP server](https://modelcontextprotocol.io/) — AI assistants query your graph directly. Single-repo by default, your code doesn't leak to other projects |
96
+
|**🤖**|**Built for AI agents**|17-tool [MCP server](https://modelcontextprotocol.io/) — AI assistants query your graph directly. Single-repo by default, your code doesn't leak to other projects |
97
97
|**🌐**|**Multi-language, one CLI**| JS/TS + Python + Go + Rust + Java + C# + PHP + Ruby + HCL in a single graph — no juggling Madge, pyan, and cflow |
98
98
|**💥**|**Git diff impact**|`codegraph diff-impact` shows changed functions, their callers, and full blast radius — ships with a GitHub Actions workflow |
99
99
|**🧠**|**Semantic search**| Local embeddings by default, LLM-powered embeddings when opted in — multi-query with RRF ranking via `"auth; token; JWT"`|
@@ -132,7 +132,7 @@ Here is a cold, analytical breakdown to help you decide which tool fits your wor
@@ -141,7 +141,7 @@ Here is a cold, analytical breakdown to help you decide which tool fits your wor
141
141
#### Choose Codegraph if:
142
142
143
143
***You need the fastest possible incremental rebuilds.** Codegraph’s three-tier change detection (journal → mtime+size → hash) achieves true O(changed) when the watcher is running — only touched files are processed. Narsil’s Merkle trees still require O(n) filesystem scanning to recompute hashes on every rebuild, even when nothing changed. On a 3,000-file project, this is the difference between near-instant and noticeable.
144
-
***You want to optimize AI agent reasoning.** Large Language Models degrade in performance and hallucinate when overwhelmed with choices. Codegraph’s tight 13-tool surface area ensures agents quickly understand their capabilities without wasting context window tokens.
144
+
***You want to optimize AI agent reasoning.** Large Language Models degrade in performance and hallucinate when overwhelmed with choices. Codegraph’s tight 17-tool surface area ensures agents quickly understand their capabilities without wasting context window tokens.
145
145
***You are concerned about supply chain attacks.** To support 90 tools, SBOMs, and neural embeddings, a tool must pull in a massive dependency tree. Codegraph keeps its dependencies minimal, dramatically reducing the risk of malicious code sneaking onto your machine.
146
146
***You want deterministic blast-radius checks.** Features like `diff-impact` are built specifically to tell you exactly how a changed function cascades through your codebase before you merge a PR.
147
147
***You value a strong standalone CLI.** You want to query your code graph locally without necessarily spinning up an AI agent.
| 🧠 |**Semantic search**| Embeddings-powered natural language search with multi-query RRF ranking |
192
192
| 👀 |**Watch mode**| Incrementally update the graph as files change |
193
-
| 🤖 |**MCP server**|13-tool MCP server for AI assistants; single-repo by default, opt-in multi-repo |
193
+
| 🤖 |**MCP server**|17-tool MCP server for AI assistants; single-repo by default, opt-in multi-repo |
194
194
| 🔒 |**Your code, your choice**| Zero-cost core with no API keys. Optionally enhance with your LLM provider — your code only goes where you send it |
195
195
196
196
## 📦 Commands
@@ -391,7 +391,7 @@ Metrics are normalized per file for cross-version comparability. Times above are
391
391
392
392
### MCP Server
393
393
394
-
Codegraph includes a built-in [Model Context Protocol](https://modelcontextprotocol.io/) server with 13 tools, so AI assistants can query your dependency graph directly:
394
+
Codegraph includes a built-in [Model Context Protocol](https://modelcontextprotocol.io/) server with 17 tools, so AI assistants can query your dependency graph directly:
395
395
396
396
```bash
397
397
codegraph mcp # Single-repo mode (default) — only local project
Add this to your project's `CLAUDE.md` to help AI agents use codegraph:
408
+
Add this to your project's `CLAUDE.md` to help AI agents use codegraph (full template in the [AI Agent Guide](docs/ai-agent-guide.md#claudemd-template)):
409
409
410
410
```markdown
411
411
## Code Navigation
412
412
413
413
This project uses codegraph. The database is at `.codegraph/graph.db`.
414
414
415
-
-**Before modifying a function**: `codegraph fn <name> --no-tests`
416
-
-**Before modifying a file**: `codegraph deps <file>`
For AI-specific integration, see the **[AI Agent Guide](docs/ai-agent-guide.md)** — a comprehensive reference covering the 6-step agent workflow, complete command-to-MCP mapping, Claude Code hooks, and token-saving patterns.
475
+
459
476
## 🔁 CI / GitHub Actions
460
477
461
478
Codegraph ships with a ready-to-use GitHub Actions workflow that comments impact analysis on every pull request.
0 commit comments