---
name: ev-grep
description: Search code or text by behavior with ev-grep, including ast-grep candidates and scored JSON results. Use to locate evidence for a review or an authorized code-curation task.
---

# ev-grep

Use ev-grep to find code worth inspecting. It assesses supplied text with Jev; it does not review a repository, execute checks, or establish that a contract holds. Follow the requested scope before editing anything.

## Select inputs

Ask one concrete question and preview the selection before a broad search:

```sh
ev-grep 'Catches a database error and returns an empty result' src/ --dry-run --json
ev-grep 'Catches a database error and returns an empty result' src/ --json > results.jsonl
```

Normal paths assess whole files. `src/cache.ts:20-60` selects a line range with file context. `--stdin` assesses piped text as one candidate. `--query-file question.txt` supplies a longer query. Selected source goes to the configured provider; exclude credentials and unrelated files.

Use repeatable `--context PATH[:N-M]` for a specific helper needed to understand a candidate. Preview with `--dry-run
--json`: it shows the exact supporting sources. Supporting code can establish what the candidate does; an unrelated
match in a helper does not make the candidate a match. Candidate JSON can supply `supporting` directly; paths in JSON
are labels and are never opened implicitly. `context` still means the candidate's complete original file.

Use syntax to narrow candidates when it preserves the evidence needed for the question:

```sh
set -o pipefail
ast-grep run --lang javascript --pattern 'function $NAME($$$ARGS) { $$$BODY }' --json=stream src/ \
  | ev-grep 'Catches an error and returns an empty result' --candidates - --json
```

This selector omits methods and arrow functions. Inspect the selection and keep its coverage limits in the review. A file inventory, caller, or transaction boundary may matter more than a function body.

For an already assembled question and evidence, use `--state evidence.json` or `--state -`. This assesses one JSON
value, bounded to 64 KiB, with the generic question classifier. Paths inside the value are labels, not files to open.
Keep source, previous/current sides, provisional descriptions, and unknowns distinct. A full Tenet evidence packet
may exceed this bound; extract the relevant clause and source while retaining their references. Preview with
`--dry-run --json`, then read the `assessment` record and its raw answer, routing, and input identity. A `match` answers
your question; phrase it so its meaning is unambiguous. It is not automatically a defect.

ast-grep `metaVariables` are retained as bounded provenance but are not sent to the model. Named captures can help you
inspect the selected relationship; AST containment and textual order do not establish executable paths or ownership.

## Read results

Capture exit status and read errors and the final summary before filtering JSON. Exit 0 means matches; 1 means no matches, including an empty selection; 2 means errors; 3 means uncertainty. Files over 64 KiB are skipped as `too_large` without changing the exit code; add `--strict` to exit 2 on them. Earlier results can remain useful after an error, but the search is incomplete.

JSON Lines includes nonmatches. Each `result` has `data.file`, `range`, `text`, optional `context` and `supporting`, and
an `assessment` with raw `choice`, `confidence`, and probabilities for `match`, `no_match`, and `uncertain`. Separate
`routing` records the CLI's outcome and, when uncertain, `model_uncertain` or `low_confidence`. The latter explains the
threshold decision, not the model's reasoning. Check the schema version before consuming records. Preserve `begin`
and request metadata for the query, threshold, tool version, and content-derived prompt identity.

Match probability and provider confidence are different measures. Neither is a calibrated probability that your review is correct. `--min-confidence` routes low-confidence answers to uncertainty; it does not improve them. `--sort score` sorts after completion without changing scores or making more requests.

For review, retain uncertain and weak negative answers:

```sh
jq -c 'select(.type == "result") | .data
  | select(.routing.outcome != "no_match")' results.jsonl
```

This retains uncertainty under the recorded CLI policy. A caller can use a stricter floor from the raw assessment;
neither threshold is a guarantee. These candidate records can feed a second `--candidates` search. Do not discard
errors and then call the filtered set a complete review.

## Use findings during curation

Start from an actual requirement. Before asserting a defect, name the evidence that could disprove it: a caller's
guard, an enclosing transaction, or a dependency guarantee. Ask one behavioral question to locate that evidence,
then read the owning implementation. A helper can rely on its caller. Missing semantics leave a question unresolved;
a negative search alone does not establish the failing path. Stop when the question is settled or the evidence is
unavailable. Preserve concrete defects even when a separate dependency is unknown.

Use project tests and static checks for deterministic guarantees. For an authorized change, rerun the same query and
selection to understand its effect. Preserve the original result; repeating unchanged evidence is not verification.

A negative search cannot establish that a required file exists, that every dependency points the right way, or that related operations occur in order. Use the inventory and trace the owning flow. When using Tenet, let its contract inventory guide these questions, and carry the evidence back to the outer review. See the [Tenet usage skill](https://tenet-contracts.com/skill.md).

Use tenet-code-curation and tenet-architecture-curation when adopted, or the project’s own curation guidance. Record adopted ownership, data, and recovery requirements in scoped contracts when authorized. Keep contract-maintenance rules about scope and deliberate changes; avoid duplicating those rules inside every skill.

If a search exposes a recurring model weakness, retain a representative case in the existing eval suite with its query and relevant context. Keep tool errors separate from poor assessments. Save enough evidence to compare changes, explain unresolved findings, and stop once the original question is answered.

See `ev-grep --help` and the [output reference](https://ev-grep.com/docs/output) for exact options and record formats.
