PHPackages                             maarheeze/codegraph - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. maarheeze/codegraph

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

maarheeze/codegraph
===================

local php code indexing for ai assistants

1.3.2(2mo ago)183[1 issues](https://github.com/maarheeze/codegraph/issues)1MITPHPPHP &gt;=8.3

Since May 20Pushed 2mo agoCompare

[ Source](https://github.com/maarheeze/codegraph)[ Packagist](https://packagist.org/packages/maarheeze/codegraph)[ RSS](/packages/maarheeze-codegraph/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (9)Dependencies (8)Versions (10)Used By (1)

CodeGraph
=========

[](#codegraph)

**Make AI agents faster and cheaper to use on your codebase.**

CodeGraph indexes your PHP code structure (classes, methods, functions, and relationships) and stores it locally. AI agents query this index instead of reading files.

> Inspired by [colbymchenry/codegraph](https://github.com/colbymchenry/codegraph) and [kha333n/laravel-code-graph](https://github.com/kha333n/laravel-code-graph)

**Result:**

- ⚡ **Faster** — Queries in milliseconds instead of reading files
- 💰 **Cheaper** — Use fewer tokens, no need to pass file contents
- 🔍 **Accurate** — Structured data about code relationships, not guesses

Ask your AI agent questions directly:

- "Who calls this method?"
- "What breaks if I change this class?"
- "Show me all usages of this function"
- "What's the impact radius of this change?"

How It Works
------------

[](#how-it-works)

1. **Index your code** — `php vendor/bin/codegraph index` (one-time)
2. **AI agent uses it** — Register CodeGraph as an MCP server (works with Claude Code and any MCP-compatible AI)
3. **Faster context** — AI queries the index instead of reading files

Works with [Claude Code](https://claude.com/claude-code), [Cursor](https://cursor.sh), and any AI supporting MCP protocol.

Installation
------------

[](#installation)

```
composer require maarheeze/codegraph --dev
php vendor/bin/codegraph init
php vendor/bin/codegraph index
```

That's it. CodeGraph will:

1. Create a `.codegraph/` directory with SQLite database (should be ignored by git!)
2. Scan your code (`app/` and `src/` directories by default)
3. Extract symbols, relationships, and code structure
4. Build the index

**Optional: Auto-reindex on changes**

For continuous development, keep CodeGraph in sync automatically:

```
php vendor/bin/codegraph watch
```

This watches your code for changes and reindexes automatically. Press `Ctrl+C` to stop. To automatically initialize and index your codebase after dependencies are installed or updated, add the following to your `composer.json`:

```
{
  "scripts": {
    "post-autoload-dump": [
      "@php artisan codegraph:init || true",
      "@php artisan codegraph:index || true"
    ]
  }
}
```

Verify it worked:

```
php vendor/bin/codegraph status
```

This shows how many symbols, edges, and files were indexed.

Usage
-----

[](#usage)

### CLI Search

[](#cli-search)

```
php vendor/bin/codegraph search User
```

### Claude Code Integration

[](#claude-code-integration)

CodeGraph works with Claude Code via the MCP protocol.

**Automatic Setup (Recommended)**

Running `php vendor/bin/codegraph init` automatically:

1. Creates `.codegraph/` directory and SQLite database
2. Detects your environment (Sail, Docker, or plain PHP)
3. Configures `.mcp.json` with the correct MCP command
4. Adds CodeGraph guidelines to your `CLAUDE.md`

That's it! Claude Code will automatically discover and use CodeGraph's tools.

**Manual Setup (if needed)**

If you need to manually configure `.mcp.json`:

```
{
  "mcpServers": {
    "codegraph": {
      "command": "vendor/bin/sail",
      "args": ["php", "vendor/bin/codegraph", "mcp"]
    }
  }
}
```

Replace `vendor/bin/sail` with:

- `php` for plain PHP projects
- `docker` with args `["compose", "exec", "-it", "app", "php", "vendor/bin/codegraph", "mcp"]` for Docker Compose (replace `app` with your actual service name)

**Then ask Claude Code:**

- "Search for the User model"
- "Who calls the create method on User?"
- "What breaks if I change this service?"
- "Find all usages of the payment provider"

**Available tools:**

- `codegraph_search` — Find symbols by name or FQN
- `codegraph_callers` — Who calls a symbol
- `codegraph_callees` — What a symbol calls
- `codegraph_blast_radius` — Impact of changing a symbol
- `codegraph_search_chunks` — Full-text search across code

Commands
--------

[](#commands)

**`init`** — Initialize CodeGraph in your project

```
php vendor/bin/codegraph init
```

Optional: Explicitly set MCP configuration (auto-detected by default):

```
# Use Sail
php vendor/bin/codegraph init sail

# Use Docker Compose
php vendor/bin/codegraph init docker

# Use plain PHP (no Docker)
php vendor/bin/codegraph init php
```

If not specified, CodeGraph auto-detects your environment:

- Checks for `vendor/bin/sail` → uses Sail
- Checks for `docker-compose.yml` → uses Docker
- Falls back to plain PHP otherwise

**`index`** — Index your code (tracks changes, only re-parses what changed)

```
php vendor/bin/codegraph index
```

**`watch`** — Auto-reindex when files change (useful during development)

```
php vendor/bin/codegraph watch
```

**`status`** — See indexing statistics

```
php vendor/bin/codegraph status
```

**`mcp`** — Start MCP server (for Claude Code integration)

```
php vendor/bin/codegraph mcp
```

**`search`** — CLI symbol search

```
php vendor/bin/codegraph search User
```

Configuration
-------------

[](#configuration)

### Customize scan paths

[](#customize-scan-paths)

Default: `src/` and `app/`

```
php vendor/bin/codegraph index --path app --path lib
```

### Customize excludes

[](#customize-excludes)

Default: `vendor/`, `node_modules/`, `storage/`

```
php vendor/bin/codegraph index --path app --exclude tests --exclude migrations
```

### Re-index your code

[](#re-index-your-code)

CodeGraph tracks file hashes and only re-parses changed files:

```
php vendor/bin/codegraph index
```

To force full re-index:

```
rm -rf .codegraph
php vendor/bin/codegraph init
php vendor/bin/codegraph index
```

What Gets Indexed
-----------------

[](#what-gets-indexed)

**Symbols:** Classes, interfaces, traits, enums, methods, functions, properties

**Relationships:** Method calls, function calls, constructors, inheritance (`extends`/`implements`/`uses`), parent calls

**Metadata:** File paths, line numbers, visibility (public/protected/private), static/abstract markers, method signatures

Known Limitations
-----------------

[](#known-limitations)

- Dynamic class names (`new $className()`) are not resolved
- Variable method calls (`$obj->$method()`) are not detected
- Closures and callbacks are not indexed
- External/vendor code (Composer packages) is not indexed
- Template files (Blade, Twig, etc.) are not analyzed
- Service container resolution is not automatic

Roadmap
-------

[](#roadmap)

- **100% code coverage** — Comprehensive unit and integration tests
- **Index template files** — Support for Blade, Twig or HTML templates (core package or plugin TBD)
- **Extensive documentation** — Architecture guides, API reference, plugin development docs

Incremental Sync
----------------

[](#incremental-sync)

CodeGraph uses file hashing to detect changes:

```
php vendor/bin/codegraph index
```

Only files that changed since last index are re-parsed. This makes indexing fast on large codebases.

To see what changed:

```
php vendor/bin/codegraph status
```

API Usage (PHP)
---------------

[](#api-usage-php)

```
use Maarheeze\CodeGraph\CodeGraph;

// Initialize for current project
$codeGraph = CodeGraph::forProject();

// Get statistics
$stats = $codeGraph->stats();
echo "Symbols: " . $stats['symbols'];

// Index code
$indexStats = $codeGraph->index();
echo "Files indexed: " . $indexStats->getFilesChanged();

// Query the storage directly
$storage = $codeGraph->getStorage();
$symbols = $storage->findByName('User');
$callers = $storage->findEdgesTo('\App\Models\User::create');
$callees = $storage->findEdgesFrom('\App\Models\User::create');
$affected = $storage->blastRadius('\App\Models\User::create', depth: 3);
```

Database Schema
---------------

[](#database-schema)

CodeGraph uses SQLite with the following tables:

- `symbols` — All indexed symbols (classes, methods, functions, etc.)
- `edges` — Relationships between symbols (calls, inheritance, etc.)
- `chunks` — Code snippets indexed for full-text search
- `files` — File metadata (paths, hashes, timestamps)

Direct database queries are supported for custom analysis.

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance67

Regular maintenance activity

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

9

Last Release

64d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/734972e64c460b2142b0b04b4f40aa30077c5dd1915411b486ec72efcae3c3bf?d=identicon)[wietsewarendorff](/maintainers/wietsewarendorff)

---

Top Contributors

[![wietsewarendorff](https://avatars.githubusercontent.com/u/313525?v=4)](https://github.com/wietsewarendorff "wietsewarendorff (12 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/maarheeze-codegraph/health.svg)

```
[![Health](https://phpackages.com/badges/maarheeze-codegraph/health.svg)](https://phpackages.com/packages/maarheeze-codegraph)
```

###  Alternatives

[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k28.9M2.6k](/packages/infection-infection)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9224.3M28](/packages/phparkitect-phparkitect)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2603.2M442](/packages/ssch-typo3-rector)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k57](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
