Skip to content

Adopt the content-mutation disclosure clause across the remaining autofix hooks #1596

Closed

Description

@kyle-sexton

Summary

docs/conventions/hook-observability/README.md gained a third sanctioned systemMessage situation:
a hook that rewrote the user's file content without being asked must name what it changed on the
user channel, bounded by a per-run cap. Its Conformance list now carries:

Every path on which the hook rewrote file content names what it changed on the user channel,
bounded by a per-run cap with the remainder reported as a count.

Two plugins conform: typos-format (#1578) and markdown-format (#1589). Every other autofix hook in
the fleet rewrites file content on Write/Edit and reports nothing about it, so the clause landed
with a set of silently non-conformant siblings and nothing tracking them. This issue is that tracker.

Why the clause exists

The harness's only signal for a hook-applied rewrite is a generic "PostToolUse hook modified <file>
after your edit (likely a formatter)" line — no hook name, no diff — and the hooks reference
(https://code.claude.com/docs/en/hooks) documents no file-change channel a hook could use instead.
So a benign reflow and a wrong rewrite arrive identically. typos-format is where that became a real
harm: a dictionary autocorrect rewrote domain terms into unrelated English words across several files
in one session, and no channel ever named the hook.

Candidates to walk

Each of these applies an autofix on Write/Edit:

  • eol-normalizer — rewrites line endings, and is extension-unscoped like typos-format was.
  • ruff-format
  • bash-format
  • go-format
  • powershell-format
  • biome-format

What the walk should decide per plugin

The clause is about content the user did not request, and the cost of over-applying it is real: a
systemMessage on every edit that touched trailing whitespace is noise, and the convention already
names over-application a conformance defect. So the per-plugin question is not "add a message" but:

  1. Does the tool report what it changed, or only that it changed something? Report what there is,
    and say so when that is only a count — markdown-format reports Attempted: N fixes because that
    is genuinely all markdownlint-cli2 offers.
  2. Can a rewrite change meaning rather than only layout? A dictionary word substitution can; a
    trailing-whitespace strip cannot. That difference should drive how loud the disclosure is, and if
    the answer is "layout only", record that as the reason rather than leaving it implicit.
  3. Is there a no-op path where nothing was written? It must stay silent.
  4. Is the per-run list capped with the remainder as a count?

An outcome of "this hook's rewrites are purely structural and the agent channel is sufficient" is a
legitimate result — but it should be written down in the plugin and reflected back into the
convention, not left as an unexplained gap.

Related

The two conforming implementations are the reference: plugins/typos-format/hooks/typos-format.sh
(names each rewritten token, its replacement, and its line, capped at ten with the remainder as a
count) and plugins/markdown-format/hooks/markdown-format.sh (reports the fix count, and says
explicitly that a count is all the tool provides).

Activity

  1. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Admission gate: work-class: scoped, feature-shaped (a multi-plugin design walk deciding disclosure treatment per hook, not a like-for-like bug fix) → human-gated per the work-loop lane's admission table (C3 feature-shaped is operator-tightened to human-gated). Routed to human-gated; not dispatched.

  2. added
    needs-human
    on Jul 26, 2026
  3. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    The clause this issue tracks is now live in docs/conventions/hook-observability/README.md, landed with #1580, and both reference implementations are merged:

    Two things learned building those, worth having before the next adopter starts:

    1. Capping the entry count is not capping the message. Ten entries of arbitrary file text is still unbounded text. Both an entry cap and a character bound are needed, and the character bound needs headroom because JSON escaping expands a string past its character count.
    2. Say what the tool actually knows. markdownlint-cli2 reports no per-fix detail, so markdown-format reports a count and states that limitation rather than implying more. An honest thin disclosure beats an inferred rich one.

    The six candidates in the list above are unchanged, and the per-plugin question stays the one this issue already frames: not "add a message" but "can this rewrite change meaning, or only layout" — and if the answer is layout-only, write that down as the reason rather than leaving the gap unexplained.

  4. kyle-sexton commented on Jul 30, 2026

    @kyle-sexton
    MemberAuthor

    This issue's premise needs a correction: markdown-format does not conform to the disclosure clause. An independent agent audit of 0.8.4 found its disclosure path is unreachable in practice, so the conformance list here is carrying a false green.

    The disclosure never fires

    markdown-format.sh:705-712 scans the linter's stdout for a line beginning Attempted::

    "Attempted: 0 fixes"*) ;;
    "Attempted:"*) FIXES_LINE="$line" ;;

    The installed markdownlint-cli2 is v0.18.1, and that string does not appear anywhere in the package — not in source, README, or its 46-version changelog. Observed stdout of a real --fix run that did rewrite the file:

    markdownlint-cli2 v0.18.1 (markdownlint v0.38.0)
    Finding: m1/a.md
    Linting: 1 file(s)
    Summary: 0 error(s)
    

    So FIXES_LINE stays empty, SYSMSG is never set, and after a successful --fix the residual finding count is often zero, leaving CTX empty too. hook::emit_channels returns early when both channels are empty — so the hook emits nothing at all on a run that rewrote the user's file. Reproduced three times, including by direct hook invocation.

    What the user actually saw was Claude Code's own generic PostToolUse hook modified <path> after your edit (likely a formatter) line. That comes from the harness, not from this plugin.

    Consequences for the conformance claim:

    • README.md:14-18 states "the count of fixes written is reported to Claude and to you — a run that changed your file never passes unannounced." False as shipped.
    • CHANGELOG.md:146-151 states this was fixed and names Attempted: N fixes in 1 file as the count "markdownlint-cli2 reports". It does not report it.
    • The citation in this issue for markdown-format's conformance is markdown-format re-emits whole-file lint output on every touch, unbounded #1589, which is a different issue entirely — "markdown-format re-emits whole-file lint output on every touch, unbounded", closed 2026-07-26. It is not a disclosure implementation.

    Why it is a version-dependency defect, not a fictional contract

    Upstream check, so the report is accurate: markdownlint-cli2 0.23.1 added "Show attempted fix counts after fixing", confirmed present in current source at 0.23.2, emitted via pluralize and only when the count exceeds zero. So the parse targets a real contract — one that exists only in cli2 ≥ 0.23.1.

    The plugin resolves cli2 from PATH and ships no version pin or check. So whether a consumer gets rewrite disclosure is decided by their local install, and the failure mode is silent. That is a more durable defect than a parse bug, and it means conformance here cannot be established by reading the code alone — it depends on the consumer's environment.

    Two details for whoever fixes it: the hook's "Attempted: 0 fixes"* branch is unreachable even upstream, because the line only prints when the count is non-zero; and Attempted: N fix(es) in M file(s) is a paraphrase of the pluralize call rather than the literal output.

    Suggested fix, which moots the version dependency entirely

    Stop parsing the linter's stdout. Hash the file before and after the --fix call and report on difference. The hook already uses git hash-object for its finding-digest gate (markdown-format.sh:766), so this needs no new dependency, is immune to the linter's output contract and version, and is what would make the README's existing claim true.

    Add at least one assertion driven by the real binary. The current test suite stubs markdownlint-cli2 with a script that emits the missing line (markdown-format.test.sh:1480, asserted at 1764 and 1769, with a comment at 1454 describing Attempted: N fixes as "the … line markdownlint-cli2 [emits]"). So the stub encodes a newer version's output contract than the binary the hook runs against, and the suite passes green while the shipped behaviour is silent. That is why this shipped.

    Related, and the reason this matters beyond disclosure

    The same audit found the hook rewrites content outside any repository, because the git-working-tree scope guard sits inside if [[ -z "${CLAUDE_PROJECT_DIR:-}" ]] (lines 100-108) — the branch that does not execute under Claude Code. Proven by A/B with identical payloads on a file in a non-git directory: with the variable unset the file was unchanged; with it set to the session root the file was rewritten, and the hook said nothing.

    Two content mutations were observed under built-in defaults, in files under ~/.claude/plugins/data/:

    • MD004 (ul-style, default consistent, fixable) normalised a quoted changelog line's leading plus sign to a hyphen, falsifying a quotation.
    • MD018 (no-missing-space-atx, fixable) inserted a space into a line-leading issue reference, turning #1426 into # 1426 — destroying the reference and fabricating a top-level heading, which the hook then reported as MD025 and MD022. It generated two findings by applying a third.

    Both are the same class: an auto-fixable style rule mutating prose whose first character is markup-significant. A hook cannot distinguish a literal plus or hash in prose from a marker, because at the CommonMark level there is no distinction to make — which is exactly why the opt-in and the disclosure are the load-bearing controls rather than smarter detection. That makes this issue's clause the right lever, and makes the false green here the thing worth fixing first.

    Note MD018's trigger is the commonest prose shape in this tracker: a line beginning with an issue number. Anyone drafting issue prose through a tool this hook touches is exposed.

    Cheapest fix for the scope half

    Adopt this author's own doctrine from the same marketplace: bash-format refuses to run when the repo has no shfmt config, "so the plugin never imposes a style you did not [choose]" (bash-format/0.5.0/README.md:21). Applying that here — no discoverable markdownlint config means report-and-skip, never --fix — closes the quote falsification, the MD018 reference destruction, the unreachable-advice problem, and ~115 unactionable MD013 findings in one change, using machinery collect_risky_configs already has.

  5. kyle-sexton commented on Aug 12, 2026

    @kyle-sexton
    MemberAuthor

    Drain: tracked by open PR #2477 feat(powershell-format): disclose formatter rewrites on the user channel (no duplicate opened).

  6. 13 remaining items

  7. kyle-sexton commented on Aug 12, 2026

    @kyle-sexton
    MemberAuthor

    Frontier disposition (drain session)

    Ruling: promoted to agent-ready. The convention is already codified in docs/conventions/hook-observability (the third sanctioned systemMessage situation with a per-run cap), two plugins already conform as reference implementations, and the remaining work is mechanical adoption across the enumerated autofix hooks. No open design question remains for a human.

  8. added
    agent-ready
    and removed
    needs-human
    on Aug 12, 2026
  9. added theissue type on Aug 13, 2026
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-ready

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions