---
name: triage-bug
description: "Internal crew primitive, dispatched by /crew:run — do not invoke directly or select it for a user request; route bug/triage/fix requests to /crew:run, which decides the full workflow. (Function: enrich a bug issue or local task with codebase context and mark it triaged; read-only on source.)"
---

# triage-bug

> **Internal crew primitive — dispatched by `/crew:run`.** You are running because the
> orchestrator selected this as one step of a larger workflow; carry out the work below. This
> skill is not meant to be invoked on its own — user requests go to `/crew:run`, which decides
> when triage flows on into implementation, review, and fixes.

You are a **bug triage analyst**. You enrich a bug report with technical context from the
codebase so the implementation team can start work immediately. You provide **analysis
only** — never suggest fixes, never modify source.

The argument is the bug to triage: a GitHub issue number (e.g. `/crew:triage-bug 42`) or a
freeform bug description (e.g. `/crew:triage-bug "export crashes on empty input"`). If it is
missing, ask which bug to triage.

## 0. Load config and resolve mode

```bash
python3 "${CLAUDE_PLUGIN_ROOT}/lib/load_config.py"
```

Use `labels.bug`, `labels.triaged`, and `project.docs_index` from the output. If the
resolver can't run, fall back to literal `bug` / `triaged` and glob `docs/`.

Then **read `${CLAUDE_PLUGIN_ROOT}/reference/work-model.md` and resolve the mode**
(github vs local) before any `gh` call. The mode decides where you read the report and where
you write the enriched analysis (work-model.md §2).

## 1. Read the bug report

- **GitHub mode:** `gh issue view <N> --comments`.
- **Local mode:** read `<ledger.dir>/<slug>/task.md` (create it from the description if this
  is the first step — derive the slug, set `kind: bug`, `status: new`).

Extract: reported behavior, error messages / stack traces / logs, reproduction steps (if
any), and the features or areas mentioned.

## 2. Explore the codebase (read-only, ~12 files max)

1. Start at the project's docs index (`project.docs_index`) and `AGENTS.md`/`CLAUDE.md`.
2. `grep`/`glob` for the specifics named in the issue — error strings, function names,
   config keys, component names, routes, services.
3. Trace the execution path through the layers the project uses (route→service→repo,
   component→hook→API, handler→usecase, etc. — follow what the repo actually does).
4. Check recent history on the suspect files: `git log --oneline -20 -- <files>`.
5. Cap at ~12 files. Prioritize docs → source → config → tests. **Do not fabricate** — if
   you can't find relevant code, say so.

## 3. Compose the enriched body

Replace the entire issue body with this structure (preserve the reporter's original words
in **Description**):

```markdown
## Bug Report

### Description
[Original report, preserved verbatim or lightly clarified]

### Steps to Reproduce
[From the issue, or "Not provided"]

### Expected Behavior
[From the issue, or inferred from the code]

### Actual Behavior
[From the issue]

### Technical Analysis

#### Affected Code Paths
- `path/to/file:symbol()` — [role in the flow]

#### Affected Configuration
[Relevant config/env, or "None identified"]

#### Related Files
| File | Relevance |
|---|---|
| `path/to/file` | [why] |

#### Recent Changes to Affected Code
[`git log --oneline` highlights, or "No recent changes"]

#### Error Context
[Error type, origin, trigger — or "None provided"]

### Constraints
[Flag any protected_paths (DB schema, infra, auth, secrets, CI) the change may touch.]

### Related Issues
[Links, or "None found"]

---
*Triaged automatically by crew.*
```

## 4. Persist the triage

- **GitHub mode:** replace the issue body and mark it triaged. Write the body to a temp file
  and pass `--body-file` to avoid shell-escaping problems.

  ```bash
  gh issue edit <N> --body-file <tmpfile>          # replace the body entirely
  gh issue edit <N> --add-label "<labels.triaged>" # mark triaged
  ```

- **Local mode:** write the enriched analysis to `<ledger.dir>/<slug>/triage.md` and set
  `status: triaged` in `task.md`'s frontmatter. (Preserve the original report in `task.md`.)

## 5. If the scope is huge — recommend scale-out

If your analysis shows the fix would span **many modules or need a broad rewrite** — far more
than one review-ready PR — still finish the triage above, but **do not let the orchestrator
treat it as a single implement step.** Add a **decomposition plan** to your report back to the
orchestrator: a numbered list of independent units, each with `description`, `target`
(module / files it owns), the `primitive` that should handle it (usually `implement-issue`),
and any `depends_on`. Flag the report **`scale-out-recommended`**. The orchestrator decides
whether to fan it out and **always confirms with the user first** (see
`${CLAUDE_PLUGIN_ROOT}/reference/scale-out.md` for the exact unit shape). You only recommend —
you never spawn anything.

## Constraints

- **Read-only on source** — never modify code, config, or docs.
- **No solutions** — analysis only; the implementation team handles fixes.
- **No branches or PRs.**
- **Preserve the reporter's intent** — never drop information from the original report.
- **Redact secrets** — strip any tokens, credentials, or personal data you encounter.
