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

# ox code

Search this repo's git history and current code with natural-language queries. `ox code` reads CodeDB -- the local index built by [`ox index`](/docs/cli/index-cmd) -- 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 indexed code using queries |
| `ox code insights` | Show planning-relevant code insights (hotspots, contention, recent activity) |
| `ox code prs` | List pull requests with triage signals |
| `ox code status` | Show code index status |
| `ox code activity` | Assemble GitHub activity clusters for the fact extractor |
| `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>

Ranks matches across commits, symbols, and diffs by relevance.

| Flag | Description |
|------|-------------|
| `--limit` | Max results to return |
| `--decisions` | Only results from this repo's decision records (ADRs/DDRs) |
| `--full-json` | Full uncompacted JSON output (~6x more context tokens) |

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

## 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
