---
description: "Log search across every agent-log.md with smart ranking and filters. Optional --semantic flag queries the per-repo triage corpus. Use when something has to be found across past task logs."
description-tr: "Tüm agent-log.md dosyalarında akıllı sıralama ve filtrelerle log araması. İsteğe bağlı --semantic bayrağı repo bazlı triyaj korpusunu sorgular."
allowed-tools: Bash, Read
argument-hint: "\"query\" [--project NAME] [--since 7d] [--phase N] [--semantic] [--json|--tsv]"
parameters: [{"name":"query","kind":"text","required":true},{"name":"--project","kind":"text"},{"name":"--since","kind":"text"},{"name":"--phase","kind":"text"},{"name":"--semantic","kind":"flag"},{"name":"--json","kind":"flag"},{"name":"--tsv","kind":"flag"}]
gui: form
destructive: false
confirm: none
---

# multi-agent search

Searches every task log under `~/.claude/logs/multi-agent/**/agent-log.md`. Uses ripgrep when available for speed, falls back to grep otherwise  -  same output. Results are ranked by `matches × recency` (last 7 days 1.0×, 7-30 days 0.5×, older 0.2×).

**`--semantic` flag** routes the query to the per-repo triage corpus (`triage-memory.mjs`) instead of the agent-log grep. Returns past Phase 3 (Review) findings ranked by token overlap. Honors `--project` as the repo-slug; `--since` and `--phase` are not applicable (the corpus is finding-grained, not phase-grained).

**Input:** `$ARGUMENTS`  -  query + optional flags

## Usage

```bash
# Plain search  -  all projects, all time
/multi-agent:search "null deref"

# Project filter
/multi-agent:search "memory leak" --project my-ios-app

# Time filter (last 7 days)
/multi-agent:search "build failure" --since 7d

# After a specific date
/multi-agent:search "xcodebuild" --since 2026-04-01

# Only inside Phase 3 (review) sections
/multi-agent:search "flaky test" --phase 3

# Limit (default 20)
/multi-agent:search "PROJ-" --limit 5

# JSON (for automation)
/multi-agent:search "null" --json

# TSV (for pipelines)
/multi-agent:search "null" --tsv

# semantic query against the triage corpus
/multi-agent:search "force unwrap optional" --semantic --project my-ios-app
/multi-agent:search "missing timeout" --semantic --json
```

## Output format

Text mode (default)  -  colourful, human-readable:

```
search-logs · 3 tasks · query=null deref
  since=7d

PROJ-1337 · app · bugfix/PROJ-1337-null-deref · 4 matches
  PROJ-1337  -  Guard null in CheckoutViewModel
  2026-04-16  ·  CheckoutViewModel.swift:142 null-deref fixed via guard

PROJ-1234 · app · feature/PROJ-1234-order-filter · 1 match
  PROJ-1234  -  Add order price filter
  2026-04-15  ·  price-filter state leaked across navigation
```

JSON mode  -  for embedded automation:

```json
{
  "query": "null deref",
  "matched_tasks": 3,
  "tasks": [
    { "task_id": "PROJ-1337", "project": "app", "branch": "bugfix/PROJ-1337-null-deref",
      "date": "2026-04-16", "matches": 4, "score": 400, "title": "...", "snippet": "..." }
  ]
}
```

## Four layers, and what each one costs

Retrieval is cheap or expensive depending on which layer answers, and the order
matters more than the query does. Filter first, fetch second - inverting these
is how a single lookup eats a phase's whole context budget.

| # | Call | Returns | Rough cost per hit |
|---|---|---|---|
| 1 | `search` / `--semantic` | pointers: id, file, one-line issue | ~50-100 tokens |
| 2 | `timeline --anchor <id>` | the rows recorded around one hit | ~50-100 tokens each |
| 3 | `show --id <id>` | one full row | ~500-1000 tokens |
| 4 | the offloaded artefact behind a `[[ref:<id>]]` | the raw payload | thousands |

Never start at layer 3 or 4. Narrow at layer 1, widen at layer 2 only around the
hits that survived, and fetch full rows only for the handful that are actually
going to be read. A `show` on twenty ids costs as much as the entire search that
found them and answers a question nobody asked.

Layer 2 is the one that gets forgotten. A finding rarely stands alone: the same
review pass produced its neighbours, and those are usually what makes an old row
legible. Both stores answer it, and the corpus is append-only so line adjacency
IS chronological adjacency:

```bash
node "$HOME/.claude/scripts/triage-memory.mjs"    timeline --anchor T:<id> --before 3 --after 3
node "$HOME/.claude/scripts/learnings-ledger.mjs" timeline --anchor L:<id> --before 3 --after 3
```

## Steps

1. **Run the script:**
   ```bash
   bash "$HOME/.claude/scripts/search-logs.sh" "$ARGUMENTS"
   ```

2. **Exit code:**
   - 0: at least one match
   - 1: no match (query may be wrong, or rethink the date filter)
   - 64: bad args

## Tips

- **Find a task:** `/multi-agent:search "component name"` shows the PROJ-ID where it was done
- **Regression scan:** `/multi-agent:search "null" --since 30d` lists null-related fixes from the last month
- **Review history:** `/multi-agent:search "blocking" --phase 3` finds tasks that hit a review blocker

## Security note

The search is scoped to **local** files  -  `~/.claude/logs/multi-agent/` (per-user, not in the repo). No network I/O, no uploads. Raw log content never leaves the terminal.
