Skip to content

fix: clone transcripts into the archive on APFS instead of copying - #196

Open
petrogurcak wants to merge 2 commits into
obra:mainfrom
petrogurcak:fix/clone-archive-copies
Open

petrogurcak wants to merge 2 commits into
obra:mainfrom
petrogurcak:fix/clone-archive-copies

Conversation

@petrogurcak

Copy link
Copy Markdown

Problem

conversation-archive mirrors every live transcript in ~/.claude/projects. While the original exists, the same bytes sit on disk twice. On my machine that was 21 GB + 21 GB, with the disk at 98 %. copyIfNewer also re-copies active transcripts on every sync, so the cost grows with each session.

Fix

cloneOrCopyFileSync replaces the four fs.copyFileSync calls (sync.ts and 3× indexer.ts). On macOS it clones with cp -c (clonefile(2)): the clone shares blocks with the original until either file changes, and it remains a separate, complete file when the harness later deletes the original. On other platforms, or if the clone fails (non-APFS volume), it falls back to fs.copyFileSync.

Why not fs.constants.COPYFILE_FICLONE: on macOS Node does not clone. COPYFILE_FICLONE silently does a full copy and COPYFILE_FICLONE_FORCE throws ENOSYS (Node 24.7). Measured on a 1 GB file: Node FICLONE uses 1024 MB, cp -c uses ~4 MB.

Verification

  • New test/clone-copy.test.ts (4 tests). A mutation that drops the cp -c call fails the test.
  • Full suite: 64 files / 354 tests pass.
  • Ran the patched build as my live plugin: sync archived 41 transcripts with no errors. Replacing the existing duplicates with clones freed 22 GB.

dist/mcp-server.js is left out: it doesn't bundle these copy paths, and my local rebuild only produced unrelated bundler drift.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MriYQJeeBh4Hb8g22gGuca

petrogurcak and others added 2 commits November 1, 2026 20:54
The archive mirrors every live transcript, so plain copies double their
disk use (21 GB -> 42 GB on one machine). On APFS a clone shares blocks
until either file changes, and the archive copy still survives when the
harness deletes the original.

Node cannot clone on macOS: COPYFILE_FICLONE silently falls back to a full
copy and COPYFILE_FICLONE_FORCE throws ENOSYS (Node 24). cloneOrCopyFileSync
uses `cp -c` (clonefile(2)) on darwin and falls back to fs.copyFileSync.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MriYQJeeBh4Hb8g22gGuca
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MriYQJeeBh4Hb8g22gGuca
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