Skip to content

Move a Kept Tree Whole in bootstrap.ps1, Since Move-Item Splits One Holding an Open File #2492

Closed

Description

@ptr727

bootstrap.ps1 swaps a kept tree with Move-Item, on the premise its own comment states: a rename of a directory in use fails whole on Windows. Move-Item does not fail whole. When the directory rename fails, PowerShell 7 falls back to moving the tree entry by entry, so every entry it can move lands at the destination and the held one stays behind, and the error is raised only after that.

Measured natively on Windows with PowerShell 7.6, a tree t holding .bootstrap-owned, a, and locked/file, with locked/file open under FileShare.None:

Move-Item -LiteralPath t -Destination t2   -> IOException
t:  locked, locked/file
t2: locked, .bootstrap-owned, a
[IO.Directory]::Move('t', 't3')            -> access denied, nothing moved

In Invoke-SwapIn, moving the live skills-tree aside while Claude Code holds a file in it therefore:

  • empties the live tree the plugin loads down to its held files, and the run dies saying only that the move failed
  • moves the ownership marker into skills-tree.old, so the next run finds an unmarked skills-tree and refuses it as "this loader did not create it", which is wrong, and its remedy, another -Dir, abandons the tree instead of repairing it

The same fallback applies to Invoke-SwapIn's rollback and to Invoke-Cleanup's restore, both of which move skills-tree.old back.

  • Fix direction: move a tree with [IO.Directory]::Move through one helper, so a rename either happens whole or not at all, which is what the swap's ordering already assumes. bootstrap.sh's mv within one directory is a single rename(2) and is not affected.

Found while driving the loader's functions natively for #1791.

Activity

  1. added
    bug
    pre-existing
    script
    on Oct 7, 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

    bugpre-existingscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions