Skip to content

Derive a moved project's path from a cwd that still exists - #115

Open
PirateIncognito wants to merge 1 commit into
doctly:mainfrom
PirateIncognito:fix/moved-project-path
Open

PirateIncognito wants to merge 1 commit into
doctly:mainfrom
PirateIncognito:fix/moved-project-path

Conversation

@PirateIncognito

Copy link
Copy Markdown

Problem

After a project folder is moved, its Claude projects folder (~/.claude/projects/<encoded>) can still hold a transcript recorded at the old location. deriveProjectPath used the cwd of the first .jsonl in directory order, so if that old transcript sorted first, the whole folder resolved to the old, now-missing directory:

  • every session in the folder was filed under the missing path, and the sidebar label came from it;
  • New session failed in open-terminal with project directory no longer exists: ...;
  • the renderer put that error in a terminal it never showed, so the button looked like it did nothing.

Fix

  • harnesses/claude.js deriveProjectPath: tries transcripts newest first and returns the first cwd that still exists (at most 10 are checked). If none exist, it falls back to the newest cwd.
  • session-cache.js planFolderRefresh: when a folder's resolved project path has changed, every transcript is passed through again so cached rows move to the new path. Unchanged transcripts resume from their end, so nothing is re-parsed.
  • session-cache.js reconcile gates: a folder whose recorded project directory no longer exists is re-planned once per run, so caches written by older builds correct themselves without waiting for a new session in that folder.
  • public/app.js launchNewSession: a failed launch now shows the terminal with the error instead of leaving it hidden.

Tests

  • test/harness-claude.test.js: a cwd that exists wins over a missing one, even when the missing one sorts first and is newer; when no cwd exists, the newest is used.
  • test/reconcile-cache.test.js: a folder cached under a missing directory, with an unchanged mtime, has all its rows re-filed under the existing path and is left alone on the next pass.
  • These new tests fail without the change and pass with it.
  • One existing test ("reconcileCacheFromFilesystem ... skips up-to-date ones") used /tmp/proj-current as its cwd. That path doesn't exist on Windows, so with this change the test would trip the new missing-directory re-check. It now uses a real temp directory and still tests the mtime gate.

I checked the fix on Windows against real data: a project that had moved out of a OneDrive folder, where New session did nothing before the fix and works after it. On Windows, some existing tests already fail on main (mostly path-separator assertions). This change doesn't touch them.

🤖 Generated with Claude Code

A Claude projects folder can hold a transcript from the project's old
location (e.g. an old session copied in after the project moved).
deriveProjectPath took the cwd of the first .jsonl in directory order, so
such a folder resolved to the old, missing directory; every session was
filed under it, and New session failed in open-terminal with "project
directory no longer exists". The renderer kept that error in a hidden
terminal, so the button appeared to do nothing.

- deriveProjectPath tries transcripts newest first and returns the first
  cwd that exists (up to 10 tried), else the newest cwd.
- planFolderRefresh passes every transcript through again when the
  folder's project changed, so cached rows move to the new path (an
  unchanged transcript resumes at its end, so no re-parse).
- Reconcile re-plans a folder whose recorded project directory is gone
  once per run, so caches written by older builds are corrected without
  waiting for a new session in that folder.
- launchNewSession shows the terminal holding a launch error instead of
  leaving it hidden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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