# colbymchenry/codegraph

### [codegraph](https://github.com/colbymchenry/codegraph)

> Pre-indexed code knowledge graph for Claude Code, Codex, Gemini, Cursor, OpenCode, AntiGravity, Kiro, and Hermes Agent — fewer tokens, fewer tool calls, 100% local.

Một repo trên github tạo ra một bản đồ code để AI Agent có thể dựa vào đó để có một cái nhìn tổng quan về code base. Truy cập nhanh và chính xác những phần code cần để sử dụng, không tìm kiếm lan man gây tốn token.

Codegraph làm việc với AI Agent thông qua MCP.

Có nhiều trường hợp AI Agent vẫn tự động dò code thay vì sử dụng codegraph. Để khắc phục mình thêm một phần vào [guidelines](https://knowledge.thanhdv.com/books/su-dung-ai-hieu-qua/page/guidelines "Guidelines") của AI Agent.

<details id="bkmrk-guidelines%23%23-code-ex"><summary>Guidelines</summary>

**\## Code exploration**

<span style="color: rgb(103, 150, 230);">-</span><span style="color: rgb(204, 204, 204);"> ALWAYS prefer using the </span>**\*\*codegraph\*\***<span style="color: rgb(204, 204, 204);"> MCP tools (</span><span style="color: rgb(206, 145, 120);">`codegraph\_context`</span><span style="color: rgb(204, 204, 204);">, </span><span style="color: rgb(206, 145, 120);">`codegraph\_search`</span><span style="color: rgb(204, 204, 204);">, </span><span style="color: rgb(206, 145, 120);">`codegraph\_trace`</span><span style="color: rgb(204, 204, 204);">, </span><span style="color: rgb(206, 145, 120);">`codegraph\_explore`</span><span style="color: rgb(204, 204, 204);">, </span><span style="color: rgb(206, 145, 120);">`codegraph\_node`</span><span style="color: rgb(204, 204, 204);">) to understand, navigate, and trace code whenever codegraph is available for the project (i.e. </span><span style="color: rgb(206, 145, 120);">`.codegraph/`</span><span style="color: rgb(204, 204, 204);"> is indexed).</span>

<span style="color: rgb(103, 150, 230);">-</span><span style="color: rgb(204, 204, 204);"> Reach for raw Read/Grep/Glob exploration only to confirm a specific detail codegraph didn't cover, or when codegraph is not available for the current project.</span>

</details>Ở các phiên bản mới codegraph đã tự động thêm vào guidelines rồi.

<details id="bkmrk-default-guidelines%3C%21"><summary>Default guidelines</summary>

<span style="color: rgb(106, 153, 85);">&lt;!-- CODEGRAPH\_START --&gt;</span>

**\## CodeGraph**

<span style="color: rgb(204, 204, 204);">In repositories indexed by CodeGraph (a </span><span style="color: rgb(206, 145, 120);">`.codegraph/`</span><span style="color: rgb(204, 204, 204);"> directory exists at the repo root), reach for it BEFORE grep/find or reading files when you need to understand or locate code:</span>

<span style="color: rgb(103, 150, 230);">-</span><span style="color: rgb(204, 204, 204);"> </span>**\*\*MCP tool\*\***<span style="color: rgb(204, 204, 204);"> (when available): </span><span style="color: rgb(206, 145, 120);">`codegraph\_explore`</span><span style="color: rgb(204, 204, 204);"> answers most code questions in one call — the relevant symbols' verbatim source plus the call paths between them, including dynamic-dispatch hops grep can't follow. Name a file or symbol in the query to read its current line-numbered source. If it's listed but deferred, load it by name via tool search.</span>

<span style="color: rgb(103, 150, 230);">-</span><span style="color: rgb(204, 204, 204);"> </span>**\*\*Shell\*\***<span style="color: rgb(204, 204, 204);"> (always works): </span><span style="color: rgb(206, 145, 120);">`codegraph explore "&lt;symbol names or question&gt;"`</span><span style="color: rgb(204, 204, 204);"> prints the same output.</span>

<span style="color: rgb(204, 204, 204);">If there is no </span><span style="color: rgb(206, 145, 120);">`.codegraph/`</span><span style="color: rgb(204, 204, 204);"> directory, skip CodeGraph entirely — indexing is the user's decision.</span>

<span style="color: rgb(106, 153, 85);">&lt;!-- CODEGRAPH\_END --&gt;</span>

</details>### Cách sử dụng cơ bản.

```markdown
# 1. Install the CLI (one-time)

**No Node.js required** — one command grabs the right build for your OS:

```bash
# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh

# Windows (PowerShell)
irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex
```

# 2. Wire up your agent(s) (one-time)

In a **new terminal**, run the installer to connect CodeGraph to the agents you use:

```bash
codegraph install
```

# 3. Work (each project)

```bash
cd your-project
codegraph init -i  
```

```bash
codegraph status
```

# 4. Uninstall

```bash
codegraph uninstall
```

# 5. Upgrade

```bash
codegraph upgrade
```
```

### Chú ý khác

Bạn không cần chạy `<span class="editor-theme-code">codegraph sync</span>` thủ công trong phiên làm việc của agent. Khi AI Agent khởi chạy `<span class="editor-theme-code">codegraph serve --mcp</span>`, chúng sẽ phối hợp để giữ cho `<span class="editor-theme-code">index</span>` luôn đồng bộ với `<span class="editor-theme-code">code</span>` - và không bao giờ đưa ra câu trả lời sai cho AI Agent.