---
name: ctxfr-fix
description: Triage and repair ctxfr context infrastructure health issues. Use when the user asks to fix stale specs, coverage gaps, routing gaps, decision links, agent quality, metrics integrity, or the equivalent of /ctxfr-fix.
---

# ctxfr Fix

Treat user text as an optional category filter: `stale`, `coverage`, `routing`, `decisions`, `agents`, `metrics`, or all categories when omitted.

If `ctxfr` is not found, tell the user: `The ctxfr binary is not installed. Run cmake --build build && cmake --install build from the ctxfr repo.`

## 1. Check Health

Run `ctxfr health` silently. Also read `CLAUDE.md` or `AGENTS.md` for routing and `docs/decisions.md` for decision links.

## 2. Triage

Categorize issues:

- Stale specs: read stale specs and changed source files; update spec content without restructuring it.
- Coverage gaps: run `ctxfr sources --orphans`; create specs for significant orphan areas, or add trivial files to the nearest related spec.
- Routing gaps: add missing routes for specs, agents, and covered source patterns; remove or flag broken links.
- Decision gaps: add missing `docs/decisions.md` rows for existing ADRs; create stub ADRs only when decisions reference missing ADRs with enough table context.
- Agent gaps: flag placeholder agent knowledge and add missing spec links where clear.
- Metrics integrity: verify `docs/context-metrics.md`, referenced paths, session-log references, score weights, health command consistency, and command/skill completeness.

## 3. Present Plan Before Editing

Before making changes, present:

```text
=== CONTEXT FIX PLAN ===

STALE SPECS - N specs to update
COVERAGE GAPS - N specs to create, N files to add
ROUTING GAPS - N entries to add, N to remove
DECISION GAPS - N issues
AGENT GAPS - N agents with quality issues
METRICS INTEGRITY - N issues

Total changes: N files to create, N files to modify
```

Ask for confirmation. Accept `yes`/`all`, `skip <category>`, `only <category>`, or `no`.

## 4. Apply Fixes

Modify only confirmed categories. For each created or updated spec, run:

```bash
ctxfr cache snapshot <spec-path>
```

## 5. Verify

Run health checks again silently and report:

```text
=== FIX RESULTS ===

Created: N files
Modified: N files

Health score: before -> after
  Routing:    before -> after
  Coverage:   before -> after
  Freshness:  before -> after
  Decisions:  before -> after
  Agents:     before -> after

Remaining issues:
```
