config-audit/commands/manifest.md
Kjell Tore Guttormsen 0b763f25c1 fix(commands): router dogfood — five seam defects, plus the placeholder class
Dogfooding `/config-audit` (the router) against the repo, fasit written before
any run (docs/router-fasit.local.md, untouched). Every claim below is measured
behaviour, not a reading of the source.

1. Bare `<target-path>` inside the step-3 fence is a shell REDIRECTION, not an
   argument. Measured in zsh: both CLIs failed before starting, no output file
   was written, and the echoed status was 1 — inside the band the router's own
   gate calls "continue normally". Quoting makes an unsubstituted placeholder
   reach argv, so it fails in the CLI where the exit code means something.
   Swept the whole class: 30 sites across 12 further command files, since a
   defect in one file is a class until the opposite is measured. New guard:
   command-placeholder-shell-safety.test.mjs.

2. The orchestrator's exit code was discarded. Two commands on one line share a
   single trailing `echo $?`, which reports only the last: measured, an
   orchestrator exit 3 echoed as posture's 0, so the "3 -> stop" gate could
   never fire. Both statuses are now captured and echoed.

3. "Running 12 configuration scanners" — the orchestrator registers 16. The new
   test binds the narrated count to the registry so the next scanner added
   cannot re-stale it silently.

4. The Area Breakdown table hardcoded 7 rows; posture emits 9 quality areas.
   Token Efficiency (a B on this repo) and Plugin Hygiene never reached the
   user. Rows added, and the row set is now asserted against lib/scoring.mjs.
   Label aligned: "MCP Servers" -> "MCP", as posture emits it.

5. Step 6 rendered "the headline line from the humanized stderr scorecard" and
   forbade deriving a replacement — while step 3 sent posture's stderr to
   /dev/null, as UX rule 2 requires, and the prose is absent from the JSON
   payload (measured). The slot could only be improvised. posture's stderr now
   goes to a file in the session dir, as commands/posture.md already did; the
   user still never sees raw scanner output.

Also: `grep -q -- "--raw"` matched any argument CONTAINING --raw (measured on
`--rawdog` and on a path with --raw in it) — anchored to whole arguments.
SCOPE_FLAGS renamed SCOPE_FLAG, since zsh does not word-split and the plural
invited the M-BUG-45 shape.

command-shell-state-shape.test.mjs only recognised line-initial assignments, so
it reported the idiomatic `node …; STATUS=$?` capture as never assigned. Widened
to assignments after a separator; verified it still fails on a real cross-block
reference before trusting it.

Suite 1477 -> 1483, frozen v5.0.0 snapshots untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDAwy1ZXRpZxht1wyCeSbF
2026-08-09 21:18:05 +02:00

5.1 KiB
Raw Blame History

name description argument-hint allowed-tools model
config-audit:manifest Show ranked token-source manifest — every CLAUDE.md, rule, agent, skill, output style, MCP server, and hook ordered DESC by estimated tokens, each tagged with its load pattern (always-loaded vs on-demand vs external), plus an always-loaded subtotal [path] [--json] Read, Bash sonnet

Config-Audit: Manifest

Produce a ranked, single-table view of every token source loaded for a given repo path. Where whats-active shows separate tables per category, manifest collapses everything into one ordered list — making it easy to see what's costing the most regardless of category.

Every source is tagged with its load pattern, derived from the published Claude Code loading model:

  • always — enters context every turn before you type (project/user CLAUDE.md, unscoped rules, agents, output styles, MCP tool schemas). This is the cost that matters most: it is paid on every request.
  • on-demand — loaded only when needed (skill bodies on invoke, path-scoped rules on a matching file read).
  • external — runs outside the context window entirely (hooks).

The always-loaded subtotal is the headline number. Sources are component-level (a plugin contributes via its skills/rules/agents/output styles/hooks/MCP, each listed once — there is no coarse "plugin" roll-up, which would double-count).

UX Rules (MANDATORY — from .claude/rules/ux-rules.md)

  1. Never show raw JSON or stderr output. Always use --output-file + 2>/dev/null.
  2. Narrate before acting. Tell the user what you're about to do.
  3. Read, don't dump. Read the JSON file and render a formatted table.
  4. End with context-sensitive next steps.

Implementation

Step 1: Parse $ARGUMENTS

First non-flag argument is the path (default .). Recognized flags:

  • --json — emit raw JSON instead of the rendered table.
  • --raw — pass-through to the scanner; accepted for CLI surface consistency with the other config-audit commands. The manifest CLI is data-table only (no findings prose), so --raw is a no-op here, but the flag is still threaded through so users get uniform behaviour across --raw.

Step 2: Run the CLI silently

Tell the user: "Building token-source manifest for <path>..."

RAW_FLAG=""
if echo "$ARGUMENTS" | grep -q -- "--raw"; then RAW_FLAG="--raw"; fi
node ${CLAUDE_PLUGIN_ROOT}/scanners/manifest.mjs "<path>" --output-file /tmp/config-audit-manifest.json $RAW_FLAG >/dev/null 2>/dev/null; echo $?

Exit code handling:

  • 0 → continue
  • 3 → tell user: "Couldn't read configuration. Check that the path exists and is a directory." Stop.

Step 3: If --json was requested, cat the file and stop

cat /tmp/config-audit-manifest.json

Do NOT render the table in JSON mode.

Step 4: Read JSON and render

Use the Read tool on /tmp/config-audit-manifest.json. Extract meta.repoPath, total, summary, and sources[]. Lead with the always-loaded subtotal (the headline), then render the top 20 sources (or fewer if the manifest is shorter):

**Token-source manifest for `<repoPath>`** — ~{total} tokens total

- 🔴 **~{summary.always.tokens} tokens enter context every turn** before you type ({summary.always.count} always-loaded sources)
- 🟡 ~{summary.onDemand.tokens} tokens on-demand ({summary.onDemand.count} sources — loaded only when invoked / matched)
- ⚪ ~{summary.external.tokens} tokens external ({summary.external.count} sources — hooks, run outside context)

| Rank | Kind | Name | Source | Tokens | Load |
|------|------|------|--------|--------|------|
| 1 | {kind} | `<name>` | {source} | ~{estimated_tokens} | {loadPattern} |
| ... | ... | ... | ... | ... | ... |

_Load column: **always** / **on-demand** / **external**. Append `°` when `derivationConfidence` is `inferred` (no primary-doc row pins it exactly)._
_Estimates assume ~4 chars/token (Claude ballpark). Real token count varies ±15%._

If sources.length > 20, follow the table with: "Showing top 20 of {N} sources. Run with --json to see the full list."

When narrating, prioritize the always-loaded subtotal: a large always source is worse than an equally large on-demand one, because it is paid on every request. Call out any single always-loaded source that dwarfs the rest.

Step 5: Suggest next steps

**Next steps:**
- `/config-audit tokens` — prompt-cache token-hotspot patterns (cache-breaking, redundant perms, deep imports, MCP budget)
- `/config-audit whats-active` — same data grouped by category, with disable suggestions
- `/config-audit feature-gap` — what *could* improve here, grouped by impact

Tone (key on the always-loaded subtotal — the every-turn cost — not the grand total):

  • High always-loaded (>40k): empathetic — "That's a heavy per-turn cost; it taxes every request before you've typed a word. Look at the largest always-loaded sources first."
  • Moderate (1040k): neutral — "Reasonable. Skim the top always-loaded sources to see if anything is unexpectedly large."
  • Low (<10k): encouraging — "Tight setup. The model has plenty of room for the actual work each turn."