An AI coding agent spends most of its tokens on search: a grep, a wrong file, a long read to reach one function. I gave my agent a local code graph from Graphify and let Jev, a very cheap ranking model, choose the files. On 30 real questions the agent used 19% fewer tokens and 24% fewer turns, with the same number of correct answers. The code graph without the ranking step made the agent worse, not better.
The prompt below sets up the same thing in your repo. It works with Claude Code, Codex, Cursor, or any agent that can run shell commands.
The setup prompt
Open your agent in the root of your repo, paste this, and send it. It stops and asks you before it needs your API key, and it never prints the key.
Set up graph-ask in this repo. graph-ask is one command that answers "where does X live"
with the right files and line numbers, so you stop spending tokens on grep and long reads.
It has two parts: Graphify builds a code graph on this machine (tree-sitter, no LLM), and
Jev (TypeSafe) ranks every file against my question for a fraction of a cent.
RULES FOR THE WHOLE TASK
- Never print, log, echo, or commit my TypeSafe API key. Never put it in this repo. Never
ask me to paste it into this chat.
- Do not run `graphify hook install`, `graphify install`, or `graphify claude install`.
They rebuild the graph on every commit. I refresh it by hand.
- Do not change product code. You may add scripts/graph-ask.py, .graph-ask.json, one
.gitignore line, and one short section in the agent instructions file.
- Report what each command printed. Do not guess. If a step fails, stop and show me the
error and one proposed fix.
STEP 1. Check the tools. Run `python3 --version` (3.9 or later is required), `git rev-parse
--show-toplevel`, and `uv --version`. If uv is missing, check `pipx --version`. Work from
the repo root for every step after this.
STEP 2. Install Graphify. The PyPI package name has a double y; the command has one.
uv tool install graphifyy (or: pipx install graphifyy)
Then run `graphify --help` to confirm that the command is on PATH.
STEP 3. Build the graph. Run `graphify update .` and tell me how long it took and how many
nodes it made. It writes graphify-out/. Add `graphify-out/` to .gitignore if that line is
missing. Never commit that folder.
STEP 4. Get the script.
mkdir -p scripts
curl -fsSL https://ducktate.com/prompts/graphify-jev/graph-ask.py -o scripts/graph-ask.py
chmod +x scripts/graph-ask.py
Read the whole file before you run it. Tell me in three lines what it sends over the
network and where. It must send only my question, file paths, and symbol names, and only
to api.typesafe.ai. If it does anything else, stop.
STEP 5. Check the key without printing it. The script reads TYPESAFE_API_KEY from the
environment or from ~/.typesafe.env. Test for it with a command that prints only yes or no,
for example:
test -n "$TYPESAFE_API_KEY" && echo env:yes || echo env:no
test -s ~/.typesafe.env && echo file:yes || echo file:no
Also run `test -z "$GRAPH_ASK_ENDPOINT" && echo endpoint:default || echo endpoint:OVERRIDDEN`. That
variable redirects every request, with my key, to another server. If it says OVERRIDDEN,
STOP and tell me.
If both key checks say no, STOP. Tell me to create a key at https://console.typesafe.ai/ and to save
it myself in ~/.typesafe.env as one line, TYPESAFE_API_KEY="...", then run
`chmod 600 ~/.typesafe.env`. Continue when I say the file is there.
STEP 6. Describe the repo, only if it needs it. Look at the top-level folders. If the repo
holds more than one product, platform, or service, write .graph-ask.json at the repo root
with 2 to 6 areas. Each area has a one-sentence description and a list of path prefixes.
The format is in the docstring at the top of scripts/graph-ask.py. If the repo is one
project, skip this step. The script works with no config.
STEP 7. Prove it on this repo. Choose 5 questions about this codebase where you can confirm
the correct file by reading it. Use plain words, not the file name. Run each question two
ways: `scripts/graph-ask.py "<question>"` and `scripts/graph-ask.py --no-jev "<question>"`.
Show me one table: the question, the correct file, its rank with Jev, its rank without Jev,
and the cost line the script printed.
STEP 8. Wire it in. Find the agent instructions file for this repo (CLAUDE.md, AGENTS.md,
or the file your tool reads; create AGENTS.md if there is none). Add this section:
## Finding code (graph-ask)
Run `scripts/graph-ask.py "<plain question>"` BEFORE you grep or read a whole file.
It prints ranked files with line numbers. Read only the lines it points at. Search by
hand only when its answer is clearly wrong. When it prints a note that the graph is
behind HEAD, refresh it with `graphify update .`.
STEP 9. Report: the Graphify version, the node count, the table from step 7, the total Jev
cost of the test, the files you added, and anything that failed.Free, ungated, no email required. Copy it as many times as you like.
What I measured
I ran 30 "where does this live" questions against one repo: a Swift Mac app with an iOS app, a Windows app in Rust, Supabase functions, scripts, and specs, about 75,000 graph nodes. Each question ran in a fresh headless Claude Code session on Claude Sonnet, once per setup. That is 120 runs, and 0 of them errored. The agent had to name the file, the lines, and the symbols.
| Setup | Correct file | Turns | Tokens processed | API cost |
|---|---|---|---|---|
| Grep and read only (baseline) | 27 of 30 | 183 | 6.72 M | $6.50 |
Graphify alone, stock graphify query first | 25 of 30 | 196 | 7.72 M | $6.81 |
| Graph plus keyword ranking, no Jev | 26 of 30 | 184 | 7.54 M | $6.54 |
| Graph plus Jev ranking (graph-ask) | 27 of 30 | 139 | 5.45 M | $6.07 |
What the numbers say:
- The graph alone cost more. The stock keyword query returned long answers that often pointed at the wrong part of the repo. The agent read them, then searched by hand anyway: 15% more tokens than the baseline and two fewer correct answers.
- The ranking step is the part that pays. With Jev choosing the files, the agent used 19% fewer tokens and 24% fewer turns than the baseline, at the same accuracy. The Jev spend was about $0.002 per question.
- The biggest win was a hard question. One question about a write guard took the baseline agent 13 turns and 525,000 tokens. With graph-ask it took 6 turns and 195,000 tokens.
- Easy questions get no gain. When one grep finds the file, the extra command is overhead. Eight of the 30 questions used more tokens with graph-ask than without.
I also tested the tools with no agent in the loop. For the same 30 questions, graph-ask printed the correct file in 28 answers and ranked it first in 21, in about 196 tokens per answer. Stock graphify query printed the correct file in 4 answers, in about 1,644 tokens per answer.
Read the numbers with care
- One repo, one model. Your repo and your agent will give different numbers. Step 7 of the prompt measures your own.
- Tokens processed includes cached tokens. Each session starts with about 50,000 tokens of system prompt and tool definitions, and cached reads are cheap. That is why a 19% token cut is only a 7% cut in dollars. New, uncached tokens were about the same in every setup.
- Ten of the 30 questions were used to tune the tool. On the 20 questions written after tuning, both the baseline and graph-ask got 19 of 20 correct, and graph-ask used 20% fewer tokens.
- Three misses were shared by every setup. On review, the agents' answers to those three were as good as my answer key.
How it works
- Graphify parses the repo with tree-sitter and writes a graph of files, symbols, and line numbers to
graphify-out/. This step is local and free. On my repo it takes about 80 seconds. - If you defined areas, one Jev request picks the area of the repo that the question is about.
- The script describes every file in scope as its path plus its most connected symbol names, and sends them to Jev in parallel groups of 250. Jev returns a probability for each file.
- The best files from each group meet in a final round. One more request ranks the symbols inside the winning files.
- The script prints the files, the line numbers, and how the chosen symbols link to each other. A typical answer takes 2 to 4 seconds.
Without a key, or with --no-jev, the script falls back to keyword ranking. It still runs, but the third row of the table shows what that is worth.
What you should know going in
- Your code stays on your machine. Your file paths and symbol names do not. The script sends your question, file paths, function and class names, and the area descriptions from your config to TypeSafe. It does not send file contents. TypeSafe states that it does not train on user data. Read their legal page before you use it on a private repo.
- Jev costs money, in small amounts. TypeSafe lists Jev at $0.042 per million input tokens, and output is free. My 30-question run cost about 6 cents. I do not know if new accounts get free credit.
- The graph goes stale. The script tells you when the graph is behind your latest commit. Refresh it with
graphify update .. I do not use the Graphify commit hook, because a rebuild takes all cores for about a minute. - Read the script first. It is one Python file, standard library only, released under the Unlicense. The prompt tells your agent to read it and report what it sends before it runs.
- Uninstall is three deletes. Remove
scripts/graph-ask.py,.graph-ask.json, andgraphify-out/, then runuv tool uninstall graphifyy.
Sources
Graphify is open source at github.com/Graphify-Labs/graphify; the package is graphifyy on PyPI. Jev is documented at docs.typesafe.ai, with the price on the models page and the 255-option limit on the Choice page. Keys come from console.typesafe.ai. The script is at ducktate.com/prompts/graphify-jev/graph-ask.py. The benchmark numbers are my own, measured on 2026-09-20 with Claude Code 2.1.273 and Claude Sonnet.
Talk to Claude instead of typing to it.
Ducktate turns what you say into clean text, on your Mac, and pastes it anywhere.
Get early access