Skip to content

bug(markdown-format): PostToolUse hook deletes .md files after a successful Write/Edit (worktree-specific?) #1061

Closed as not planned

Description

@kyle-sexton

Lane: babysit (cycle 33/34, amendment-round 16).

Triggering example: worker-1033, babysitting melodic-software/claude-code-plugins#1033, reproduced this twice in its own worktree: editing SKILL.md and separately writing a brand-new throwaway ztest.md both returned a successful tool result, but the file was then gone from disk afterward (git shows the tracked file deleted; the new file never persisted). The worker did not modify guardrails and treated the deletion as systemic to markdown Write/Edit in that environment, likely triggered by the markdown-format plugin's PostToolUse hook (markdownlint-cli2 --fix "$FILE") rather than content-specific.

Observed: a markdown Write/Edit reports success, then the target file is deleted from disk.

Expected: the hook lints/auto-fixes in place (or fails loudly / no-ops) — it must never delete the file it was invoked on.

Category: bug (destructive — data loss on any markdown edit in the affected environment; also an operational blocker, since a worker fixing a markdown finding gets a false "success" and may believe it landed a fix that was actually silently lost).

Related pattern, not a duplicate: #1057 logged the same symptom class (a formatter's PostToolUse hook deleting the file it was invoked on, there bash-format's shfmt -w) on a different plugin. Worth checking whether both trace to a shared helper/pattern across the formatter-hook family, but filing separately since the two are different plugins/hooks with independent fixes.

Not a self-observation paper-cut: clears the DEFER-FORBIDDEN / destructive-finding bar (rule 3b class 1), filed standalone per the intake throttle's carve-out.

Recommended immediate mitigation for other workers: verify file survival (git status / re-read) after any markdown Write/Edit, before trusting the write and before committing.

Non-reproduction note from this orchestrator's own session: writing this very issue body as a markdown file in the main session's own working directory did NOT delete the file — markdown-format ran, reported lint findings, and the file survived normally. This suggests the deletion may be specific to worker-1033's particular worktree/environment (e.g. a detached-HEAD or symlinked worktree path, or a stale hook version cached there) rather than universal to every markdown-format invocation on this machine. Worth checking worktree-specific factors during triage rather than assuming a blanket repro.

Activity

  1. added
    needs-triage
    on Jul 22, 2026
  2. kyle-sexton commented on Jul 22, 2026

    @kyle-sexton
    MemberAuthor

    Confirmed and broadened by a second, independent worker (worker-1054, same cycle) — this is NOT markdown-specific. Its report:

    A PostToolUse hook fires on every Write/Edit and silently DELETES the tool-written file inside the babysit worktree on this machine. Confirmed reproducibly: first Edit to bugfix.md "succeeded" then vanished within seconds; re-writes of both the exact original content and a trivial .txt probe were also deleted immediately; git-written files (the git worktree add checkout, git merge origin/main) all persist fine. So it is NOT AV, NOT content-/name-triggered — it is the Write/Edit tool path specifically. Not in user or project-level settings.json PostToolUse hooks (none configured) — almost certainly one of the enabled melodic-software *-format/eol-normalizer plugin PostToolUse hooks botching an atomic-replace (write-temp/delete/rename) on Windows and leaving the file deleted. git checkout HEAD -- <file> was harness-DENIED (per safety.md's permission layer), so the worker correctly did not route around it.

    Orchestrator's own audit (this session, not yet fully independently reproduced): spot-checked this cycle's actually-pushed commits for silent corruption. Three commits that touched .md/.sh files via Write/Edit and were then committed+pushed this session (claude-code-plugins@d82de0ba, standards@c05179ec) show clean modified diffs with real additions/deletions, not removed/deleted-file entries — so at least these did NOT silently ship a deletion. The two reproductions above (worker-1033, worker-1054) both happened in worktrees that never reached a git-commit step (worker-1054 explicitly left its worktree dirty/unpushed), so the current evidence is: the bug is real and reproducible, but nothing has been confirmed to have silently corrupted an already-merged PR yet. Worth a broader retroactive audit before ruling that out entirely.

    Operational recommendation from worker-1054 (relayed, not yet acted on by the operator): halt file-mutating fixes fleet-wide until the offending hook is identified/patched, and audit recently-"fixed" PRs for missing/corrupted commits.

  3. kyle-sexton commented on Jul 22, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    TL;DR

    The markdown-format hook is exonerated — by code and by empirical repro in exactly the detached-HEAD linked-worktree context the reporter suspected. markdownlint-cli2 --fix rewrites in place; the hook has no unlink/rm/mv/temp-swap on any path. Every worktree-specific difference degrades to a harmless no-op or skip, never a delete.

    The reporter's own clue is the key: the hook fires on every .md Write/Edit in both the main session and the worker worktree, and in the main session it ran and the file survived. If the hook were the deleter, main would have reproduced too. It didn't — so the worktree-specific variable is not the hook; it is what else was running in that worktree: the PR-babysit loop. That loop contains a documented destructive working-tree op that explains both symptoms and the non-repro. Root cause is a strong, specific hypothesis but unconfirmed for worker-1033's exact run (loss-time state can't be reconstructed post-hoc) → needs-human.

    Host: melo-lap-001, Git-Bash MINGW64, markdownlint-cli2 v0.18.1 (markdownlint v0.38.0), typos-cli 1.44.0.

    Verified against #1057

    Empirical repro (throwaway git repo + linked worktree, scratch only)

    1. markdownlint-cli2 --fix on a real .md, direct (the accused command): file PRESENT, 45→41 bytes, rewritten in place. Not deleted.
    2. Full markdown-format.sh hook, .md inside a genuine detached-HEAD linked worktree (git-dir ≠ git-common-dir confirmed), real CC-shaped payload, CLAUDE_PROJECT_DIR set to the worktree: hook rc=0, SKILL.md PRESENT, 14→12 bytes (fixed in place: #Bad→# Bad, trailing spaces stripped). Not deleted.

    The detached-HEAD / linked-worktree context — the reporter's leading suspect — did not change the outcome.

    The actual worktree-specific deleter

    babysit-prs/reference/loop.md:405-407, §5.1.6 "PR done — transition to next":

    If a full-mode PR checkout ... has uncommitted changes from a failed fix: git reset --hard HEAD then git clean -fd (unstage + revert tracked + remove untracked)

    This runs only inside a babysit worktree on the PR-transition path — never in the main session. It maps to both symptoms precisely:

    • untracked ztest.md "never persisted" = git clean -fd removing untracked files.
    • tracked SKILL.md "shows deleted" = git reset --hard HEAD reverting/removing an uncommitted working-tree change (a new-but-uncommitted file is removed; an edit to a tracked file is reverted).

    Sequence that fits the report: the worker's Edit/Write did land on disk (tool returned success — correctly), then the loop's own §5.1.6 housekeeping wiped the uncommitted change while transitioning PRs, and the loss got misattributed to the markdown-format hook because it correlated in time with the markdown edit.

    Corroborating evidence:

    • The branch reflog for feat/976-find-handoff-skill (PR feat(session-flow): add find-handoff skill to recover a lost handoff (#976) #1033) shows only normal commits/merges — consistent with this mechanism: git clean leaves no ref trace, and git reset --hard HEAD does not move HEAD, so neither leaves a discriminating reflog entry.
    • This repo's own guardrails/block-dangerous-git.sh blocks both halves of the §5.1.6 combo — git reset --hard ("discards uncommitted work with no recovery path") and git clean -f ("permanently deletes untracked files"). Both fired against my throwaway repo during this investigation. The repo already classifies these as the destructive operations.

    Conclusion

    • Hook innocence: HIGH confidence. markdown-format cannot delete the file (code + repro).
    • Root cause: strong, specific hypothesis — the babysit §5.1.6 git reset --hard HEAD + git clean -fd cleanup — but not confirmed for worker-1033's specific run. I cannot reconstruct loss-time state, and the ops that fit leave no reflog trace by design.

    Recommendation

    Route needs-human. Named open question, answerable only from worker-1033's transcript:

    Did the babysit loop's §5.1.6 cleanup (git reset --hard HEAD then git clean -fd), or any equivalent git reset --hard / git clean -fd / git stash -u, run in worker-1033's worktree between the successful Edit/Write and the observed file loss?

    If confirmed, the fix belongs in babysit-prs §5.1.6, not markdown-format: the cleanup must not silently destroy uncommitted changes it cannot distinguish from "failed-fix cruft" (e.g. commit/stash intended edits before the destructive reset+clean, or narrow git clean scope), and workers should treat post-Edit git status verification as mandatory in the babysit loop (the reporter's suggested mitigation is correct). Do not patch markdown-format — a guard there addresses nothing.

  4. added
    needs-human
    wayfind: task
    and removed
    needs-triage
    on Jul 22, 2026
  5. added theissue type on Jul 22, 2026
  6. added
    agent-ready
    and removed
    needs-human
    on Aug 13, 2026
  7. kyle-sexton commented on Aug 13, 2026

    @kyle-sexton
    MemberAuthor

    Frontier disposition (drain session)

    Ruling: Promote to agent-ready.

    Small scoped bug with a bounded blast radius and enough specification for autonomous pickup. Removed needs-human, added agent-ready.

    Re-open trigger: If implementation reveals an unresolved design fork or security policy decision.

  8. kyle-sexton commented on Aug 13, 2026

    @kyle-sexton
    MemberAuthor

    Frontier disposition (drain session)

    Ruling: Close as not planned for this drain wave.

    Issue remains historically valuable but is either advisory, blocked on a larger carrier, or superseded by later conventions. Re-open with a concrete acceptance brief if a consumer needs the work this session.

    Title: bug(markdown-format): PostToolUse hook deletes .md files after a successful Write/Edit (worktree-specific?)

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-readywayfind: task

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions