# Code search

> How agents ask DMN about code: plain-language search that returns whole sections, definitions and callers, blast radius, exact-text grep, other projects and a current index.

Source: https://getdmn.com/docs/search/

## What happens when an agent asks

*Diagram: One question, read three ways: DMN merges what each finds into one ranked list and sends back whole sections of code, fitted to a budget.*

DMN reads your code three ways when it indexes it: what each piece of code does, the exact words in it, and its structure, meaning which function calls which. A question goes to the ways that fit it, and DMN merges what they find into one ranked list. With `--curate` the answer is the code itself: whole functions, classes or blocks, cut to fit a budget, so the agent doesn't have to open file after file. A grep for words the code never uses finds nothing; a search by meaning still finds it.

## Ask in plain words

```sh
dmn search "where do we rate-limit logins" --curate
dmn search "how is a session resumed" "what happens when the token expires" --curate
```

- Several questions in one call each get their own results, and a section that answers two of them shows once.
- `--budget <chars>` sets how much code comes back (8,000 characters by default); `--compact` cuts it to 3,000.
- Without `--curate`, you get a ranked list of files, each with the first few lines of what matched.

## Ask about a symbol

| Command | What it answers |
|---|---|
| `dmn context <symbol>` | Its definition, who calls it and what a change could affect, in one call |
| `dmn search --mode symbol <symbol>` | Where it's defined, and where it's used |
| `dmn search --mode trace <symbol>` | Who calls it, and who calls those |
| `dmn impact --symbol <symbol>` | What could break if it changes; `--path <file>` does the same for a file |

## When you know the exact text

```sh
dmn grep "TooManyRequests"                 # exact matches, with the code around them
dmn grep "retryAfter" "Retry-After" -i     # several patterns, case-insensitive
dmn grep "TODO" --path src/auth -l         # one folder; -l lists the files only
```

`dmn grep` is as exact as grep, but returns each hit inside its function or block rather than as a bare line.

## Find your way around

| Command | What it shows |
|---|---|
| `dmn search --mode structure src/auth` | A map of a folder: its files and what's defined in each |
| `dmn search --mode files "src/**/*.test.ts"` | Files that match a pattern |
| `dmn repo` | Branch, status, recent commits, ahead and behind, and stashes |
| `dmn review --base main --head HEAD` | What changed between two refs, file by file; `--mode semantic_diff` lists the symbols |

## Other projects

`dmn projects` lists every project DMN tracks, each with a short name. Use it to ask about one project from inside another:

```sh
dmn search "how does billing retry" --project billing-api --curate
dmn context chargeCustomer --project-path billing-api
dmn grep "STRIPE_" --path @billing-api:src
```

## Keeping the index current

DMN indexes a project when you open it in the app or run `dmn index`, then re-indexes files as they change. In Claude Code, a hook re-indexes each file the agent edits straight away. If results seem stale:

```sh
dmn index --watch      # queue an update and wait until it's searchable
dmn index --force      # rebuild the project's index from scratch
```

Search never starts indexing on its own, and never starts the engine.

## For agents without a shell

Every command on this page has an MCP tool behind it: `search` (with the same modes), `read`, `impact` and `repo`. See [MCP tools](/docs/mcp-tools/).
