config-audit/commands/drift.md
Kjell Tore Guttormsen acd1cf1248 fix(commands): stop writing files no later step can read, and payloads nobody asked for
Dogfooding the four read commands (posture, tokens, manifest, whats-active)
surfaced four defect classes, all in the seam between what a command template
promises and what the scanner behind it actually does.

M-BUG-40, fifth arm: posture wrote four temp files it could never read back.
#49 closed the $$/cross-block class in four commands, but posture survived it —
and so did the guard written to prevent exactly this. The guard compared each
$$ path to the block that created it, so a path written once and then read via
prose had no second occurrence to flag. Measured live: written from PID 21614,
read attempted from PID 23772. The invariant is now blanket (no $$ in any temp
path), which also caught fix.md and feature-gap.md.

M-BUG-43: 6 of 7 scanners write their payload to stdout when --raw/--json is
set even when --output-file was given, and the templates redirected only
stderr. Measured: posture 255 182 B, whats-active 35 922 B, drift 28 316 B,
manifest 23 825 B, tokens 8 768 B. fix and feature-gap never read the file they
wrote, so both recovered one letter grade from a quarter-megabyte dump.

tokens swallowed --json and --with-telemetry-recipe: documented, never
threaded, so --json returned the humanized payload where the docs promise
byte-stable v5.0.0 output.

M-BUG-42: manifest's render contract asked for {load}; the payload carries
loadPattern, so the Load column rendered blank for all 96 rows.

Four new tests (1449 -> 1453), each verified red before the fix. The
render-contract test checks {field} names against a live payload from a
fixture, since a hardcoded key list would drift. Frozen v5.0.0 snapshots
untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VGCk9o27eWo9uXLjkZTXEq
2026-08-01 20:40:07 +02:00

4.9 KiB

name description argument-hint allowed-tools model
config-audit:drift Compare current configuration against a saved baseline — shows new, resolved, and changed findings [path] [--baseline name] [--save] Read, Write, Glob, Grep, Bash sonnet

Config-Audit: Drift Detection

Compare current configuration against a saved baseline to see what changed.

Arguments

  • $ARGUMENTS may contain:
    • A target path (default: current working directory)
    • --save: Save current state as baseline
    • --baseline <name>: Compare against a specific named baseline (default: "default")
    • --raw: Pass-through to the scanner; produces v5.0.0 verbatim diff output (bypasses the humanizer). Use when piping into v5.0.0-baseline diff tooling that depends on byte-stable output.

Implementation

Save a baseline

If --save is present:

Tell the user: "Saving current configuration as baseline..."

RAW_FLAG=""
if echo "$ARGUMENTS" | grep -q -- "--raw"; then RAW_FLAG="--raw"; fi
node ${CLAUDE_PLUGIN_ROOT}/scanners/drift-cli.mjs <path> --save --name <baseline-name> --json $RAW_FLAG 2>/dev/null

--save writes its human confirmation to stderr, which 2>/dev/null discards — pass --json so the {saved, name, path} object lands on stdout. Read stdout for confirmation. Tell the user:

### Baseline Saved

Captured current state as baseline "{name}".
Run `/config-audit drift` anytime to see what changed since this point.

Compare against baseline

Without --save:

Tell the user: "Comparing current configuration against baseline..."

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

Exit codes: 0 = stable/improving, 1 = degrading (both normal — present the result either way), 3 = a real error.

Then read /tmp/config-audit-drift.json with the Read tool. The default-mode report itself goes to stderr, so --output-file is the only way this command sees the diff at all.

Check _baselineAnchor first. If the baseline was saved from a different directory than the one being scanned, the diff is not a drift signal — every baseline finding shows as "resolved" and every current finding as "new", which renders as a falsely reassuring "improving" trend. When the anchor differs, say so plainly and offer to re-anchor with /config-audit drift --save instead of presenting the numbers as drift.

In default mode the diff sections are humanized — finding titles, descriptions, and recommendations have already been replaced with plain-language equivalents. New/resolved/changed finding lists carry userImpactCategory, userActionLanguage, and relevanceContext so you can group and prioritize without re-deriving severity prose. If --raw was passed, the v5.0.0 diff is verbatim — present it in a code block as-is.

If baseline not found, tell the user:

No baseline found. Save one first with:
  /config-audit drift --save

Otherwise, parse and present the drift report. Use the Read tool on the captured stdout (or pipe it into a tmpfile first if you prefer):

### Configuration Drift

**Trend:** {Improving|Degrading|Stable}
**Score:** {before} → {after} ({+/-delta} points)

{If new findings:}
#### New Issues ({count})
| ID | Action | Description |
|----|--------|-------------|
| {id} | {userActionLanguage — "Fix this now", "Fix soon", etc.} | {humanized title} |

{If resolved findings:}
#### Resolved ({count})
| ID | Description |
|----|-------------|
| {id} | {humanized title} |

{If area changes:}
#### Area Changes
| Area | Before | After | Change |
|------|--------|-------|--------|
| ... | ... | ... | ... |

When iterating new/resolved findings, prefer userActionLanguage over raw severity for the "Action" column — the humanizer already mapped severity to plain-language phrasing, and surfacing it consistently keeps the toolchain coherent. Mention relevanceContext when it isn't affects-everyone (the user wants to know if a fix touches shared config or just their machine).

List baselines

If $ARGUMENTS contains --list:

node ${CLAUDE_PLUGIN_ROOT}/scanners/drift-cli.mjs --list --output-file /tmp/config-audit-baselines.json 2>/dev/null; echo $?

The human-readable listing goes to stderr, which 2>/dev/null discards — read /tmp/config-audit-baselines.json with the Read tool and render the baselines array (name, findingCount, savedAt) as a table. If the array is empty, tell the user no baselines are saved yet and point at /config-audit drift --save.

What's next

After viewing drift:

  • /config-audit fix — Auto-fix new findings
  • /config-audit posture — Full posture assessment
  • /config-audit drift --save — Update the baseline to current state