Skip to content

disk-hygiene: whole-machine audit driven by an orchestrator and subagents (no model-invocable audit, 250k cap needs manual splitting, guard and output gaps) #5214

Description

@kyle-sexton

What happened

I ran /disk-hygiene:clean across a whole WSL home directory. An orchestrator session drove it and dispatched subagents to do the scanning. The audit finished, but four things made this use harder than it should be. The installed version was 0.28.9. I re-checked each point below against origin/main (0.28.14) and none of them has changed.

Related work that already exists: #4009 (closed, added --sizes-only and the fan-out worker brief), #4004 (open, a home-directory audit on Windows), #2618 and #4228 (belt scope and subagent reach), #3348 and #4261 (guard denial text).

1. The skill cannot be invoked by a model, so an orchestrator cannot run even the read-only audit

plugins/disk-hygiene/skills/clean/SKILL.md:5 sets disable-model-invocation: true, and the description says "manual-only". An orchestrator session or a subagent therefore cannot load the skill. The worker I dispatched had to call scripts/hygiene.py scan directly, without the skill's instructions, and rebuild the flags from the worker brief.

Expected: the read-only audit (scan, classify, report) can be started by a model, so a session can delegate an audit. --execute and the removal lane stay user-only.

Suggested direction: split the read-only audit into a model-invocable skill or action, and keep the --execute path behind the existing user-only confirmation gate.

2. Whole-home scans hit the entry cap and there is no automatic split

Repro: run a whole-home inventory with --confirmed-large-scan. It exits 2 with:

snapshot exceeds 250000 entries; rerun with --max-depth or split the audit into bounded subtrees

The cap is MAX_SNAPSHOT_ENTRIES = 250_000 at skills/clean/scripts/hygiene.py:34, raised at hygiene.py:2009. Selecting children with --root-children hits the same cap when the selected children are large. There is no multi-target form and no automatic split, so the worker divided home into four runs by hand and merged the results. --sizes-only returns exact totals but writes no per-entry inventory (entries: 0, no findings), so every audit needs a second pass over each subtree. Each scan took minutes.

Expected: one command that audits a large tree, either by accepting several targets or by splitting on the depth-1 frontier itself and returning a documented set of snapshots.

Suggested direction: an --auto-split option (or a documented orchestration helper) that uses the --sizes-only frontier to plan bounded subtree scans, runs them, and reports coverage. At a minimum, make the cap error name the largest children so the caller can choose the split.

3. Guard ergonomics: the engine gate blocks read-only inspection and does not say which token failed

The denial text is accurate about scope: it says the gate is always on and that "/disk-hygiene:clean need not have been invoked" (skills/clean/scripts/destructive_guard.py:1838). Two things still cost retries:

  • Any command that contains the engine filename is gated, including read-only inspection of the plugin's own source. While preparing this report, git show of the engine file, cp of it, and grep over it were each denied. A pipe such as | tail after an engine call is denied for the same reason. The only way around it was a glob that avoids spelling the filename.
  • Required flags must open the invocation in declaration order (--target, then --output), then optional flags follow in any order (lib/engine_grammar.py:17-25; flag declarations near lines 158-219). Putting --root-children before --output is denied, although argparse would accept it. The denial lists the allowed shapes and the interpreter, but never states the ordering rule or which token broke it.

Suggested direction: (a) allow read-only inspection commands (grep, git show, cat, cp) that only name the engine as an operand, or say in the denial that such commands are gated; (b) have the denial name the failing token and state the rule, for example "required flags first: --target, --output".

4. Output shape and ownership gaps

  • The snapshot carries per-entry hints with a confidence_ceiling, but no per-tier counts or bytes. A summary such as "how many medium-tier entries, how many bytes" needs jq over the whole file. A tier_counts block (count and reclaimable bytes per ceiling) in the snapshot and in the stdout summary would remove that step for orchestrators.
  • The baseline hint common-temp-file (skills/clean/reference/baseline-policy.json:27, pattern *.tmp, ceiling medium) matches ~/.codex/.tmp, a 55 MB directory the codex CLI manages. The hint reason says "provenance and live ownership still need proof", so this is by design, but nothing in the engine identifies the owner. This is the same shape as disk-hygiene:clean — audit of a real home-directory run (Windows, v0.23.3): 726 bytes engine-eligible against ~60 GB product-managed; 9 decisions and 1 bug #4004 and disk-hygiene: add a gated managed-state lane with a bundled owner registry #4006 (owner registry). A small known-owner list (.codex, .claude, and similar) that annotates or lowers matches would cut false leads.
  • --project-dir is optional (hygiene.py standing_policy_paths skips the project layer when it is absent), but SKILL.md and reference/fan-out-worker-brief.md show --project-dir "${CLAUDE_PROJECT_DIR}" in every template. From a session whose project is not the target, for example a home-directory session, there is no guidance on whether to omit it. One sentence in the worker brief would settle it.

Activity

  1. added
    needs-triage
    on Sep 29, 2026
  2. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Found while running disk-hygiene and repo-hygiene over a whole WSL machine from an orchestrating session with subagents.

    Additional evidence for items 1 and 3, from an independent check of 0.28.13 against origin/main (0.28.14). Nothing below is fixed on main.

    Item 1: even with a model-invocable audit, a delegated worker cannot build a valid command.

    • The "disk-hygiene guard values" note (hook_python, data_root) comes from a UserPromptExpansion hook in hooks/hooks.json whose matcher is disk-hygiene:clean$. It fires only when a person types the command, so no orchestrator or subagent ever receives it.
    • skills/clean/reference/fan-out-worker-brief.md gives workers scan templates containing literal ${CLAUDE_PLUGIN_ROOT}, ${CLAUDE_PLUGIN_DATA}, ${CLAUDE_PROJECT_DIR} and <hook-python>. A worker cannot expand them, because the guard rejects shell expansion. Today the only way to learn the real values is to send a command the guard will deny and read them from the denial text. SKILL.md (around lines 115-117) describes that step for the probe, but the brief does not.
    • The brief says --data-root must match "the plugin data directory the belt authorized". Inside a subagent, the plugin-level engine gate enforces it, not the frontmatter belt.
    • SKILL.md:159 says "Create a unique run directory under ${CLAUDE_PLUGIN_DATA}/runs/". The guard denies mkdir, and the engine already creates the parent of --output itself (write_json calls mkdir(parents=True, exist_ok=True), hygiene.py:285 on main). Following the step as written produces a denied call.

    Desired addition: the parent fills hook_python, data_root, the engine path and the run directory into the brief before spawning, and/or the brief documents a one-call bootstrap through the argument-free kill-switch probe. SKILL.md:159 should say "choose a unique run directory path; the engine creates it".

    Item 3: the gate is the hooks.json if filter, and a search string is enough to trip it.

    The plugin-level registration is "if": "Bash(*hygiene.py*)", so the substring anywhere in the command routes it to the engine-gate check. Besides git show and grep, a gh issue list --search "... hygiene.py ..." was denied too. Related: #4218 (same fault, PowerShell lane).

  3. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Triage: human-gated

    Summary: Four independent items bundled: (1) a model-invocable read-only audit skill, (2) --auto-split or a cap error naming the largest children, (3) guard ergonomics (denial names the failing token; allow read-only mentions of the engine name; overlaps #4218), (4) doc/output nits. Confirmed on main: the skill is disable-model-invocation: true, the run-dir instruction conflicts with the guard, and the guard's *hygiene.py* substring gate fires on a plain grep.

    Open question: (1) Is a second, model-invocable read-only audit skill wanted, given manual-only was deliberate? (3) How far may the guard relax?

    Evidence that settles it: the maintainer's policy decision on (1) and (3)

    RECOMMENDED: split into four issues. Item 4 is delegable now: the skill and fan-out brief say the engine creates the run dir, the parent fills hook_python/data_root/engine path into the brief, and --project-dir is optional. Item 3 folds into #4218; the known-owner list overlaps #4004/#4006.

  4. added
    needs-human
    and removed
    needs-triage
    on Sep 29, 2026
  5. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Owner decision (2026-09-29): Split this issue into four separate issues now. Items 1 (a model-invocable read-only audit skill) and 3 (relaxing the engine guard for read-only mentions) are decided with evidence: an agent gathers whether a read-only-only skill can be made unable to reach --execute, and which read-only command heads may name the engine, and posts it here. Items 2 and 4 (cap error naming the largest children; docs and output nits) proceed as their own issues.

    Next: an agent files the four issues, posts the evidence for items 1 and 3 on this issue, then stops. Because the guard and deletion safety are security-class, the owner makes the final call on items 1 and 3.

  6. added
    agent-ready
    on Sep 29, 2026
  7. kyle-sexton commented on Sep 30, 2026

    @kyle-sexton
    MemberAuthor

    Owner decision (2026-09-29) followed: the issue is split into four, and the evidence for items 1 and 3 is below. This comment changes no code.

    The four new issues

    Item 1 evidence: can a read-only-only skill be made unable to reach --execute?

    Checked at 074e08088 (origin/main when checked; nothing under plugins/disk-hygiene differs at the current head). I ran destructive_guard.py directly with synthetic Bash payloads, in both --mode engine-gate (plugin-level, always on) and --mode belt (skill frontmatter), using the hook's absolute interpreter and the plugin data root.

    Command shape engine-gate belt
    scan --target ... --output <run dir>/s.json --data-root ... allow allow
    preview --snapshot ... --plan ... --data-root ... allow allow
    apply --execute --snapshot ... --plan ... --confirm-tier high --approval-token ... --report ... --data-root ... ask ask
    • The guard never answers allow to apply --execute. It returns ask in both modes, so the harness must put a permission prompt to the user. This is the only deterministic barrier in front of deletion. It is a property of the guard, not of disable-model-invocation, so a model-invocable skill that shells out to the same engine meets the same ask.
    • The plugin-level gate does not forbid apply. It admits the apply shape (as ask) whether or not /disk-hygiene:clean was invoked; its denial text says so. The current model-invocation ban therefore does not make deletion unreachable: any session can already run the scan, preview and apply shapes.
    • The engine adds a second check that needs no harness: apply refuses unless --execute, --confirm-tier (equal to the plan's tier) and --approval-token (equal to the token a fresh preview computes; hygiene.py around lines 4549-4556) all hold. A model can derive the token by running preview, so the token is a consistency check, not consent. Consent is the ask prompt plus the AskUserQuestion step in SKILL.md.
    • A read-only skill whose own frontmatter hooks deny the apply shape would not cover subagents. SKILL.md lines 213-221 record that skill-frontmatter hooks do not reach subagents (basis disk-hygiene: small items: recycle-or-permanent choice, absolute protect globs, belt does not reach subagents, SKILL.md understates Bash allowlist #4228, Claude Code 2.1.278, not re-probed here), and the orchestrator case in this issue is a subagent. So "structurally unable to reach --execute" can only be enforced at the plugin level (a new guard mode) or in the engine (a read-only subcommand set).
    • Not probed: how ask behaves when no one can answer (a headless --bg run, or bypassPermissions). AGENTS.md notes a hook ask can open a dialog nobody answers. The answer decides whether ask alone is enough for an unattended orchestrator.

    What this supports: a model-invocable audit skill that only documents the scan shapes adds no deletion reach beyond what exists today, but it cannot be made structurally unable to reach apply. The choice for the owner is whether the existing ask plus the token is an acceptable floor, or whether a plugin-level read-only mode must exist first.

    Item 3 evidence: which read-only command heads may name the engine?

    Same method, engine-gate mode. The hooks.json filter is "if": "Bash(*hygiene.py*)". In the guard, a mention only defers when it is provably not an invocation (_engine_gate_relevant, destructive_guard.py:688); anything the parser cannot prove is a mention fails closed into the gate.

    Command shape engine-gate
    git show origin/main:<relative path to engine> defer (allowed)
    git grep -n foo -- <relative path>, git log -p -- <path>, git diff -- hygiene.py defer
    grep -n foo <relative path> defer
    rg foo hygiene.py, echo hygiene.py (bare name) defer
    grep, cat, head, rg, cp with the absolute engine path as operand deny
    git show <relative path> | head -50 deny (any pipe, redirect or ; after a mention)
    git show ... > /tmp/x.py deny
    gh issue list --search "hygiene.py in:body" deny
    gh issue view 5214 --comments | grep hygiene.py deny
    sudo grep x hygiene.py deny
    /usr/bin/ls <engine path>, /usr/bin/stat <engine path> ask
    valid scan followed by | tail -5 deny
    scan with --output before --target, or --root-children before --output deny

    What decides the outcome:

    • A read-only head is denied when its operand resolves to the bundled engine file (absolute path), or when the command carries an operator (pipe, redirect, ;, substitution) or any shape the literal parser cannot prove is a mention.
    • The denial text lists allowed shapes and the interpreter, but not the failing token or the ordering rule (required flags first, in declaration order: lib/engine_grammar.py:17-25).
    • Constraints for relaxing: the gate documents itself as "a belt, not the authority", with accepted residuals for copied or aliased engines. One more residual, observed here: an engine spelled with a mid-word quote (hygien'e'.py) defers in engine-gate mode, including for the apply shape (so the ask never fires from this gate), while the belt denies it. A grep or cat allowance would sit next to that gap, but any rule that admits operators after a mention widens the same fail-open class.
    • Overlap: disk-hygiene: PowerShell lane denies commands that merely mention engine script names in string data #4218 (same fault, PowerShell lane).

    Final call

    The engine guard and deletion safety are security-class, so the final call on items 1 and 3 stays with the owner, and #5214 stays open with needs-human. I opened no PR and changed no code. #5517 and #5520 proceed as their own issues.

  8. kyle-sexton commented on Sep 30, 2026

    @kyle-sexton
    MemberAuthor

    Owner decision (2026-09-30): close as completed per consensus batch 4 (three read-only researchers, unanimous or majority; record in .work/drain/consensus-proposals-4.json). The owner: "I don't want anything blocked. I want us to keep chewing through the PRs and issues till we're at zero."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyneeds-human

    Fields

    No fields configured for Feature.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions