Problem
GitHub's web UI supports regex search via /pattern/ syntax (e.g. /from.*axios/), but the GitHub REST API (api.github.com/search/code) does not — confirmed by spike testing.
Currently, passing a regex query like /from.*axios/ to the CLI returns No results found because the API silently ignores the pattern.
Goal
Make regex queries work transparently in github-code-search by:
- Detecting
/pattern/ syntax in the query
- Automatically deriving a meaningful literal search term to send to the GitHub API (casting a wide net)
- Post-processing the raw API results locally with the original regex (narrowing to true matches)
- Displaying the regex mode clearly to the user
Real-world use cases driving this feature
- Semver audit —
filename:package.json /"axios":\s*"[~^]?[0-9]/ + --regex-hint axios — track which repos still use an old/vulnerable version of a dependency
- Deprecated library hunt —
/require\(['"]old-lib['"]\)/ or /from.*['"]old-lib['"]/
- TODO/FIXME triage —
/TODO|FIXME|HACK/ — surface all annotation types at once
- Import pattern matching —
/from.*['"]axios/ — find all axios import variants
Architecture
This is implemented in two steps:
Key design decision: deterministic buildApiQuery()
The query sent to the GitHub API is derived algorithmically — no AI involved, fully deterministic and testable:
| Input |
API query |
Logic |
/from.*['"]axios/ |
axios |
Longest literal sequence outside [...], quantifiers, alternations |
/TODO|FIXME|HACK/ |
TODO OR FIXME OR HACK |
Top-level alternation → GitHub OR operator |
/require\(['"]old-lib['"]\)/ |
old-lib |
Longest literal |
filename:package.json /["']axios["']:/ |
filename:package.json axios |
Qualifiers preserved, regex term extracted |
/[~^]?[0-9]+\.[0-9]+/ |
⚠️ warn + --regex-hint required |
No exploitable literal |
/useState/ |
useState |
Trivial case |
Known limitations (to be documented)
- Regex filtering applies to the first 1 000 results only (GitHub API hard cap)
- If
buildApiQuery() produces a very broad term, the API returns a lot of noise before filtering — --regex-hint lets the user override
- Flag
g has no effect (GitHub doesn't return all inline occurrences); flag i is applied client-side
Definition of Done (EPIC)
The EPIC is considered done when:
Problem
GitHub's web UI supports regex search via
/pattern/syntax (e.g./from.*axios/), but the GitHub REST API (api.github.com/search/code) does not — confirmed by spike testing.Currently, passing a regex query like
/from.*axios/to the CLI returns No results found because the API silently ignores the pattern.Goal
Make regex queries work transparently in
github-code-searchby:/pattern/syntax in the queryReal-world use cases driving this feature
filename:package.json /"axios":\s*"[~^]?[0-9]/+--regex-hint axios— track which repos still use an old/vulnerable version of a dependency/require\(['"]old-lib['"]\)/or/from.*['"]old-lib['"]//TODO|FIXME|HACK/— surface all annotation types at once/from.*['"]axios/— find all axios import variantsArchitecture
This is implemented in two steps:
src/regex.tsmodule +aggregate()regex filter--regex-hintescape hatch, docs, C4 diagramsKey design decision: deterministic
buildApiQuery()The query sent to the GitHub API is derived algorithmically — no AI involved, fully deterministic and testable:
/from.*['"]axios/axios[...], quantifiers, alternations/TODO|FIXME|HACK/TODO OR FIXME OR HACKORoperator/require\(['"]old-lib['"]\)/old-libfilename:package.json /["']axios["']:/filename:package.json axios/[~^]?[0-9]+\.[0-9]+/--regex-hintrequired/useState/useStateKnown limitations (to be documented)
buildApiQuery()produces a very broad term, the API returns a lot of noise before filtering —--regex-hintlets the user overrideghas no effect (GitHub doesn't return all inline occurrences); flagiis applied client-sideDefinition of Done (EPIC)
The EPIC is considered done when:
docs/architecture/components.md) shows the newregex.tscomponent in the CLI data pipelineAGENTS.mdmodule map updated withsrc/regex.tsdocs/usage/search-syntax.mdhas a "Regex queries" sectionbun run docs:buildcompletes without errors