GH-SEARCH-CODE(1) GitHub CLI manual GH-SEARCH-CODE(1)

# [NAME](#NAME)

gh-search-code - Search within code

# [SYNOPSIS](#SYNOPSIS)

**gh search code &lt;query&gt; \[flags]**

# [DESCRIPTION](#DESCRIPTION)

Search within code in GitHub repositories.

The search syntax is documented at:

⟨https://docs.github.com/search-github/searching-on-github/searching-code⟩

Note that these search results are powered by what is now a legacy GitHub code search engine. The results might not match what is seen on **github.com**, and new features like regex search are not yet available via the GitHub API.

For more information on handling search queries containing a hyphen, run **gh search --help**.

# [OPTIONS](#OPTIONS)

[**--extension** **&lt;string&gt;**](#extension)

Filter on file extension

[**--filename** **&lt;string&gt;**](#filename)

Filter on filename

[**-q**, **--jq** **&lt;expression&gt;**](#q)

Filter JSON output using a jq expression

[**--json** **&lt;fields&gt;**](#json)

Output JSON with the specified fields

[**--language** **&lt;string&gt;**](#language)

Filter results by language

[**-L**, **--limit** **&lt;int&gt; (default 30)**](#L)

Maximum number of code results to fetch

[**--match** **&lt;strings&gt;**](#match)

Restrict search to file contents or file path: {file|path}

[**--owner** **&lt;strings&gt;**](#owner)

Filter on owner

[**-R**, **--repo** **&lt;OWNER/REPO&gt;**](#R)

Filter on repository, in OWNER/REPO format

[**--size** **&lt;string&gt;**](#size)

Filter on size range, in kilobytes

[**-t**, **--template** **&lt;string&gt;**](#t)

Format JSON output using a Go template; see "gh help formatting"

[**-w**, **--web**](#w)

Open the search query in the web browser

# [JSON FIELDS](#JSON_FIELDS)

**path**, **repository**, **sha**, **textMatches**, **url**

# [EXIT CODES](#EXIT_CODES)

0: Successful execution

1: Error

2: Command canceled

4: Authentication required

NOTE: Specific commands may have additional exit codes. Refer to the command's help for more information.

# [EXAMPLE](#EXAMPLE)

```
# Search code matching "react" and "lifecycle"
$ gh search code react lifecycle
# Search code matching "error handling"
$ gh search code "error handling"
# Search code using raw search qualifiers as separate arguments
$ gh search code panic path:pkg language:go
# Search code matching "deque" in Python files
$ gh search code deque --language=python
# Search code matching "cli" in repositories owned by microsoft organization
$ gh search code cli --owner=microsoft
# Search code matching "panic" in the GitHub CLI repository
$ gh search code panic --repo cli/cli
# Search code matching keyword "lint" in package.json files
$ gh search code lint --filename package.json
```

# [SEE ALSO](#SEE_ALSO)

[**gh-search(1)**](/man/os/gh/gh-search.1)

Sep 2026

---

Document: gh-search-code(1) from gh 2.102.0-r0 (Chainguard OS)
Source: https://github.com/cli/cli
