Skip to content

Refuse a save over a project another session saved - #8

Merged
bruw merged 1 commit into
mainfrom
stale-file-guard
Oct 20, 2026
Merged

bruw merged 1 commit into
mainfrom
stale-file-guard

Conversation

@bruw

@bruw bruw commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Address karanb192/awesome-claude-code-mods#362

Two sessions sharing a root could overwrite each other's project saves without either one noticing. Now a save first checks the file against what this session last read from or wrote to it. If another session saved the file since, nothing is written.

What changes

Board edits (keys, clicks, typed text): the board loads the other session's file, and a notice says why.

  • One u brings back the user's version, with the refused edit made on it, and saves it. A second u goes back to before that edit.
  • If the clash came from pressing Enter in a field, the field stays open with the typed text, so Enter sends it again on top of the other session's version.

Claude's edits (apply, write, attach): the edit is refused with nothing changed, whether the board is open or closed.

  • If Claude had read the project, its next edit is also refused until it reads it again.
  • The refusal and the notes added to Claude's prompts say the change came from another session, not "changed on the board by hand".
  • If Claude never read the project, its edit is checked against the current file instead.

Where the check happens

  • Saves, project list reloads, opening a project for a run, and the tool's read all go through one record of the file per project.
  • A save that fails for any other reason leaves that record as it was, so the next edit doesn't falsely clash.
  • When Claude writes the file with its own Write or Edit tools, that counts as this session's write.
  • If a plugin reload loses the record while the board stays open, saves compare against the board instead, as they did before this change.

Undo or redo during a clash: the undo history goes back to where it was before the step.

Other: version 0.4.2 → 0.4.3, and one line in docs/SPEC.md.

Known gaps

  • A save that lands between the read and the write is still lost, because the engine has no write-if-unchanged.
  • There's no merge or side-by-side view: the user keeps one version or the other.
  • Text in a field that closes by losing focus, rather than by Enter, isn't put back in the field. It's still in the version one u brings back.

Testing

  • bun run check passes: validation, tsc and 178 tests.
  • New unit test for sameProject.
  • Hook tests:
    • Board open: an apply refused after another session's save, then accepted after a re-read.
    • Board closed: a write from an older read is refused and the file left alone. This test fails if the closed-board check is removed.
  • Board key paths (clashes, undo, typed text) have no automated tests, because the hook test harness can't drive board keys. I checked each by hand with two Claude sessions in tmux:
    • a board edit on a stale board
    • u to get back their own version, with history kept
    • undo during a clash
    • Claude's two refusals and their wording
    • reloading from the project list and the note Claude then gets
    • a closed-board write
    • typed text kept and then sent on top of the other session's version

Each project's file is checked, before a save, against what this session
last read from or wrote to it. Where another session saved it since, nothing
is written: the board takes the file, and an edit Claude made from an older
read is denied until it reads the project again, with Claude told the change
came from another session.

On the board, one undo brings back the person's version with the refused
edit made on it; text typed in a field stays there to be sent again.

Claude-Session: https://claude.ai/code/session_01KAmaXmom3mXgvd45vXco4U
@bruw
bruw merged commit cb090fa into main Oct 20, 2026
4 checks passed
@bruw
bruw deleted the stale-file-guard branch October 20, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant