---
ref: tool:github/search-code
name: Search code
company: company:github
workflows: []
access: [mcp, cli, api]
tags: [capability:manage-code, category:code, has:api, has:cli, has:mcp]
docs: https://docs.github.com/en/rest/search/search#search-code
updated: 2026-09-26
---

# Search code

Returns files, and the repositories they live in, whose code matches a query such as an import of a package.

Note: The REST endpoint requires authentication and allows 10 requests per minute.

## Set up

Use the first option your agent supports.

### MCP (official, remote)

Add this server to your agent's MCP settings, then sign in when asked.

```json
{ "mcpServers": { "github": { "url": "https://api.githubcopilot.com/mcp/" } } }
```

Call the MCP tool `search_code`.

Server URL: https://api.githubcopilot.com/mcp/

### CLI (official)

Install the command and sign in with it, then confirm it runs.

```sh
brew install gh
gh --version
```

Run `gh search code`.

### API (official)

- Base URL: https://api.github.com
- Endpoint: `GET /search/code`
- Auth: send the header `Authorization: Bearer $GITHUB_TOKEN`
- Get a key: https://github.com/settings/personal-access-tokens/new
- Docs: https://docs.github.com/en/rest

Before anything else, confirm access with the cheapest read-only call, like a list or a search. Never send or change anything to test access.

## Rules

- Ask the user before anything that sends messages, costs money, or changes data, and say how many records it touches. One approval covers a batch the user has seen.
- Never print API keys.
