Code search
The Code Search tool lets agents search connected code repositories from Glean. Use it to find relevant files, diffs, code, and references for code-related questions.
Code Search is available in several Glean experiences. Glean can invoke it automatically for code-related questions, and you can add it explicitly as a By Glean tool in Agent Builder. Code Search is also available through the Glean MCP Server for supported third-party coding tools.
With Code Search, you can:
- Find and understand code by locating specific snippets, recent changes, and relevant files across connected repositories
- Generate code snippets and starting points based on examples in your codebase
- Debug by tracing recent commits and pull or merge requests that may have introduced an issue
- Check feature implementation status and find related documentation
Inputs
Configure Code Search in Agent Builder with a natural-language query or a fixed search pattern. You can optionally filter results by file extension.
| Input or setting | What to provide | Example |
|---|---|---|
| Search query | Describe the code, change, or implementation you want to find | recent changes in runtime config loading logic |
| Fixed query or template | Provide a precise search pattern or use variables in a query template | Find [[Feature name]] in the codebase |
| File extension | Limit results to a file type using the extension field | py |
Outputs
Code Search returns relevant code files, snippets, commits, pull or merge request diffs, and references from the connected repositories. The results become context for the agent, so follow Code Search with a Respond step to summarize findings or with another step that uses the code context.
Usage examples
- Debug errors: Ask what recent changes could have affected a component. Code Search can find relevant pull or merge requests, commits, and files for the agent to analyze.
- Confirm feature status: Ask whether a feature exists and how to enable it. The agent can locate feature flags, code paths, and related documentation.
- Get implementation guidance: Ask where to add or extend functionality. Code Search can find similar changes and example files.
Prerequisites
- Connect a supported code host, such as GitHub Cloud, GitHub Enterprise Server, or GitLab Cloud
- For self-hosted code hosts, ensure the instance is network-accessible to the Glean crawler running in your cloud
- Allow Glean to complete an initial crawl and indexing process before expecting all repository content to be searchable
Code Search respects the connected code host's permissions. Users can access only the code and repository content they are allowed to access in the source system.
Configuration
The steps below describe how to use Code Search as a tool in Agent Builder:
- Open Agent Builder and add a step.
- Select the Code Search tool under By Glean.
- Enter a natural-language query or a fixed query template.
- Optionally provide a file extension, such as
py, to focus the search. - Add a Respond step or another downstream step to summarize or use the results.
Code Search is enabled by default after a supported code host is connected. The previous admin toggle for the code tool has been removed.
Limitations
- Results are limited to repositories and content that the running user can access in the connected code host
- Newly connected or recently changed repositories may not appear until crawling and indexing complete
- Search quality depends on the specificity of the query and the available indexed code context