Code Search
Sourcegraph code search is fast, works across all your repositories at any commit, and supports multiple search modes.Search modes
- Standard search
- Structural search
- Commit diff search
Standard search matches literal strings and regular expressions across all indexed files.Use the filter bar in the search UI to narrow results by repository, language, file path, and more.
Try it on open source
You can try Sourcegraph search on public repositories at sourcegraph.com/search. For example:- Search for repo:dgrijalva/jwt-go parsewithclaims to find all uses of the
ParseWithClaimsfunction
Code review: gain context on changed code
When reviewing a pull request, you often need to understand the full context of changed code—not just the lines in the diff.Workflow
Install the browser extension
Install the Sourcegraph browser extension for Chrome, Firefox, or Safari. This adds code navigation directly to GitHub, GitLab, and Bitbucket pull requests.
Open a pull request
Visit a pull request in your code host. With the browser extension active, you’ll see hover tooltips appear when you mouse over code in the diff.
Use Go to definition
Hover over any symbol in the diff—added, unchanged, or deleted code. Click Go to definition to jump to the symbol’s implementation, even if it’s in a different repository.
Explore code: understand an unfamiliar codebase
As a new developer on a project, or when working in an unfamiliar part of the codebase, Sourcegraph’s code navigation helps you orient quickly.Workflow
Search for the entry point
Search on Sourcegraph for the function or module you want to understand. Use the query bar on your organization’s Sourcegraph instance, or initiate a search from your editor or browser extension.
Navigate to the relevant result
Click through to the file. If the search returns many results, use the suggested filters below the search box or add filters like
lang:go or repo:my-org/my-service to narrow them down.Drill down with Go to definition
Click on any token and select Go to definition to navigate to its implementation. Continue drilling down depth-first until you’ve mapped the relevant call chain.
Try this on the open-source
node-jsonc-parser repository. Start at the getLocation function, follow Go to definition through visit, and continue until you reach createScanner.Debug issues: trace what changed
When you receive a crash report with a stack trace, diff search helps you quickly identify what changed that might have caused the problem.Workflow
Run a diff search on the crashing function
Take the function name from the top of the stack trace and run a diff search:Results show all commits that modified code matching that name, newest first.
Review recent changes
Scroll through the results. Each result shows the diff with context. Click on the commit message to view the full diff with code navigation enabled.
Drill into the change
Click on code in the commit diff to open the full file at the revision before or after the commit. Use Go to definition and Find references to understand how the change affected callers and behavior.
Learn how a function should be called
When you need to add a new feature that uses an unfamiliar function or library, looking at real-world call sites is more reliable than reading documentation that may be outdated.Workflow
Open a matching file
Find and click on a search result that looks like a relevant usage. If there are many results, narrow them using filters.
Find all references
Click on the function name in the file and select Find references to see all call sites across your codebase (and optionally, across public open-source repos).
Code Navigation
Sourcegraph provides two tiers of code navigation:Search-based code navigation
Search-based code navigation
Precise code navigation
Precise code navigation
Code Navigation docs
Set up precise code navigation and explore all navigation features.
Cody AI
Cody is Sourcegraph’s AI code assistant. Because Cody has access to your entire codebase as context, its answers are grounded in your actual code rather than general programming knowledge.- Chat
- Autocomplete
- Commands
Ask Cody questions about your codebase in natural language:
- “Where is the authentication middleware defined and how does it work?”
- “Explain the retry logic in the payments service”
- “What does this function return when the input is empty?”
Cody overview
Learn about all Cody capabilities and supported clients.
Cody quickstart
Install Cody in your editor and get started.
Deep Search
Deep Search is an agentic AI tool that answers complex questions about your codebase. It explores your code autonomously, running multiple searches and synthesizing the results into a comprehensive answer. Unlike Cody chat, Deep Search is designed for open-ended investigative questions where the answer requires exploring many files and understanding broad patterns:- “How does authentication work across all our services?”
- “Which repositories are still using the deprecated v1 API?”
- “Walk me through how a request flows from the frontend to the database”
@-mentions to scope Deep Search to specific repositories, directories, files, or symbols for faster, more focused results.
Deep Search docs
Learn how Deep Search agents work and how to get the best results.
Code Insights
Code Insights turns any Sourcegraph search query into a time-series visualization. Use dashboards to track engineering metrics, migration progress, and codebase health over time. Example insights:- Track how many repositories still use an old version of a library (and watch the number decrease as migrations land)
- Monitor the adoption of a new logging framework across all repos
- Track the number of
TODOcomments ortype: ignoreannotations over time - Measure vulnerability remediation progress after a CVE disclosure
Code Insights docs
Learn how to create insights and build dashboards.
Batch Changes
Batch Changes automates large-scale code changes across many repositories. You write a changeset specification describing what to change, Sourcegraph applies it, and you manage the resulting pull requests from a single interface. Common use cases:- Update an API after a library major version bump
- Apply a security patch to hundreds of repositories
- Rename a configuration key across all services
- Add required license headers to source files
Batch Changes docs
Learn how to create and manage large-scale code changes.