8 Powerful Ways to Function Search Across Codebase Efficiently
Part of the AI Code Quality guide. Start with How to Reduce AI Coding Mistakes: A Practical Guide
A match for formatPrice doesn't tell you whether you've found its definition or a file that calls it. And before you compare search tools, decide which copy of the code matters, because a result from the default branch may describe a helper you've changed locally, and you need to inspect the version your new caller will actually import.
ripgrep is where I'd start for a known name. When I don't know it, I want help finding candidates, followed by enough source code to check their behavior, because a promising signature doesn't settle how a helper handles missing inputs, or whether its defaults fit the new caller.
These are eight starting points. The commands and prompts below are search examples, with captured output identified separately.
| Tool | Start here when |
|---|---|
| ripgrep | You know a name or literal string in local files |
| ast-grep | You want a particular declaration shape |
| GitHub Code Search | You want definitions in a GitHub repository |
| VS Code | You're navigating symbols while editing |
| Cursor | You can describe the behavior but don't know its name |
| Claude Code | You want an agent to search and read candidates |
| Sourcegraph Code Search | You want to scope a query across repositories on your instance |
| Pharaoh (ours) | You want function metadata from a mapped TypeScript, JavaScript, Python, C or C++ repo |
1. ripgrep: search the files you have
ripgrep is my first choice for a known name. From the repository root, with rg installed, run:
rg -n --type ts '\bformatPrice\b' .
ripgrep's --type filter narrows the files searched, and -n includes line numbers, so when a name appears in several packages, you can open a hit at its reported location, then read enough of the source to check whether it is a definition. The current ts definition includes .tsx, as well as .ts, .cts and .mts.
ripgrep matches text. A declaration and a call can both match this query, as can a comment, so read the surrounding code before treating a hit as the helper you want, and check the search scope before treating an empty result as proof that it doesn't exist.
For a Python repository, change the file type:
rg -n --type py '\bformat_price\b' .
2. ast-grep: search a declaration shape
If you want named function declarations rather than every mention of a name, try ast-grep's pattern search, which matches syntax trees, lets metavariables stand in for names, and uses $$$ to match a sequence of nodes, including an empty sequence.
ast-grep run --lang ts --pattern 'function $NAME($$$ARGS): $RET { $$$BODY }' .
The run command accepts the language and pattern explicitly. Keep the single quotes so your shell doesn't expand $NAME.
A pattern matches one shape, type annotations included. This one needs a return type, so it skips a declaration without one (drop : $RET for those) and a generic one such as function first<T>(items: T[]): T. It also leaves out class methods and arrow functions, which need their own pattern, such as const $NAME = ($$$ARGS) => $BODY. To list every named function declaration whatever its annotations, match the node kind instead, with ast-grep run --lang ts --kind function_declaration ., which also finds async and generic declarations. And since ast-grep treats TSX as a separate language, you'll need another pass with --lang tsx for those files, even when the components sit beside your utilities, before treating the search as an inventory.
3. GitHub Code Search: ask for definitions
In GitHub's code search box, try:
repo:calcom/cal.diy language:TypeScript symbol:formatPrice
GitHub's symbol qualifier searches definitions, rather than references, and the repository and language qualifiers narrow the query, so you can look for the implementation in a specific project, without opening matches from every other repository on GitHub.
You need to sign in to use code search.
GitHub searches the default branch, and it leaves forks out by default, so this query names the upstream repository, calcom/cal.diy, rather than the Pharaoh-so/cal.diy fork used in the Pharaoh example below.
ripgrep is the better fit when you're checking a local change. A hosted definition can help you inspect a repository without opening a checkout, but it won't answer what your uncommitted version does, and finding a symbol doesn't establish that its behavior fits your task, even if the name looks perfect.
4. VS Code: navigate from the editor
Run Go to Symbol in Workspace, then enter formatPrice. The default shortcut is Cmd+T on macOS or Ctrl+T on Windows and Linux.
Workspace symbol search depends on language support, as does Go to Definition with F12, so when the editor resolves a call, you can follow it to the implementation, inspect the signature in context, and keep working in the same window.
ripgrep can provide a text-search check if the symbol picker is empty. Check the workspace you've opened and its language support before concluding the helper is absent.
5. Cursor: describe what you're looking for
Cursor's Agent searches with grep and Instant Grep, an index Cursor builds on your machine, and for a broad question it can hand the work to an Explore subagent that runs many searches in parallel. That gives you somewhere to start when you know the behavior, have no good guess at the name, and would otherwise be trying synonyms in a search box, one after another.
Try this prompt in Agent:
Find existing helpers that format a numeric price for display with a currency and locale. Show the definition paths and line ranges. Read the candidate implementations and explain their defaults. Don't edit files.
Treat the answer as a shortlist. Open the cited code, check which candidate handles the inputs you have, and ask for another search if the result looks like a nearby concept, because a plausible match still needs a source check.
6. Claude Code: ask it to investigate before writing
Claude Code can search local files and read them. Its current tool reference says the default tools vary by platform, with Glob and Grep absent by default on macOS, Linux and WSL, so on those systems the search can go through Bash, and a prompt that insists on specific tool names may be asking for tools the session doesn't expose.
The CLI accepts an initial prompt:
claude 'Locate the definition of formatPrice in this repository. Read it and show its path, line range, parameters and default values. Check the imports at one call site. Do not edit files.'
That's a request to the agent, not a recorded result or a permissions setting. Inspect its answer against the files it cites.
I want the search to end with an implementation I can review, with the caller's import checked too, because a matching name in another package may be irrelevant, and I don't want an agent to create a new helper just because its first search was too narrow.
7. Sourcegraph Code Search: scope repositories explicitly
On a Sourcegraph instance containing your organization's repositories, replace your-org in this query:
repo:^github\.com/your-org/ lang:typescript type:symbol formatPrice
The query syntax gives you repository and language filters, plus a symbol-search mode, and I would check the repository scope first, especially if the helper lives in a shared package, before digging through the returned definitions.
Forks are excluded by default. Add fork:yes if the repositories you need include forks.
This depends on which repositories are available on your instance. Check that coverage before interpreting a missing result, especially when a shared library has moved, a repository has been renamed, or your search was scoped to only part of the organization.
8. Pharaoh (ours): get function metadata over MCP
I build Pharaoh. It's a hosted MCP server for TypeScript, JavaScript, Python, C and C++ repositories, with a graph of functions and their relationships, and search_functions returns candidate signatures with paths and line ranges, module names, export status and complexity.
In a connected client, ask:
Call search_functions for cal.diy with query formatPrice and limit 8. Then open the matching implementation before proposing any new formatting helper.
Captured October 26, 2026 from repository Pharaoh-so/cal.diy, revision 54343aa6. The header and first result are unchanged; later results are trimmed:
# Search Results: "formatPrice" (showing 1-8)
- const formatPrice = (price: number, currency: string | undefined, locale = "en") => ... [exported, complexity: 3]
packages/lib/currencyConversions.ts:60-71 (lib)
The result names the helper and shows its locale default.
Open that file before reusing the helper. The signature leaves its implementation out, so the currency handling still needs a source check, and if the defaults don't fit your caller, you'll need to decide whether this is the right helper at all.
Pharaoh's graph covers the default branch. A push to that branch triggers a refresh for a live repository, and pharaoh_account can request a refresh before another push, but local edits and other branches aren't covered, so use local search to check work in progress.
If you don't know which module owns the helper, get_codebase_map shows the layout, while get_module_context supplies exported signatures and callers from other modules, so you can narrow the area you're investigating, then return to the implementation.
Before you add the function
ripgrep is often enough for a known name. For an unfamiliar behavior, ask an agent for candidates, inspect the definitions it finds, then check the import your new caller would use, rather than turning the first unsuccessful query into permission to write another utility.
For the workflow around that decision, see stop AI from writing duplicate functions.
To use the structural search above, connect a repository to Pharaoh. Install its GitHub App on the account or organization that owns the repository, connect your client, and sign in with GitHub, then ask for a helper you already know exists so you can check the result against its source.
Frequently asked questions about searching across a codebase
What is the best way to search for a function by name?
Use ripgrep from the repository root with a language filter, such as rg -n --type ts '\bformatPrice\b' .. It searches text, so inspect surrounding code to distinguish definitions from calls and comments.
How can I find function definitions instead of every name match?
Use a syntax-aware tool such as ast-grep with a declaration pattern or the function_declaration node kind. This can target declarations, but separate patterns or language passes may be needed for class methods, arrow functions, and TSX files.
Which tools can search functions across repositories?
GitHub Code Search, Sourcegraph, and Pharaoh can search hosted repositories with repository and language scope. Their coverage and branch behavior differ, so check the relevant repository scope before treating a missing result as proof that a function is absent.
How should I verify a function found by code search?
Open the cited implementation, read its signature and behavior, and check the import at a caller. A matching name may belong to another package or have defaults that do not fit your use case.
Article Record
ReferencesPrimary sources used for this article
- Code Navigation
- GUIDE.md
- About GitHub Code Search
- Understanding GitHub Code Search syntax
- ast-grep run | ast-grep
- Pattern Syntax
- List of Languages with Built-in Support
- Search Query Syntax - Sourcegraph docs
- Semantic & Agentic Search | Cursor Docs
- Improving agent with semantic search · Cursor
- Understanding Codebase like a Professional! Human–AI Collaboration for Code Comprehension
- Cross-Repository Code Navigation | Sourcegraph Blog
- CLI reference
- Tools reference - Claude Code Docs
Update HistoryMeaningful revisions to this article
- Added four frequently asked questions about searching across a codebase to help readers find practical answers more easily.