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 a jq expression ✨
  • --json <fields> β€” output JSON with the specified fields
  • --language <string> β€” filter results by language 语言 πŸ¦‹
  • -L, --limit <int> (default 30) β€” 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, in OWNER/REPO format
  • --size <string> β€” filter on size range, in kilobytes πŸ“¦
  • -t, --template <string> β€” format JSON output using a Go template; see gh 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:

  • path
  • repository
  • sha
  • textMatches
  • url

⭐ 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 🌈


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