New
Apps 6,419Makers 6,403This week 7
Promote your app−30%
jag screenshot 1
2views in
the last 30 days

jag

Grep for agents: rank the matches of a term by a question

Built with Claude Code

by ai-ready-future · Unclaimed · added Oct 29, 2026
no ratings0 comments

Grep with a model that ranks the matches by how well they answer your question. The package on crates.io is jag-cli. The command is jag.

Install

jag runs on Linux (x86_64 and arm64) and on macOS (arm64 and x86_64). Each way gives the same version.

1. Install the jag program

With npm (Node.js 18 or later):

$ npm install -g @airf/jag

2. Add the jag skill to your agent

A skill tells a coding agent how to use jag. To add it to your agent, after step 1:

$ npx skills add ai-ready-future/jag

The tool asks which agents get the skill and where it goes. To install for Claude Code with no question, add --agent claude-code -y. The tool writes skills-lock.json in the project. You write no instructions and edit no file.

jag sends no usage data. The skills tool, not jag, sends anonymous usage data and a security-audit request to skills.sh. DO_NOT_TRACK=1 stops both: DO_NOT_TRACK=1 npx skills add ai-ready-future/jag.

If your agent cannot install a skill, copy the instructions in Copy the instructions into an agent.

Other ways to install

With cargo (Rust 1.99 or later). This builds jag from source in some minutes:

$ cargo install --locked jag-cli

From GitHub Releases: download the archive for your system and its .sha256 file from the latest release. Then check the archive, open it, and move jag to a folder in your PATH:

$ sha256sum -c jag-<version>-<target>.tar.gz.sha256        # Linux
$ shasum -a 256 -c jag-<version>-<target>.tar.gz.sha256    # macOS
$ tar -xzf jag-<version>-<target>.tar.gz
$ mv jag-<version>-<target>/jag ~/.local/bin/

The targets are x86_64-unknown-linux-musl, aarch64-unknown-linux-musl, aarch64-apple-darwin, and x86_64-apple-darwin.

On macOS, a browser marks each file that it downloads, and macOS then stops jag. Download with curl -LO, or remove the mark: xattr -d com.apple.quarantine jag.

Or run jag with no install:

$ npx @airf/jag --help

The jag skill runs the command jag, so an agent needs one of the installs above.

On Linux, a question to the model needs the CA certificates of the system (the package ca-certificates).

Copy the instructions into an agent

If your agent cannot install a skill, copy the text below into the instructions of the agent. It is the text of the jag skill, with no frontmatter. The agent also needs the jag program (step 1 of Install).

# Search with jag

This file tells you what jag is, how to run it, how to read its output, and
what to do when it cannot run.

## What jag is

jag is an enhanced rg. It has the same command form as rg: a term and a
path. Use jag in place of rg for each search of code or text files.

jag adds the option `--ask`. With `--ask` and a question in plain language,
jag ranks the matching lines by how well they answer the question. Without
`--ask`, jag finds the lines as rg does.

## How to run jag

Run the command in a shell. There are two forms.

Without a question, jag finds the lines as rg does. It makes no call to the
model and it costs nothing:

```
jag --json --max-chars 8000 retry .
```

With a question, jag ranks the matching lines by how well they answer it. It
makes a call to the model, and the call costs money:

```
jag --json --max-chars 8000 --ask "Where does the code retry a failed request?" retry .
```

It is up to you to use `--ask` or not.

- `--json` is present in each command. jag then writes one JSON document on
  standard output.
- The term is one broad word or a short regular expression, for example
  `retry`.
- The question is one clear sentence in plain language. A question that
  starts with `-` needs the form `--ask="QUESTION"`.
- The path is present in each command, for example `.`. Without a path, jag
  can wait for text on standard input that does not come.
- `--max-chars N` is present in each command. It sets the size limit of the
  output. The limit counts characters, not tokens. Choose N from the text
  that you can read now. The smallest value is 1,000. The default is 20,000.
- The options `-i`, `-w`, `-F`, and `-g GLOB` work as they do in rg.
- Do not pipe the output into `head` or a similar command. The limit already
  keeps the output short, and a cut document is not valid JSON.
- Do not run `jag --check` before a search. It makes a paid call. Run the
  search and read the exit code.

## How to read the output

Read `exit_code` first. Then read `results` in the order that jag gives.
The first result is the best.

- Each result has `path`, `first_line`, and `last_line`. Open `path` from
  `first_line` to `last_line` before you change code.
- Each line of a result has `number`, `text`, and `is_match`. `is_match` is
  true for the lines that hold the term. Cite a line as `path:number`.
- `no_good_answer` is true when no result answers the question well.
  `results_found` is the count of results that matched the term.
