Ditch Grep: How I Taught My AI Assistant to Truly Understand My Code
If youโve ever stepped into a massive, production-grade codebase, you know how challenging it can be to navigate. Files are scattered everywhere, functions call other functions across dozens of directories, and trying to change one line feels like playing Jenga in the dark.
When you start pair-programming with AI assistants to help you build features, you quickly run into a massive wall: how do you feed the AI the right code context? If you give it too much code, you waste tokens and the AI gets confused. If you use grep or standard text search to find things, you get flooded with hundreds of useless matches-comments, text strings, and functions with identical names in completely different files.
There has to be a better way. Moving beyond simple text search to AST-aware semantic analysis is a game-changer for AI pair programming. Here is how we achieved it using Serena MCP.
The Solution: Semantic Code Analysis (Serena)
Instead of just doing a basic text search, Serena is an MCP (Model Context Protocol) server that connects directly to the TypeScript Language Server (the same engine that runs Intellisense in your IDE). It doesn't just read letters; it actually understands what the code is doing.
Here are the three biggest ways this completely upgrades your AI coding workflow:
Semantic Precision (Goodbye, Grep Clutter)
If you search for a common helper function likegetUserUniqueIdusing a normal text search, you get flooded with dozens of matches from every controller across the codebase. Serena resolves this semantically. It knows whichgetUserUniqueIdfunction belongs to which controller. It filters out calls, imports, comments, and other files-returning only the exact definitions and calls you actually care about.Hyper-Targeted Snippets
If the AI needs to inspect a specific function, you normally have to read the entire file. Serena can fetch the exact boundaries of a function body (e.g. from line 15 to 93) and hand it to the AI. This keeps the prompt clean and focused.Empowering Smaller Models (
mimo-v2.5,minimax-m3)
One of the coolest side benefits of semantic analysis is how it democratizes AI pair programming for smaller, faster, or low-context LLMs. If you are using a lightweight model with a smaller context window (likemimo-v2.5orminimax-m3), you cannot throw massive 500-line controller files at it. By using Serena, the model can query only the specific 10-line block it needs, allowing cheaper and faster models to work on huge codebases just as effectively as high-end models.
How Does It Stay Updated When You Change Code?
If the AI writes new code, or you modify a file, how does Serena stay in sync? It happens in two ways:
Real-time File Watchers (LSP) : Because Serena is connected directly to the Language Server Protocol (LSP), it registers OS-level file watchers. The moment you save a file (or the AI writes a change), the language server detects the event, re-parses the file's Abstract Syntax Tree (AST) in memory, and updates its symbol index instantly.
Smart Incremental Caching : For startup, Serena stores symbol metadata on disk (under the project's
.serena/cache/folder). When the server starts up, it compares the current files against the cache. Instead of re-indexing the whole codebase, it only re-parses files whose modified timestamps (mtimes) or git hashes have changed, keeping startup times sub-second.
Serena vs. Other Codebase Indexers
During my research, I found a few other popular codebase-indexing MCP servers that developers use:
- mcp-codebase-index : A structural codebase indexer that parses Python, TypeScript/JS, Go, Rust, and C# files to analyze dependency graphs and navigate projects.
- ChunkHound : A local-first semantic code search tool that uses the tree-sitter library and DuckDB to run semantic vector and regex search on your code locally.
- codebase-memory-mcp : An open-source server that indexes codebases into a persistent knowledge graph, helping AI answer high-level structural questions with minimal token usage.
Unlike general vector search engines that use fuzzy semantic matching, Serena stands out by being compiler-aware (using TypeScript language server typings to build a deterministic AST). If you are working on large codebases with AI agents, moving beyond grep to compiler-aware tools is the single best upgrade you can make!
About the Author
This post was written by Jahangir Nasirwala. Jahangir is a software engineer passionate about exploring AI developer tooling, optimizing developer experience (DX), and building robust software workflows. Feel free to connect on LinkedIn!
Comments
No comments yet. Start the discussion.