Guide · wgrep 0.3.0
Search a local codebase
by meaning and exact text
Install wgrep, index one repository, and run a semantic query, a scoped query, and an exact text search. The example uses a two-file Python repository so you can check each step.
Before you start
The guide takes about five minutes. The first index build is the slow part.
- Windows x64, Linux x64, or macOS. The commands below use Windows PowerShell.
- PowerShell 5.1 or later, Git, and a local repository.
- Network access for the first
wg up. It downloads about 56 MB of model and parser assets. - No
rgbinary is needed. The ripgrep 15.1 engine is insidewg.
1. Download and unpack
Download the Windows archive from the latest release. The release page also has Linux and macOS archives.
The extracted folder has a build suffix. The wildcard below finds it.
The first wg up downloads the model and parser assets. Later runs use the local cache.
Invoke-WebRequest https://github.com/holdfast-labs/wgrep/releases/download/v0.3.0/wg-0.3.0-windows-x64.zip -OutFile wg-0.3.0-windows-x64.zip
Expand-Archive wg-0.3.0-windows-x64.zip -DestinationPath .
$dir = (Get-ChildItem wg-0.3.0-windows-x64-* -Directory)[0].FullName
$env:PATH = "$dir\bin;$env:PATH"
wg --version
wg 0.3.02. Create a small repository
The example creates a two-file Python repository in your home folder. Replace it with your own repository after the first run.
The files are deliberately small. The command order and output shape are the point.
$demo = "$env:USERPROFILE\wgrep-demo"
New-Item -ItemType Directory -Force "$demo\src" | Out-Null
git -C $demo init
@'
def validate_request(req):
if "token" not in req.headers:
raise ValueError("missing token")
return True
def handle_request(req):
validate_request(req)
return {"ok": True}
'@ | Set-Content "$demo\src\server.py"
@'
def add(a, b):
return a + b
'@ | Set-Content "$demo\src\maths.py"3. Attach the repository
Run wg up in the repository. Without a path, it uses the nearest Git ancestor or the current directory. It returns when the root is ready.
On Windows PowerShell, the progress line can appear in red. It is progress output, not an error. Use wg up --json in scripts.
wg status shows the attached root and index state.
cd $demo
wg up
Ready: 2 files, 2 chunks
Root: C:\Users\you\wgrep-demo
Build: 0.04s | Model setup: 0.00s | Total: 0.21s | PID: 56784
Text index: 0.02s | 2 files | 0.0 MB on disk | 0.0 MB residentwg statuspid=56784 models=1 roots=1
C:\Users\you\wgrep-demo [ready]: 2 files, 2 chunks, generation 1
text: ready [current], 2 files, 0.0 MB disk, 0.0 MB resident4. Search by meaning
The default route ranks code chunks from the live index. Write the behavior or symbol you expect to find.
--top accepts 1 to 100 and defaults to 5. --json returns a semantic JSON array. --explain adds score fields and requires --json.
Semantic results are ranked, not exhaustive. A correct answer can fall outside the shortlist. The fixture also returns src\maths.py as a weak second result.
wg "where are incoming requests validated" --top 3
src\server.py:1-8
def validate_request(req):
if "token" not in req.headers:
raise ValueError("missing token")
return True
def handle_request(req):
validate_request(req)
return {"ok": True}
src\maths.py:1-2
def add(a, b):
return a + b5. Limit the search with scope and filters
Version 0.3.0 adds semantic scope. Pass a file or directory after the query to search only that part of the attached root. A missing scope path acts as an empty scope.
Scope limits the candidate set. It does not remove weak matches. Use an exclude glob or a score cutoff to remove them.
Repeat --semantic-glob to include files. Prefix a pattern with ! to exclude files. Patterns without / match file names at any depth. Patterns with / are relative to the attached root. Windows also accepts native \ separators in root-relative patterns.
--min-score keeps chunks at or above a raw cosine score. There is no default cutoff. If nothing passes, JSON output is [] and the command returns exit 1.
wg "where are incoming requests validated" src --top 3
src\server.py:1-8
src\maths.py:1-2wg "where are incoming requests validated" --semantic-glob "*.py" --semantic-glob "!src/maths.py" --top 3src\server.py:1-8wg "where are incoming requests validated" --top 3 --min-score 0.35 --json[{"path":"src\\server.py","start":1,"end":8}]wg "teacher logits distilled into the student" trainers --semantic-glob "*.py"
wg "double surface topology loss" --semantic-glob "*.py" --semantic-glob "!tools/**"6. Switch to exact text
A ripgrep flag switches to the built-in ripgrep 15.1 engine. It runs inside the wg process. No rg binary is needed.
Always pass a path in scripts and agent commands. With no path, ripgrep reads stdin when stdin is a pipe.
The text route does not need wg up or a running daemon. An attached root adds trigram pruning. A fallback to a full scan changes speed, not results.
wg -n -F "validate_request" .
.\src\server.py:1:def validate_request(req):
.\src\server.py:7: validate_request(req)wg -n -e "fn\s+\w+\(" .
wg -g "*.py" "validate_request" .
wg --files .7. Use it from an agent
Ask for JSON and pass an explicit path on the exact route. Exit codes are 0 for a match, 1 for no match, and 2 for an error.
Use --top to bound the shortlist. Use -F or -e when the agent needs every match, not a ranking.
wg "where are requests validated" --json --top 5
wg --json -F "needle" .
wg status --jsonMeasured
Warm semantic query, p50: 25.2 ms for wgrep and 565.7 ms for the sgrep CLI. Rare identifier text search: 6.0 ms for wgrep and 63.8 ms for ripgrep 15.1. Workload: 13,332 Rust files on a Debian 13 VPS with 4 vCPU.
Know the limits
- The semantic route returns a ranked shortlist, not a complete result set.
- The text index only removes files that cannot match. Common terms and broad regexes still scan much of the tree.
- One daemon holds up to 32 attached roots.
wg downstops every root. - Semantic paths and arguments must be UTF-8. The text route passes non-UTF-8 arguments to the engine and falls back to a full scan when the index cannot represent a path.
Sources and related
Commands checked against wgrep 0.3.0 on Windows with a two-file fixture: wg up, wg status, a semantic query, scoped and filtered queries, --min-score, wg -F, and wg down.