.nh .TH "GH-SEARCH-CODE" "1" "Oct 2024" "GitHub CLI 2.58.0" "GitHub CLI manual" .SH NAME gh-search-code - Search within code .SH SYNOPSIS \fBgh search code [flags]\fR .SH DESCRIPTION Search within code in GitHub repositories. .PP The search syntax is documented at: \[la]https://docs.github.com/search\-github/searching\-on\-github/searching\-code\[ra] .PP 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. .SH OPTIONS .TP \fB--extension\fR \fB\fR Filter on file extension .TP \fB--filename\fR \fB\fR Filter on filename .TP \fB-q\fR, \fB--jq\fR \fB\fR Filter JSON output using a jq expression .TP \fB--json\fR \fB\fR Output JSON with the specified fields .TP \fB--language\fR \fB\fR Filter results by language .TP \fB-L\fR, \fB--limit\fR \fB (default 30)\fR Maximum number of code results to fetch .TP \fB--match\fR \fB\fR Restrict search to file contents or file path: {file|path} .TP \fB--owner\fR \fB\fR Filter on owner .TP \fB-R\fR, \fB--repo\fR \fB\fR Filter on repository .TP \fB--size\fR \fB\fR Filter on size range, in kilobytes .TP \fB-t\fR, \fB--template\fR \fB\fR Format JSON output using a Go template; see "gh help formatting" .TP \fB-w\fR, \fB--web\fR Open the search query in the web browser .SH JSON FIELDS \fBpath\fR, \fBrepository\fR, \fBsha\fR, \fBtextMatches\fR, \fBurl\fR .SH EXIT CODES 0: Successful execution .PP 1: Error .PP 2: Command canceled .PP 4: Authentication required .PP NOTE: Specific commands may have additional exit codes. Refer to the command's help for more information. .SH EXAMPLE .EX # search code matching "react" and "lifecycle" $ gh search code react lifecycle # search code matching "error handling" $ gh search code "error handling" # 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 .EE .SH SEE ALSO \fBgh-search(1)\fR