Code search
Semantic Code Search vs. grep: When to Use Each
Use grep for literal text and semantic code search for callers, dependencies and cross-repository impact when changing code.
By Kivgraph ·
Kivgraph builds local semantic code intelligence for AI coding agents, with exact references, dependency paths and cross-repository impact.
Use grep for literal text and semantic code search for relationships between program entities. The two approaches solve different problems, and a good coding workflow keeps both available.
What grep does well
grep is fast, ubiquitous and often the cheapest way to answer a narrow question. The GNU grep manual defines it as a tool for printing lines that match a pattern, which is exactly why it is useful for literal text.
Typical literal-text questions include:
- Does this exact string exist?
- Which files mention a configuration key?
- Where is a log message written?
- Does a small repository contain a known token?
For a rare name or a simple absence check, text search can be the right first move. It has almost no setup cost and gives the agent raw evidence to inspect.
Where text search becomes ambiguous
Source code reuses names. A method, type or variable can appear in multiple packages and repositories. An occurrence can also be a comment, a string, a shadowed local variable or a different declaration with the same spelling.
Text search does not establish that one occurrence calls another. It also cannot naturally answer which dependency paths leave a repository or what is affected transitively by a change.
What semantic search adds
Semantic code search uses language-aware facts to connect declarations and references. The result can carry the repository, file, symbol, line range, confidence and provenance needed to decide whether the relationship is exact or unresolved.
Typical questions include:
- Who calls this function?
- Which declarations does this implementation reference?
- Which repositories consume this exported type?
- What reaches this package within two dependency levels?
Kivgraph exposes these questions through find_references, trace_dependencies and find_cross_repo_consumers.
The right workflow for an AI agent
Start with the cheapest method that can answer the question. Move to semantic tools when the question depends on identity or structure:
- Search text for literals, configuration and rare terms.
- Resolve the symbol when multiple declarations or imports are possible.
- Query references, dependencies or impact.
- Read only the returned source needed for the change.
This is not a claim that a graph wins every query. Kivgraph publishes a benchmark that includes the cases where grep is cheaper, as well as the cases where structural queries avoid repeated exploration.
A simple rule
If the question contains “where does this text occur?”, use grep. If it contains “what does this symbol mean?”, “who calls it?” or “what breaks if it changes?”, use semantic code search.