- `left_out` is the count of results that the size limit left out. When it is
  more than 0, `size_limit_fix` tells how to get the rest. Raise the number of
  `--max-chars`, or use a narrower term or path.
- `warnings` lists paths that jag could not search.
- When `error` is not null, the search failed. `error.cause` tells why and
  `error.fix` tells what to do. `results` is then empty. Do not use it as a
  result.

## What each exit code means

| Code | Meaning | What to do |
|---|---|---|
| 0 | Results found | Read `results` |
| 1 | No match, or no good answer | If `no_good_answer` is true, the term matched, but no result answers the question: say so. If `results_found` is 0, the term matched nothing: try a broader term, or another path |
| 2 | Usage error, or a path that does not exist | Read `error.fix`. If `error` is null, read `warnings`. Fix the command and run it again |
| 3 | The key is missing or cannot be used | jag cannot run: see the next section |
| 4 | The service does not accept the key | jag cannot run: see the next section |
| 5 | The account has no credit | jag cannot run: see the next section |
| 6 | The service is down | jag cannot run: see the next section |
| 7 | The cost limit was reached | The results are valid. Use them. For more, use a narrower term or path |
| 8 | The size limit left out results | The results are valid. Use them. For more, follow `size_limit_fix` |
| 126 | jag did not start | jag cannot run: see the next section |
| 127 | jag was not found | jag cannot run: see the next section |
| 130 | The user stopped the search | Stop. Do not run jag again until the user asks |

## When jag cannot run

jag cannot run when the exit code is 3, 4, 5, 6, 126, or 127, or when the
shell says `command not found`. Do this one time in the task:

- For 3, 4, 5, and 6, give `error.cause` and `error.fix` to the user as jag
  writes them.
- For 126, 127, and `command not found`, tell the user that jag is not
  installed. Do not install it yourself. Give the user the install steps at
  https://github.com/ai-ready-future/jag#install. One way is
  `npm install -g @airf/jag`.
- For 3 and 4, the user does the fix in their own terminal. `error.fix` says
  how: for example, it can name `jag --setup`. Do not run `jag --setup`
  yourself.

Do not run jag again in this task, unless the user says that the fix is
done. For 6, do not run jag again at once: jag already tried again in the
same run.

The key is secret. Never ask the user for the key in the chat. Never put a
key in a command. Never read or print the files in `~/.config/jag/`.

Store your TypeSafe key

Get a key at https://console.typesafe.ai/keys. Then run:

$ jag --setup

jag --setup asks for the key. The terminal shows no echo. It stores the key in ~/.config/jag/config.yml. It needs a terminal. With no terminal, set JAG_TYPESAFE_API_KEY instead.

To remove the stored key:

$ jag --forget-key

Where jag looks for the key

jag uses the first key that it finds, in this order:

  1. the variable JAG_TYPESAFE_API_KEY
  2. the variable TYPESAFE_API_KEY
  3. the file ~/.config/jag/config.yml

The file has this form. The key goes under config:, not at the top level:

config:
  api-key: <your key>

jag refuses a config file that other users can read. Run chmod 600 on it. jag never shows the key.

This order is for the TypeSafe key. To use an AI gateway in place of the TypeSafe API, see "Use an AI gateway".

Use an AI gateway

jag can send the model calls to an AI gateway. Set the address of the gateway and the model name that the gateway uses. For each of the two settings, jag uses the first source that is set:

Setting Option Variable Config file
The address --base-url URL JAG_BASE_URL config.base-url
The model name --model NAME JAG_MODEL config.model

The default address is https://api.typesafe.ai/v1. The default model is jev-1.13.0. A blank value counts as not set. The address must be an https address, with no user name and no ? or #. http is allowed only for 127.0.0.1, localhost, and [::1]. jag adds /v1 when the path of the address does not end with /v1.

These gateways take the TypeSafe model:

Gateway JAG_BASE_URL JAG_MODEL
OpenRouter https://openrouter.ai/api ~typesafe/jev-latest
Vercel AI Gateway https://ai-gateway.vercel.sh/typesafe typesafe-ai/jev
Pydantic AI Gateway https://gateway-us.pydantic.dev/proxy/typesafe jev-latest

The TypeSafe key goes only to the TypeSafe API. For any other address, jag sends a gateway key, and it never sends the TypeSafe key. jag uses the first gateway key that it finds:

  1. the variable JAG_GATEWAY_API_KEY
  2. config.gateway-api-key in ~/.config/jag/config.yml
config:
  api-key: <your TypeSafe key>
  gateway-api-key: <your gateway key>
  base-url: https://openrouter.ai/api
  model: "~typesafe/jev-latest"

