GH-SEARCH-CODE(1)
π gh-search-code(1) β the GitHub CLI manual, bestie edition π
okay so bestie, you already know gh is that girl, and this page is all about looking for actual code inside GitHub repos. welcome to your new obsession β¨
β¨ NAME β¨
gh-search-code β search within code π΅οΈββοΈ
πΈ SYNOPSIS πΈ
gh search code <query> [flags]
π¦ DESCRIPTION π¦
Search within code in GitHub repositories. literally the whole vibe. π
the search syntax is documented at:
https://docs.github.com/search-github/searching-on-github/searching-code
β οΈ okay important heads-up, bestie: these search results are powered by what is now a legacy GitHub code search engine. so 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. iykyk, we don't make the rules π
for more info on handling search queries containing a hyphen, run gh search --help. (hyphens, always causing drama π)
π OPTIONS π
--extension <string>β filter on file extension π--filename <string>β filter on filename-q,--jq <expression>β filter JSON output using ajqexpression β¨--json <fields>β output JSON with the specified fields--language <string>β filter results by language θ―θ¨ π¦-L,--limit <int>(default30) β maximum number of code results to fetch. thirty is the default, she's not greedy π--match <strings>β restrict search to file contents or file path:{file|path}π--owner <strings>β filter on owner π-R,--repo <OWNER/REPO>β filter on repository, inOWNER/REPOformat--size <string>β filter on size range, in kilobytes π¦-t,--template <string>β format JSON output using a Go template; seegh help formattingπ§-w,--webβ open the search query in the web browser π (main character move, honestly)
π JSON FIELDS π
these are the fields you can ask for, no cap:
pathrepositoryshatextMatchesurl
β 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. (yes, go read the help, it's giving responsible π )
π₯ EXAMPLE π₯
okay these examples ate, honestly:
# 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 π
gh-search(1)β the sibling, go say hi π«Ά
that's the whole page, bestie, you're so welcome π this masterpiece was brought to you by GitHub CLI v2.102.0, dated Oct 2026 β written in GH-SEARCH-CODE(1) energy, slayed in manual-page form πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms