# ox code (https://sageox.ai/docs/cli/code)

# ox code

Search this repo's code, symbols, git history, PRs, issues, and comments. `ox code` reads CodeDB -- the local index built by [`ox index`](/docs/cli/index-cmd) -- with a Sourcegraph-style query DSL whose filters grep cannot match, and surfaces planning signals like hotspots, stalled PRs, and index status.

## Usage

<Terminal>
  <TerminalCommand>ox code [subcommand] [flags]</TerminalCommand>
</Terminal>

Every subcommand reads the local CodeDB index. Build or refresh it first with [`ox index`](/docs/cli/index-cmd).

## Subcommands

| Command | Description |
|---------|-------------|
| `ox code search <query>` | Search the CodeDB index using a query DSL |
| `ox code defs <name>` | Where is `<name>` defined? (symbol search) |
| `ox code refs <name>` | Where is `<name>` referenced in code text? (text search across the index) |
| `ox code callers <name>` | Who calls `<name>`? (resolved call graph) |
| `ox code callees <name>` | What does `<name>` call? (resolved call graph, transitive via `--depth`) |
| `ox code log <path>` | Commits touching `<path>` (git history via the index) |
| `ox code insights` | Show planning-relevant code insights (hotspots, contention, recent activity) |
| `ox code prs` | List pull requests ranked for triage (stalled, age, activity) |
| `ox code status` | Show code index status |
| `ox code activity` | Recent GitHub activity (PRs, issues, commits) over a time window |
| `ox code index [url]` | Index a git repository -- alias for [`ox index code`](/docs/cli/index-cmd) |

## Search code

<Terminal>
  <TerminalCommand>ox code search "authentication middleware" --limit 10</TerminalCommand>
</Terminal>

Searches symbols, code, diffs, commits, comments, PRs, and issues. Narrow a query with DSL filters such as `type:`, `file:`, `lang:`, `author:`, `after:`, `calls:`, and `calledby:`; run `ox code search --help` for the full grammar.

<Terminal>
  <TerminalComment>Find a symbol definition</TerminalComment>
  <TerminalCommand>ox code search "ResolveSession" type:symbol</TerminalCommand>
  <TerminalComment>Search open PR titles, bodies, and review comments</TerminalComment>
  <TerminalCommand>ox code search "rate limit" type:pr state:open</TerminalCommand>
  <TerminalComment>Find source comments tagged TODO</TerminalComment>
  <TerminalCommand>ox code search "TODO" type:comment ckind:todo</TerminalCommand>
</Terminal>

| Flag | Description |
|------|-------------|
| `--limit` | Max results to return |
| `--snippet` | Max snippet length per result, in characters |
| `--decisions` | Only results from this repo's decision records (ADRs/DDRs) |
| `--full-json` | Full uncompacted JSON output (~4x more context tokens) |

<Terminal>
  <TerminalComment>Search only Decision Records</TerminalComment>
  <TerminalCommand>ox code search "rate limiting" --decisions</TerminalCommand>
</Terminal>

When the index is unavailable (still building, or not yet created), agent-context invocations return a structured JSON status instead of an error. Check the `status` field before you treat the output as results.

## Navigate symbols and history

Each of these commands is a shortcut for an `ox code search` query.

<Terminal>
  <TerminalComment>Where is ResolveSession defined?</TerminalComment>
  <TerminalCommand>ox code defs ResolveSession</TerminalCommand>
  <TerminalComment>Where does the text "migration" appear in Go code?</TerminalComment>
  <TerminalCommand>ox code refs migration --lang go</TerminalCommand>
  <TerminalComment>Who calls authenticate?</TerminalComment>
  <TerminalCommand>ox code callers authenticate</TerminalCommand>
  <TerminalComment>What does authenticate call, three hops deep?</TerminalComment>
  <TerminalCommand>ox code callees authenticate --depth 3</TerminalCommand>
  <TerminalComment>Which commits touched this file since April?</TerminalComment>
  <TerminalCommand>ox code log cmd/ox/code.go --after 2026-04-01</TerminalCommand>
</Terminal>

| Command | Equivalent search |
|---------|-------------------|
| `ox code defs <name>` | `ox code search "<name>" type:symbol` |
| `ox code refs <name>` | `ox code search "<name>" type:code` |
| `ox code callers <name>` | `ox code search "" calledby:<name>` |
| `ox code callees <name>` | `ox code search "" calls:<name> depth:<N>` |
| `ox code log <path>` | `ox code search "" file:<path> type:commit` |

`refs` is plain text search. For the resolved call graph, use `callers` and `callees`.

All five accept `--limit`, `--snippet`, and `--full-json`. These flags are specific to one command:

| Flag | Command | Description |
|------|---------|-------------|
| `--depth` | `callees` | Transitive call depth (1-10) |
| `--lang` | `refs` | Restrict to a language (for example `go`, `ts`) |
| `--author` | `log` | Restrict to commits by this author |
| `--after` | `log` | Include commits after this date (for example `2026-04-01`) |
| `--before` | `log` | Include commits before this date |

## Planning insights

<Terminal>
  <TerminalCommand>ox code insights --days 30</TerminalCommand>
</Terminal>

Reports change hotspots, file contention, and recent activity -- the signals worth reading before planning a change.

| Flag | Description |
|------|-------------|
| `--days` | Time window in days |
| `--limit` | Max rows per section |
| `--json` | Structured JSON output for agents |

## Triage pull requests

<Terminal>
  <TerminalCommand>ox code prs --sort stalled --state open</TerminalCommand>
</Terminal>

Ranks indexed PRs by triage signal -- most-stalled open PRs first by default. Ranking is deterministic and computed from indexed GitHub data (no LLM, no external API).

| Flag | Description |
|------|-------------|
| `--sort` | Ranking: `stalled` \| `age` \| `activity` |
| `--state` | PR state: `open` \| `closed` \| `merged` \| `all` |
| `--limit` | Max number of PRs to return |
| `--pretty` | Pretty-print JSON output |

## Index status

<Terminal>
  <TerminalCommand>ox code status</TerminalCommand>
</Terminal>

Shows what CodeDB has indexed and how current it is. Add `--json` for machine-readable output.

## What's next

- [ox index](/docs/cli/index-cmd) - Build the CodeDB index that `ox code` searches
- [ox query](/docs/cli/query) - Search recorded team knowledge beyond code
- [ox decision](/docs/cli/decision) - Enrich Decision Records with team context