Put a model name that starts with ~ in quotes, in the shell and in the file. An example search through a gateway:

$ jag --base-url https://openrouter.ai/api --model "~typesafe/jev-latest" --ask "how long is the wait" retry src

When JAG_BASE_URL or config.base-url names a gateway, jag --setup and jag --forget-key work on the gateway key. They keep the other values of the file. With no gateway key, a search stops with exit 3 before the call. --check follows the same settings and the same key as a search, and it accepts --base-url and --model.

To store or remove the key of the other route, name that route for the one command. For example, to store the TypeSafe key while a gateway is set:

$ JAG_BASE_URL=https://api.typesafe.ai jag --setup

Check that jag is ready

$ jag --check [--base-url URL] [--model NAME]

The check shows pass or fail for five items, in this order:

  1. a key is present
  2. the service accepts the key
  3. the account has credit
  4. the service is reachable
  5. other users cannot read the key file

An item that jag cannot examine, because an earlier item failed, shows not checked. Each item that fails has its cause and its fix on the error stream. The check makes one small call to the model service. The call costs less than $0.00001. --timeout, --retry-wait, --base-url, and --model apply to the call. On a gateway, item 1 names the gateway key, and the texts say "gateway".

When all five items pass, the check shows this and exits with 0:

pass        a key is present (JAG_TYPESAFE_API_KEY)
pass        the service accepts the key
pass        the account has credit
pass        the service is reachable
pass        other users cannot read the key file (no key file)
jag is ready.

Exit codes:

Code Cause
0 All five items pass
2 The command line or a setting is not valid
3 No key, a bad key, or a config file that others can read or that jag cannot use
4 The service does not accept the key
5 The account has no credit
6 The service is not reachable

When more than one item fails, the code is the code of the first item that fails.

Examples

The output below is what jag shows in a terminal, with no color. It comes from a test of jag. The test searches a small sample folder, and a test service takes the place of the model. The scores, the order of the results, and the cost come from that test service. With the real model, the order of your results and your cost can be different. In a pipe, the layout and the number of results can be different.

An operator reads the log of a deploy that failed. The log goes into jag through a pipe, and the question asks which step failed:

$ cat logs/deploy.log | jag --ask "which step made the deploy fail" fail
<stdin>-6-10:00:10 step 3 of 6: update the database
<stdin>-7-10:00:14 step 3 of 6 done
<stdin>-8-10:00:15 step 4 of 6: start the new service
<stdin>:9:10:00:19 health check failed once, will try again
<stdin>-10-10:00:24 step 4 of 6 done
<stdin>-11-10:00:25 step 5 of 6: warm the cache
<stdin>-12-10:00:31 step 5 of 6 done
<stdin>-13-10:00:32 step 6 of 6: send traffic to the new service
<stdin>:14:10:00:36 step 6 of 6 failed: the new service has no free disk space
<stdin>-15-10:00:37 roll back started
<stdin>-16-10:00:40 traffic is back on the old service
<stdin>-17-10:00:41 roll back done
--
<stdin>:18:10:00:42 deploy of build 412 failed
jag: cost $0.000063: scored 2 of 2 results, skipped 0.

A new employee reads the notes of the company and asks about leave:

$ jag --ask "how many days of leave do new staff get" days notes
notes/leave.md-1-# Leave
notes/leave.md-2-
notes/leave.md:3:New staff get 25 days of paid leave each year.
notes/leave.md-4-Leave starts to count on the first day of work.
notes/leave.md:5:Ask your manager before you book more than 10 days in a row.
--
notes/onboarding.md-1-# First weeks
notes/onboarding.md-2-
notes/onboarding.md:3:In the first 30 days, a new person meets the team and reads the guides.
notes/onboarding.md-4-They get a laptop on the first day.
notes/onboarding.md-5-Their manager checks in each week.
--
notes/expenses.md-1-# Expenses
notes/expenses.md-2-
notes/expenses.md-3-Send a receipt with each claim.
notes/expenses.md:4:The company pays a claim within 14 days.
notes/expenses.md-5-A claim without a receipt waits until the receipt comes.
jag: cost $0.000095: scored 3 of 3 results, skipped 0.

A developer looks for the place where the code waits before it tries a request again:

