aaddrick/gh-cli-search/gh-search-code
- community
Checking that the SKILL.md file is still in the repository.
Use when searching code across GitHub repositories - provides syntax for file extensions, filenames, languages, sizes, exclusions, and using -w flag for regex search via web interface
Install
npx vskill@latest install aaddrick/gh-cli-search/gh-search-codeSKILL.md
GitHub CLI: Search Code
Overview
Search for code across GitHub repositories using gh search code. Important: CLI API uses legacy search engine. For regex and advanced features, use -w flag to open in web browser.
When to Use This Skill
Use this skill when searching code across GitHub:
- Searching for code patterns across multiple repositories
- Finding specific file types or filenames in repos/orgs
- Locating code by language or file size across GitHub
- Searching in specific repositories or organizations
- Need to exclude certain results (requires
--flag) - Need regex search (use
-wto open in browser)
Syntax
Key Flags Reference
| Flag | Purpose | Example | |
|---|---|---|---|
--extension <string> | Filter by file extension | --extension js | |
--filename <string> | Target specific filenames | --filename package.json | |
--language <string> | Filter by programming language | --language python | |
--owner <strings> | Limit to specific owners | --owner microsoft | |
-R, --repo <strings> | Search within repository | --repo cli/cli | |
--size <string> | Filter by file size (KB) | --size ">100" | |
--match <strings> | Search in file or path | --match file or --match path | |
-L, --limit <int> | Max results (default: 30) | --limit 100 | |
-w, --web | Open in browser | -w | |
--json <fields> | JSON output | --json path,repository |
JSON Output Fields
Available fields: path, repository, sha, textMatches, url
Exclusion Syntax (Critical!)
When using inline query exclusions (negations with -), you MUST use the -- separator:
✅ Correct: gh search code -- "search-terms -qualifier:value" ❌ Wrong: gh search code "search-terms" --flag=-value ❌ Wrong: gh search code "search-terms" --flag=!value ❌ Wrong: gh search code "search-terms" --filename="!test"
Examples:
gh search code -- "function -filename:test"(exclude files named "test")gh search code -- "import -language:javascript"(exclude language)gh search code -- "config -path:vendor"(exclude vendor directories)gh search code -- "TODO -extension:md"(exclude extension)
Why the `--` separator is required: The -- tells the shell to stop parsing flags and treat everything after it as arguments. Without it, -qualifier:value inside quotes may be misinterpreted.
Understanding -filename: vs -path: Qualifiers
Critical Distinction: These qualifiers have different matching behaviors:
| Qualifier | Matches | Use When | |
|---|---|---|---|
-filename: | Filename only (e.g., test.js, utils_test.py) | Excluding files by their name pattern | |
-path: | Full file path (e.g., src/test/file.js, lib/testing/util.js) | Excluding directory paths or path segments |
When to Use Each
Use `-filename:` when:
- User says "exclude test files" → means files named with "test"
- Targeting files by their name pattern
- Examples:
test.js,config_test.py,utils.test.ts
Use `-path:` when:
- User says "exclude test directories" → means directories containing "test"
- Targeting files in specific directory paths
- Examples:
tests/,__test__/,src/test/,lib/testing/
Matching Examples
`-filename:test` matches:
test.js✅utils_test.py✅test_helper.rb✅src/file.js❌ (doesn't contain "test" in filename)tests/utils.js❌ (filename is "utils.js", not "test")
`-path:test` matches:
tests/utils.js✅ (path contains "test")src/test/file.js✅ (path contains "test")lib/testing/helper.py✅ (path contains "test")test.js✅ (path includes filename)src/utils.js❌ (path doesn't contain "test")
Practical Examples
Exclude files by name:
Exclude directories:
Combine both qualifiers:
Critical Syntax Rules
When to Use Flag Syntax vs Query Syntax
Decision Tree:
Flag Syntax (for positive filters):
Query Syntax with `--` (required for exclusions):
⚠️ NEVER mix both syntaxes in a single command!
1. Exclusions and Negations
CRITICAL: When excluding results, you MUST use query syntax with the -- separator.
Exclusion Syntax Rules:
- Use the
--separator before your query - Use
-qualifier:valueformat (dash prefix for negation) - Quote the entire query string
Examples:
Single exclusion:
Multiple exclusions:
Combine with positive filters using flags:
PowerShell exclusions:
Common Exclusion Patterns:
| User Request | Command | Qualifier Used | |
|---|---|---|---|
| "Find code but not in test files" | gh search code -- "function -filename:test" | -filename: (matches file names) | |
| "Code excluding test directories" | gh search code -- "function -path:test" | -path: (matches directory paths) | |
| "Code excluding specific language" | gh search code -- "import -language:javascript" | -language: | |
| "Code not in vendor/node_modules dirs" | gh search code -- "config -path:vendor -path:node_modules" | -path: (matches directories) | |
| "Functions excluding test and spec files" | gh search code -- "function -filename:test -filename:spec" | -filename: (matches file names) | |
| "Code excluding large files" | gh search code -- "class -size:>500" | -size: | |
| "Code not in specific extension" | gh search code -- "TODO -extension:md -extension:txt" | -extension: | |
| "Code excluding example/doc directories" | gh search code -- "api -path:examples -path:docs" | -path: (matches directories) |
2. Quoting Rules
Multi-word search:
Complex queries with qualifiers:
3. Size Comparisons
Use quotes for comparison operators:
Common Use Cases
Search for function patterns:
Find configuration files:
Search in specific repo:
Exclude files named with "test":
Exclude test directories:
Search by file size:
Use regex (via web):
Build complex query, refine in web:
Common Mistakes
| Mistake | Problem | Fix | |
|---|---|---|---|
--extension="NOT js" or --language=-python | Flag syntax doesn't support negation | Use query: -- "-extension:js" or -- "-language:python" | |
gh search code import -language:js | -language interpreted as flag | Use --: gh search code -- "import -language:js" | |
"function NOT language:js" | NOT keyword doesn't work | Use -: -- "function -language:js" | |
Mixing syntaxes: --language python "code -filename:test" | Can't mix flags with query qualifiers | Use query for all: -- "code language:python -filename:test" | |
| Not quoting multi-word queries | Searches separately | Quote: "error handling" | |
| Forgetting quotes on comparisons | Shell interprets > | Quote: --size ">100" | |
Using -filename inline without -- | Parsed as flag | Use --: -- "code -filename:test" | |
| Trying regex via CLI | CLI API doesn't support regex | Use -w flag: gh search code "pattern" -w | |
PowerShell without --% | Breaks with exclusions | Add: gh --% |
Installation Check
If gh command not found:
If not authenticated:
Web Browser Flag (-w/--web)
Important workaround for advanced features:
The -w/--web flag opens your search in GitHub's web interface, which supports features not available via CLI API:
Regex Search (Web Only)
When to Use -w
Use the web flag when you need:
- Regex patterns -
/pattern/syntax for complex matching - Advanced filters - Newer GitHub search features
- Visual browsing - Easier to explore results visually
- Better results - Web uses newer search engine
Combining CLI + Web
Limitations (CLI API)
- Powered by legacy GitHub search engine
- Results may differ from github.com
- Regex search not available via CLI (use
-wflag instead) - Some advanced features may not work
- Workaround: Use
-w/--webto access full GitHub search features
Related
- GitHub search syntax: https://docs.github.com/search-github/searching-on-github/searching-code
- For searching other resources:
gh-search-issues,gh-search-prs,gh-search-repos,gh-search-commits
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationPassed, 83 of 100Effective. 1 run. Evaluated 7 months ago.
Source
- SKILL.md in the repositoryCheckingskills/gh-search-code/SKILL.md
Popularity
- Repository stars
- 3
- 7-day trend score
- 7
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 2 Apr 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/aaddrick/gh-cli-search/gh-search-code)