Shaf Lab

Code search

Finding functions or snippets in a codebase by text or meaning.

Code search is how you find functions, types, or snippets in a codebase by text or by meaning. It might be a fast regex over a tree, a typo-tolerant index, or an embedding search that can find 'the thing that retries HTTP calls' even if those words never appear. In a large repo, good search is often faster than asking a model to guess the file path.

Keyword search is still the default for exact symbols and error strings. Semantic search helps when you remember what the code does, not what it is called. Many teams use both: a lexical index for precise hits, and a vector index for 'find me something like this.'

Keep the index close to the repo and refresh it as the tree changes. A stale index is how people start believing a function was deleted when it only moved. For agent workflows, expose search as a tool with a tight result budget so the model is not dumped a hundred weakly related files.

If you can jump to a symbol in the editor, start there. Bring out a heavier search stack when the repo is large, or when agents need to look around without opening the whole tree.