$ jag --ask "where does the code wait before it tries a request again" retry src
src/client.py-12-        # Wait before the next try.
src/client.py:13:        time.sleep(retry_wait)
src/client.py-14-    raise RuntimeError("the service did not answer")
--
src/queue.py-3-        try:
src/queue.py-4-            job.run()
src/queue.py-5-        except TimeoutError:
src/queue.py:6:            job.retry_count += 1
src/queue.py-7-            jobs.append(job)
--
src/client.py-1-import time
src/client.py-2-
src/client.py:3:max_retry = 3
src/client.py:4:retry_wait = 2
src/client.py-5-
src/client.py-6-
src/client.py-7-def send(request):
src/client.py:8:    for attempt in range(max_retry):
src/client.py-9-        reply = call_service(request)
src/client.py-10-        if reply.ok:
src/client.py-11-            return reply
--
src/settings.py:1:# How many times to retry a job.
src/settings.py:2:job_retry_limit = 5
jag: cost $0.000126: scored 4 of 4 results, skipped 0.

A developer who does not need the model gives no question. jag then gives the same output as rg, with no cost line:

$ jag retry src
src/client.py
3:max_retry = 3
4:retry_wait = 2
8:    for attempt in range(max_retry):
13:        time.sleep(retry_wait)

src/queue.py
6:            job.retry_count += 1

src/settings.py
1:# How many times to retry a job.
2:job_retry_limit = 5

An employee asks a question that the notes do not answer. jag exits with exit code 1 and shows the label before the results. Ask a better question, or search for a broader term:

$ jag --ask "what is the refund policy" policy notes
jag: no good answer. The results below do not answer the question well.
notes/security.md-1-# Security
notes/security.md-2-
notes/security.md:3:Read the security policy before you use a company laptop.
notes/security.md-4-Lock the screen when you leave your desk.
notes/security.md-5-Report a lost laptop on the same day.
--
notes/travel.md-1-# Travel
notes/travel.md-2-
notes/travel.md:3:The travel policy says to book trains before planes.
notes/travel.md-4-Book at least one week before the trip.
notes/travel.md-5-Keep the tickets for the expense claim.
jag: cost $0.000063: scored 2 of 2 results, skipped 0.

A technician looks for the reason that a backup stopped, and sets a small size limit. jag leaves out some results, exits with exit code 8, and tells how to raise the limit. Use a larger --max-chars:

$ jag --max-chars 1000 --ask "why did the backup stop" error logs
jag: size limit reached: showed 1 of 6 results, left out 5. To see more, use --max-chars with a number larger than 1000, or --no-max-chars.
logs/backup.log-29-02:04:10 copied 10 percent of volume 4
logs/backup.log-30-02:04:20 copied 40 percent of volume 4
logs/backup.log-31-02:04:30 copied 70 percent of volume 4
logs/backup.log:32:02:04:40 error 4: the backup disk answered too slowly
logs/backup.log:33:02:04:41 error 4: the copy of volume 4 was cut off
logs/backup.log-34-02:04:50 copy of volume 4 started again
logs/backup.log-35-02:04:55 copied 100 percent of volume 4
logs/backup.log-36-02:04:59 check of volume 4 passed
jag: cost $0.000189: scored 6 of 6 results, skipped 0.

A developer asks a question before jag has a key. jag exits with exit code 3 and tells what to do. Run jag --setup (see Store your TypeSafe key):

$ jag --ask "where does the code wait before it tries a request again" retry src
jag: no TypeSafe API key found.
Get a key at https://console.typesafe.ai/keys, then run `jag --setup`,
or set JAG_TYPESAFE_API_KEY.

Search with no question

With no question, jag gives the same output as rg (ripgrep) 15.2.0 gives for the same arguments:

$ jag TERM [PATH...]

The lines, the colors, the layout, the error texts, and the exit codes are those of rg. An error text starts with jag: in the place of rg:. jag makes no call to the model and reads no key and no setting of the model service. The files come in the order of the paths on the command line. Inside one path, the files come in the order of their names, as rg --sort path does.

To rank the matches by a question, add --ask:

$ jag --ask "how long is the wait" retry src

A question that starts with - needs =:

$ jag --ask="-v or --verbose?" verbose src
  • In a terminal, rg shows the path above its lines, with the line numbers. In a pipe, rg shows path:text for more than one file, and only the text for one file. Add -n for line numbers, -H for the path, or --heading.
  • jag does not cut a line, and it writes no cost line and no notice of skipped files. jag skips binary files, hidden files, and ignored files, as rg does.
  • A few things are not the same as in rg: --max-chars and --no-max-chars (the size limit, below), --json, --ask, --help, --version, and the options of the model. The texts for a term that uses look-around or a new line, for an option that jag does not know, and for the value modified of --sort, do not ha

Description taken from the repository README.

Ratings

–
0 ratings
5 0
4 0
3 0
2 0
1 0

Rate this app

Sign in to rate

Comments 0

Sign in to comment

No comments yet.

Related apps

#cli · #search · #grep