Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(transcript): key project dirs the way Claude Code actually does

Chaitanya Giridbdeef7f8684
diff --git a/package.json b/package.json
index b4dbbb19..bf20f0b3 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
"typecheck:node": "tsc --noEmit -p tsconfig.node.json",
"typecheck:web": "tsc --noEmit -p tsconfig.web.json",
"typecheck": "npm run typecheck:node && npm run typecheck:web",
- "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs",
+ "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/transcript-project-dir.test.cjs",
"dist": "npm run build && electron-builder",
"dist:mac": "npm run build && electron-builder --mac",
"dist:win": "npm run build && electron-builder --win",
diff --git a/src/main/transcript.ts b/src/main/transcript.ts
index e4630ad8..e35f2b84 100644
--- a/src/main/transcript.ts
+++ b/src/main/transcript.ts
@@ -3,17 +3,49 @@ import os from 'node:os';
import path from 'node:path';
import { estimateCostUsd, normalizeModel } from './pricing';
-/** Resolve the Claude Code transcript directory for a given working directory.
- * Claude Code stores per-project transcripts under ~/.claude/projects, keying
- * each project by its absolute cwd with the leading slash dropped and every
- * remaining slash turned into a dash (e.g. /Users/me/app → Users-me-app). On
- * Windows EVERY non-alphanumeric character is dashed (drive colon and
- * backslashes included): C:\Users\me\app → C--Users-me-app. */
-export function projectDir(cwd: string): string {
- const key = process.platform === 'win32'
- ? cwd.replace(/[^a-zA-Z0-9]/g, '-')
+/** Claude Code's project key: the absolute cwd with EVERY non-alphanumeric
+ * character turned into a dash — the leading slash and any dots included.
+ * /Users/me/app → -Users-me-app, /Users/me/MDv0.3.0 → -Users-me-MDv0-3-0,
+ * C:\Users\me\app → C--Users-me-app.
+ *
+ * One rule for every platform. The Windows branch always used it; POSIX had its
+ * own narrower spelling, and that divergence is what broke — see projectDir. */
+function projectKey(cwd: string): string {
+ return cwd.replace(/[^a-zA-Z0-9]/g, '-');
+}
+
+/** The pre-2026 POSIX key: leading slash DROPPED, only slashes dashed, so dots
+ * survived (/Users/me/MDv0.3.0 → Users-me-MDv0.3.0). Kept solely so transcripts
+ * written before the change stay readable. */
+function legacyProjectKey(cwd: string): string {
+ return process.platform === 'win32'
+ ? projectKey(cwd)
: cwd.replace(/^\//, '').replaceAll('/', '-');
- return path.join(os.homedir(), '.claude/projects', key);
+}
+
+/** Resolve the Claude Code transcript directory for a given working directory:
+ * ~/.claude/projects keyed by cwd.
+ *
+ * We used to emit the legacy key unconditionally on POSIX, which silently
+ * stopped matching once Claude Code moved to dashing every non-alphanumeric.
+ * Nothing errored — every caller reads an absent directory as "no transcripts
+ * yet" — so the miss cost months of dead memory condensation (a long run of
+ * `condense-abort`s with zero successes) and a usage reconciler quietly reading
+ * nothing at all.
+ *
+ * Prefer the CURRENT spelling; fall back to the legacy one only when it exists
+ * and the current one does not, so pre-change installs stay readable. That order
+ * is not cosmetic: this harness itself created legacy-named directories by
+ * copying transcripts into them, so a fallback-first resolver would keep reading
+ * our own stale copies forever. When neither exists we return the CURRENT
+ * spelling, because callers that go on to create the directory must create the
+ * one Claude Code will actually read. */
+export function projectDir(cwd: string): string {
+ const root = path.join(os.homedir(), '.claude/projects');
+ const current = path.join(root, projectKey(cwd));
+ if (existsSync(current)) return current;
+ const legacy = path.join(root, legacyProjectKey(cwd));
+ return existsSync(legacy) ? legacy : current;
}
/** Ensure session `<sessionId>.jsonl` exists in `cwd`'s Claude project dir so a
diff --git a/test/load-ts.cjs b/test/load-ts.cjs
index 293efe3e..c8a255d3 100644
--- a/test/load-ts.cjs
+++ b/test/load-ts.cjs
@@ -24,7 +24,12 @@ function loadFile(filename) {
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
- strict: true
+ strict: true,
+ // Match tsconfig.node/tsconfig.web. Without it a default import of a CJS
+ // builtin (`import path from 'node:path'`) compiles to `path_1.default`,
+ // which is undefined at run time — the module loads fine and then explodes
+ // on first use. Test harness only; no shipped code compiles through here.
+ esModuleInterop: true
},
fileName: filename,
reportDiagnostics: true
diff --git a/test/transcript-project-dir.test.cjs b/test/transcript-project-dir.test.cjs
new file mode 100644
index 00000000..3c6befef
--- /dev/null
+++ b/test/transcript-project-dir.test.cjs
@@ -0,0 +1,121 @@
+'use strict';
+
+// Originally contributed by Vyapak Goyal (@gts-47) in #123, extended here with
+// the dotted-path cases that the first version's dot-free fixtures could not
+// catch.
+//
+// POSIX-only: projectDir() resolves against os.homedir(), which these cases
+// redirect via $HOME — a knob Windows does not honour.
+
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const os = require('node:os');
+const path = require('node:path');
+const loadTs = require('./load-ts.cjs');
+
+const { projectDir } = loadTs('src/main/transcript.ts');
+
+/** projectDir() resolves against os.homedir(), which POSIX reads from $HOME — so
+ * each case gets a throwaway home and never touches the real ~/.claude. */
+function withHome(run) {
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'md-transcript-'));
+ const prev = process.env.HOME;
+ process.env.HOME = home;
+ try {
+ return run(home, (key) => {
+ const dir = path.join(home, '.claude/projects', key);
+ fs.mkdirSync(dir, { recursive: true });
+ return dir;
+ });
+ } finally {
+ if (prev === undefined) delete process.env.HOME;
+ else process.env.HOME = prev;
+ fs.rmSync(home, { recursive: true, force: true });
+ }
+}
+
+test('an unseen cwd resolves to the CURRENT key, leading slash dashed', () => {
+ withHome(() => {
+ // The regression: this used to return 'Users-me-app', a directory Claude Code
+ // has not written to in months, so every read came back empty and every
+ // caller read empty as "no data yet".
+ assert.equal(path.basename(projectDir('/Users/me/app')), '-Users-me-app');
+ });
+});
+
+test('DOTS are dashed too, not just slashes', () => {
+ withHome(() => {
+ // The case a slash-only fix silently fails: Claude Code dashes EVERY
+ // non-alphanumeric, so a version-numbered project directory keys as
+ // MDv0-3-0. Dashing only the separators yields '-Users-me-MDv0.3.0', which
+ // Claude Code never writes to — and because the legacy fallback then finds
+ // the harness's own stale twin, the miss looks like a hit.
+ assert.equal(
+ path.basename(projectDir('/Users/me/Documents/MDv0.3.0')),
+ '-Users-me-Documents-MDv0-3-0'
+ );
+ });
+});
+
+test('every other non-alphanumeric is dashed as well', () => {
+ withHome(() => {
+ assert.equal(
+ path.basename(projectDir('/Users/me/my_proj (old)/v1.2')),
+ '-Users-me-my-proj--old--v1-2'
+ );
+ });
+});
+
+test('the current directory wins even when a legacy twin exists', () => {
+ withHome((_home, mkProject) => {
+ // Both spellings exist on a machine that ran the old code: the harness itself
+ // created the legacy twin by copying transcripts into it. Preferring the
+ // legacy one would mean reading our own stale copies forever.
+ const legacy = mkProject('Users-me-app');
+ const current = mkProject('-Users-me-app');
+ const resolved = projectDir('/Users/me/app');
+ assert.equal(resolved, current);
+ assert.notEqual(resolved, legacy);
+ });
+});
+
+test('the dotted legacy twin loses to the dotted current spelling', () => {
+ withHome((_home, mkProject) => {
+ const legacy = mkProject('Users-me-MDv0.3.0');
+ const current = mkProject('-Users-me-MDv0-3-0');
+ const resolved = projectDir('/Users/me/MDv0.3.0');
+ assert.equal(resolved, current);
+ assert.notEqual(resolved, legacy);
+ });
+});
+
+test('a legacy-only install still resolves, so old transcripts stay readable', () => {
+ withHome((_home, mkProject) => {
+ const legacy = mkProject('Users-me-app');
+ assert.equal(projectDir('/Users/me/app'), legacy);
+ });
+});
+
+test('a legacy-only install with dots resolves to its undashed twin', () => {
+ withHome((_home, mkProject) => {
+ // The legacy key kept dots, so the fallback has to keep them too — deriving
+ // it from the new key by stripping the leading dash would look for
+ // 'Users-me-MDv0-3-0' and find nothing.
+ const legacy = mkProject('Users-me-MDv0.3.0');
+ assert.equal(projectDir('/Users/me/MDv0.3.0'), legacy);
+ });
+});
+
+test('the real failing path resolves to the dir Claude Code actually writes', () => {
+ withHome((_home, mkProject) => {
+ // The exact cwd whose transcripts the condense step could not find (#123).
+ const cwd = '/Users/vyapakgoyal/Documents/HarnessAgents';
+ mkProject('-Users-vyapakgoyal-Documents-HarnessAgents');
+ mkProject('Users-vyapakgoyal-Documents-HarnessAgents');
+ assert.equal(
+ path.basename(projectDir(cwd)),
+ '-Users-vyapakgoyal-Documents-HarnessAgents'
+ );
+ });
+});