Zero Labs
Industry News / AI

I Wasted Hours Letting AI Search My Codebase Then CodeGraph Changed Everything

Source · Towards AI By Shubham Choudhary

From the publisher’s feed, collected in the ZeroLabs newsroom.

CodeGraphThere is a strange kind of frustration that happens when you use AI coding tools on a large project.At first, it feels magical.You open Claude Code, Cursor, Codex CLI, or another AI coding assistant and ask something simple:“Where is authentication handled?”“Which files will break if I change this service?”Then you wait.The AI starts searching. It runs grep. It opens files. It scans folders. It reads the wrong file, then another wrong file, then a helper file, then a test file that is only slightly related. Sometimes it finally finds the right function. Sometimes it gives a confident answer that sounds useful but misses an important dependency buried somewhere else.That was my biggest problem with AI coding assistants: not that they were bad at coding, but that they wasted too much time understanding the codebase before doing the actual work.Then I found CodeGraph.CodeGraph is an open-source tool by Colby McHenry that gives AI coding agents semantic code intelligence. In simple words, it builds a local knowledge graph of your codebase so AI tools can understand symbols, relationships, call graphs, files, routes, and dependencies without blindly scanning everything again and again. It works with tools like Claude Code, Cursor, Codex CLI, and OpenCode, and it runs 100% locally.The Real Problem: AI Still Searches Code Like a Junior DeveloperMost AI coding tools are powerful, but their biggest weakness is context.When an AI agent enters a new repository, it does not automatically understand the architecture. It has to explore. It usually does this through tools like grep, glob, file reading, and search commands.That sounds fine for a small side project. But in a serious codebase, this gets expensive quickly.The AI may need to answer one question, but before answering it, it has to inspect many files. Every search, every file read, every exploration step consumes tokens, tool calls, and time. In bigger repositories, the agent can spend more effort finding context than solving the task.This is why AI coding sometimes feels slow and costly. The assistant is not only writing code. It is also repeatedly rebuilding its mental map of your project.CodeGraph solves this by doing something smarter: it indexes the codebase first.Instead of making the AI search from scratch every time, CodeGraph creates a pre-indexed code knowledge graph. That graph stores things like functions, classes, methods, imports, callers, callees, inheritance, routes, and file structure. Then the AI can query that graph directly.It is the difference between giving someone a library and giving them a catalog.What CodeGraph Actually DoesCodeGraph turns your codebase into a structured graph.That means it does not only look at text. It understands code structure. It can identify symbols, connect function calls to definitions, resolve imports, track relationships, and show what depends on what.Under the hood, CodeGraph uses tree-sitter to parse source code into ASTs, extracts code elements such as functions and classes, stores everything in a local SQLite database, and supports full-text search through FTS5. It also performs reference resolution so calls, imports, inheritance, and framework patterns become connected relationships instead of isolated text matches.That matters because code is not just text. Code is a network.A function calls another function. A controller is connected to a route. A service depends on a repository. A class extends another class. A small change in one utility file can break multiple test files.Traditional search can find words. CodeGraph can help reveal relationships.This is why the idea is powerful for AI coding agents. Instead of asking, “Which files contain the word login?” the agent can ask, “What calls this login function?” or “What is the impact radius if I change this symbol?”That is a much better way to work.Why It Is UsefulThe first big benefit is speed.CodeGraph’s README reports benchmark results across seven real-world open-source codebases, including VS Code, Excalidraw, Django, Tokio, OkHttp, Gin, and Alamofire. In those tests, CodeGraph showed average savings of about 35% cheaper cost, 59% fewer tokens, 49% faster time, and 70% fewer tool calls when compared with an agent answering architecture questions without CodeGraph.Those numbers explain the value immediately.If you use AI coding tools daily, fewer tokens and fewer tool calls are not just technical details. They mean less waiting, lower cost, and fewer moments where the agent gets lost in irrelevant files.The second benefit is accuracy.When AI has poor context, it guesses. Sometimes it guesses well, but sometimes it misses hidden dependencies. CodeGraph reduces that risk by giving the agent structured information about how code is connected.The third benefit is privacy.CodeGraph is local-first. It uses a local SQLite database and does not require external services or API keys. For developers working on private company repositories, client projects, or sensitive codebases, this is a major advantage.The fourth benefit is impact analysis.Before changing a function, you can ask what calls it, what it calls, and what may be affected. This is especially useful in large projects where one “small” change can break something far away.Why Developers Are Paying AttentionCodeGraph is becoming popular because it attacks one of the most painful parts of AI-assisted development: repeated codebase exploration.The AI coding ecosystem is moving fast. Developers are using Claude Code, Cursor, Codex, and other agents not only for autocomplete, but for real tasks: debugging, refactoring, feature development, test generation, and architecture analysis.But all these workflows depend on one thing: context.A smart model with weak context behaves like a talented developer who just joined the company five minutes ago. It may be capable, but it still needs to understand the system.CodeGraph gives the agent a map.That is why it feels practical. It is not trying to replace your editor. It is not another chatbot. It is infrastructure for AI coding tools. It gives them better code intelligence before they start making decisions.Another reason it is popular is broad language support. CodeGraph supports many languages, including TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Scala, Dart, Svelte, Vue, Liquid, and Pascal/Delphi. It also supports framework-aware route extraction across frameworks such as Django, Flask, FastAPI, Express, NestJS, Laravel, Rails, Spring, Gin, Axum, ASP.NET, Vapor, React Router, and SvelteKit.That makes it useful beyond one ecosystem.How to Use CodeGraphThe easiest way to start is with the interactive installer.npx @colbymchenry/codegraphThe installer can auto-configure supported agents such as Claude Code, Cursor, Codex CLI, and OpenCode. After installation, go to your project folder and initialize CodeGraph:cd your-projectcodegraph init -iThis builds the local knowledge graph index for your project.After that, restart your AI coding agent so the MCP server configuration loads properly. Once your project has a .codegraph/ directory, your agent can use CodeGraph tools automatically.You can also manually run useful commands:codegraph indexThis fully indexes the project.codegraph statusThis shows index health and statistics.codegraph query "UserService"This searches symbols by name.codegraph context "fix login bug"This builds relevant context for an AI task.codegraph affected src/auth.tsThis finds test files affected by changed source files.That last command is especially interesting for real development workflows. For example, you can pipe changed files from git and run only affected tests:git diff --name-only | codegraph affected --stdinIn CI or pre-commit workflows, that can save time by avoiding unnecessary test runs.A Simple ExampleImagine you are working on a login bug.Without CodeGraph, your AI agent may search for “login,” open several files, inspect route files, read services, open tests, and maybe eventually understand the flow.With CodeGraph, the agent can ask for context around the login task, identify the relevant symbols, inspect callers and callees, and understand the route-to-handler connection much faster.This changes the workflow from:“Search everything and hope we find the right files”to:“Ask the graph what matters”That is the core value.When CodeGraph Helps the MostCodeGraph is most useful when your project is not tiny.If you have a small repository with 20 files, regular search is usually enough. But if your project has hundreds or thousands of files, multiple modules, many dependencies, routes, services, tests, and shared utilities, CodeGraph becomes much more valuable.It is especially useful for Large projectsThe bigger the codebase, the more painful blind search becomes. That is exactly where CodeGraph shines.Final ThoughtsCodeGraph is useful because it solves a very real problem: AI agents waste too much time exploring codebases through repeated file search. By creating a local semantic knowledge graph, CodeGraph helps agents understand code structure, relationships, impact, and context faster.SourcesOfficial CodeGraph GitHub repo — features, setup, benchmarks, supported tools: https://github.com/colbymchenry/codegraphAlso worth reading 👀If CodeGraph feels like the missing intelligence layer for AI coding agents, OpenHuman feels like a similar missing layer for personal AI assistants.I also wrote about OpenHuman and why it may become the bridge between ChatGPT-style tools and real personal context, memory, and workflows. You can read it here:I Almost Ignored OpenHuman — Then I Realized It Might Be the Missing Layer Between ChatGPT and My…A quick note before you go 👋I break down real AI shifts before they hit the mainstream 🚀Click Follow now so you do not miss what matters next and drop a clap 👏 if this helped.I Wasted Hours Letting AI Search My Codebase Then CodeGraph Changed Everything was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.