You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(workspace-cleanup): setting to delete Claude Code chats of deleted workspaces - #42959
When Orca deletes a workspace, the Claude Code chats from that workspace stay on disk forever. On one machine that was 1,229 transcripts and 5 GB from workspaces that no longer exist. This adds a setting to Workspace Cleanup, off by default and marked Recommended, that deletes those chats once their workspace is gone.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$296
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$296
Prod
30
$\color{#1a7f37}{\Huge{\mathbf{+}}}$1413
$\color{#cf222e}{\Huge{\mathbf{−}}}$164
$\color{#1a7f37}{\Huge{\mathbf{+}}}$1249
What Changed
Setting: Settings → Workspace Cleanup gets a "Chat history" group with Delete chat history with the workspace. It's off by default and marked Recommended, like the merged rule. Turning it on asks first, because it also catches chats from workspaces deleted before today.
Per host: the setting belongs to the host that owns the workspaces. A paired host on an older Orca shows "Update Orca on " and is never sent the key, because settings.update is strict. The per-host switch hook is now generic (useHostBooleanSetting), shared with the Codex history-sharing switch.
When it runs: the cleanup runner sweeps chat history after its removals. That happens on startup, 10 s after the setting turns on, on Clean up now and on orca workspace cleanup run, and at most every 6 h from the hourly tick. It catches every way a workspace gets deleted (rules, the dialog, by hand, git worktree remove), because it looks at what is gone rather than hooking each delete path.
Reporting: runs record {deleted, failed, freedBytes}. The Activity list, the status line and the CLI show it, and an open session history list refreshes.
How a chat qualifies:
The folder: the transcript's recorded cwd sits under a folder that's gone. The deepest folder that still exists must be, by device and inode, one of Orca's nested <workspaces root>/<repo> folders with no .git. Flat roots never count, because they hold Claude Code's own .claude/worktrees and the user's projects.
Not listed: nothing Orca still lists is inside that folder: archived and renamed rows, folder projects, symlink targets. Identity comparison settles symlinks, case and Unicode.
Idle: right before each file is removed, the chat and its subagent transcripts must be idle for an hour, and their last recorded cwd must still be in the gone folder. A chat resumed in a live workspace is kept.
Permanent: deletion goes through AI Vault's validated delete, permanently (the Trash would free nothing). Caches are cleared once per batch.
Only Claude Code is swept for now. Claude records the cwd on every message, so a resumed chat can be told apart. Agents that record it once (Pi, OMP, Copilot, Cursor) can't show that and are left alone. Orca's own native chats and Codex follow in their own PRs.
Why
Part of #16776. Codex history is the remaining part, and that PR will close the issue and credit @maxmilian for #16990.
#16990 used a 90-day age cutoff. Review found it could delete live and same-path chats, and that deleting one hardlinked copy frees nothing. Tying deletion to "this chat's workspace is gone" deletes nothing anyone can still open in Orca, and needs no age cutoff. One switch next to the existing rules keeps it inside Workspace Cleanup instead of adding a sixth rule.
deleted-workspace-chat-history.test.ts runs the sweep against real temp folders. It deletes the gone workspace's chats, including one recorded through the physical (/private/var) spelling. It keeps:
live, archived, renamed and nested archived workspaces
folder projects, including one behind a symlink and one behind a dangling link
a .. sibling base, an unrelated clone with .git, and an old flat workspace named like a repo
an unmounted base, a trimmed-cwd lookalike, a row added mid-scan
recent chats, a chat resumed in a live workspace behind a 300 KB blob, a chat whose subagent still writes from a live workspace
Codex, Pi and remote-host rows
Each guard was checked by removing it and seeing the test fail.
pnpm check:changed: all 38 checks pass.
Measured on macOS against real data: 1,229 Claude transcripts (5.06 GB) whose nested Orca workspace folder is gone, 20 kept for live workspaces, 695 outside Orca workspaces kept.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
The risky part is permanent deletion of chat history. Every check fails toward keeping the chat: unknown, unreadable, recently written, resumed elsewhere, or still listed all mean keep. The setting is off by default, and turning it on asks first.
Cost: a sweep lists Claude sessions in AI Vault's scanner child process and stats the workspace parents. It runs at most every 6 h.
Older hosts: an older paired host is never sent the key, and older clients ignore the new chatHistory run field.
Out of scope: WSL paths are skipped and never touched.
Known gaps: other Orca profiles on the same machine, sharing one workspace folder, aren't read for their archived or renamed rows. A paired host's deletions can show in the desktop's history list for up to 15 s.
Backing out: a plain revert. Deleted transcripts can't be restored.
Level: Medium
AI Disclosure
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Cross-platform: paths are compared by filesystem identity (bigint dev:ino). Names are case- and NFC-folded off Linux; POSIX \ is kept.
Remote: each host runs its own sweep: desktop for local, each orcad for its own.
Mobile: nothing changes.
Folder workspaces: they're protected and never treated as deleted.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
The change adds an opt-in setting that lets workspace cleanup delete eligible Claude chat history associated with missing workspace folders. The sweep checks workspace listings, folder state, transcript activity, and cancellation before deletion. It records deletion counts and freed bytes in cleanup run results. The runner schedules sweeps, and the CLI and settings UI display their results. The settings UI includes a confirmation step when enabling the option.
Merge Risk: Low · up to 1fce4
The feature is off by default and confirmation-gated. A narrow race could still let a chat be permanently deleted after a workspace row changes during the cleanup scan. A few minor settings-UI issues also remain.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a new Workspace Cleanup setting that deletes Claude Code chats when their workspaces are deleted. The changeset matches this. It adds the setting, the sweep, the sched…
Description check
The description follows the repository template. It covers ELI5, What Changed, Why, Linked Issue (Part of #16776, which is an incomplete issue link under the template's 'Fixes #' rule), Visual Proof w…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: a new Workspace Cleanup setting that deletes Claude Code chats when their workspaces are deleted. The changeset matches this. It adds the setting, the sweep, the schedule, and the reporting. The title uses the conventional feat(scope) form and is specific enough for a teammate scanning history.
Full details: Description check
Explanation
The description follows the repository template. It covers ELI5, What Changed, Why, Linked Issue (Part of #16776, which is an incomplete issue link under the template's 'Fixes #' rule), Visual Proof with before/after images and a confirmation dialog image, a detailed Testing section, a Risk section with level, backout path, and cost, plus the Notes and Checklist. The AI Disclosure and Review sections are empty, but the template marks AI Disclosure as optional for internal contributors. The Linked Issue is a partial reference, not a 'Fixes #' closing link, and the PR body explains why. The description is thorough and mostly complete.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
146-150: Major · Data Integrity & Integration · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Recheck listed workspaces for each target.
The catalog check at Line 139 runs once for the entire folder. If a workspace row is added after the first target is processed, later targets still pass this callback while the folder remains absent. Those chats are deleted despite the new row that must protect them.
Refresh and check the catalog inside the per-target approval path. The existing fingerprint can avoid repeated filesystem reads when the catalog has not changed.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: b4146eb7-eb8d-43e7-8fe9-ef358c8e243a
Commits
Reviewing files that changed from the base of the PR and between 15329fd and d6df596.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Stop protecting listed paths when the symlink chain exceeds eight hops.
linkTargets collects at most nine paths. When a listed path has nine or more chained symlinks, the final target is never appended, and no returned path reaches a gone folder. The gone folder is then absent from listed.gone in both readListedFolders calls, so chats in that folder can pass the protection check. The hop < 8 bound also contradicts the comment at lines 115-116, which says the cap never deletes more.
Follow the chain with cycle detection. If the traversal limit ends with a link still unresolved, treat that listed path as unresolved and block deletion of the affected folders rather than omitting protection silently.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Quick win
Recheck companion versions before approving deletion.
If companion A receives a new message while the function checks companion B, the parent transcript can remain unchanged. Line 140 then returns true, even if A is now active or resumed in a live workspace. Permanent deletion also removes A.
Retain and recheck the companion versions and directory membership before approval. Do not use the parent's version as proof that its companions stayed unchanged.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Provide recovery after a failed settings read.
If the initial settings.get request fails or times out, this handler only logs the error. The hook stays in loading, so both switch consumers stay disabled until the component remounts.
Expose an error state with a retry action, or retry when the host reconnects.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Include chat-deletion failures in the collapsed summary.
If chatHistory has zero deletions and three failures, and no workspaces were removed or failed, this run displays “Nothing to clean, 0 kept.” The failure indicator reads only run.counts.failed, so collapsed runs hide every chat-deletion failure.
Add run.chatHistory.failed to the summary or failure indicator. Keep the expanded error details.
This companion has a recent filesystem mtime. isStillIdleInGoneFolder therefore rejects it before reading its cwd. The test would still pass if companion cwd validation were removed.
Set the companion's mtime to DAY_AGO. This makes the fixture exercise the live-workspace protection for permanent deletion.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: eb21ee7a-1548-4e1d-b7ec-6318ff12e9fb
Commits
Reviewing files that changed from the base of the PR and between d6df596 and 9f0dc54.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Adds an off-by-default host setting. When on, each cleanup run deletes agent
transcripts whose Orca workspace folder no longer exists, through AI Vault's
validated delete, and reports the count and space in the run's activity.
…a workspace
Skip workspace parents that are or hold a project checkout, protect folders
holding a still-listed workspace in any spelling, re-check each folder right
before deleting, batch scope paths, count companion bytes, sweep chats at most
every 6 hours on hourly runs, and refresh the report when the switch changes.
…eletable
Look for deleted workspaces only in <root>/<repo> of nested layouts, protect
renamed workspaces' earlier paths, folder workspaces and case variants, use the
recorded cwd only, re-check the parent and the setting before each deletion.
…m the chat sweep
Drop parents inside a still-listed workspace, also read this host's own
worktree rows, record a run only when a rule or a due chat sweep has work,
and cache per-folder protection with precomputed matchers.
…identity
Walk up from the recorded cwd to the deepest existing folder and require it to
be, by device and inode, an Orca <root>/<repo> folder without .git; key
protected paths the same way, so symlinks, case and Unicode spellings are the
OS's call. A failed history scan no longer fails the run, and an open session
history list refreshes after chats are deleted.
Walk physical ancestors of a symlinked parent, skip a gone folder with a
lookalike sibling (parsers trim cwd), re-read listed paths after the scan,
never touch WSL paths, use bigint file identity, and report the next run
that actually sweeps when only chat history is on.
…ing listed links
Before deleting, re-read each transcript: skip it if it was written in the last
hour or its last recorded cwd is outside the gone folder (a chat resumed at a
live workspace's root). Listed symlinks protect their targets, and parents are
re-checked against the listed paths read after the scan.
…records its cwd
Keep a transcript unless its latest recorded cwd, read back past large blobs,
is still in the gone folder; agents that record cwd once can't prove a chat
wasn't resumed elsewhere. Follow symlinks along listed paths, dangling ones too.
…hat right before removal
Parse whole JSONL records backwards and use their top-level cwd, not tool
arguments; run the setting, folder, idle and last-cwd checks right before each
transcript's removal; resolve relative listed links from their real folder.
…ed rows per folder
Check a chat's companion transcripts with the same idle and last-cwd rules,
read Orca's listed rows right before each gone folder's deletion, keep '..'
in listed link targets for the OS to resolve, and say Claude Code in the copy.
…tat rows only on change
Fold case with upper then lower (final sigma), take the repo name with this
host's basename, re-read listed rows per folder only when the catalog changed,
and sweep chats even when rule evaluation fails.
…companion walk
Record each companion's version and require the same set, unchanged, before
approving deletion; skip the symlink-based sweep test on Windows.
…gh, checked per chat
Each listed path claims the (existing folder, name) pairs along it, so a gone
folder holding one stays protected whether that path exists right now or not;
claims are re-read before every removal, and an unfollowable symlink chain
stops the sweep.
…s the sweep fail-closed or ignored
A stat error other than absence while reading listed paths marks the snapshot
incomplete; ENOTDIR counts as absence instead of stopping every sweep.
… and allow exactly eight links
Run the slow transcript checks first so the folder and listed-row checks are
the freshest before the rm, and resolve the eighth link instead of treating
it as an unfollowable chain.
Files skipped from review as they are similar to previous changes: 2
src/renderer/src/i18n/en-runtime-required.json
src/renderer/src/i18n/locales/en.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Quick win
Refresh filesystem-derived claims before deletion.
The catalog fingerprint does not change when a listed symlink changes its target. For example, /links/saved can point to another missing folder when readCurrent runs, then point to the candidate workspace during the transcript idle check. The final isUnclaimed call reuses the old claims and permits permanent deletion, although the listed path now protects that workspace.
Re-read filesystem-derived claims before each removal, or validate their filesystem dependencies before reusing them.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Guard update results against a host change in the Codex history-sharing switch.
update writes its result to the shared remote state without checking that the owner is still the same environment. The read effect guards its completion, but the update path does not. If the owner changes from host A to host B while A's update is in flight, and B's read finishes first, A's result overwrites B's state. The hook then reports loading for B. The read effect does not run again for B, so the state stays at loading until the environment or setting key changes.
Apply the same ownership check that the read effect uses. Before calling setRemote in update, confirm that the captured environmentId is still the active owner. A ref that tracks the current owner can provide this check.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Recheck the catalog fingerprint after readCurrent awaits.
readCurrent reads the catalog fingerprint before it awaits listedLinksUnchanged or the rebuild reads. A catalog change during either await is not reflected in the returned claims. The final isUnclaimed call in the per-removal predicate can then return stale claims. If a new catalog row claims the missing folder, the predicate can approve permanent deletion of that folder's chats.
Validate the fingerprint after each await, and rebuild when it has changed:
Suggested fix
--- "a/src/main/workspaces/cleanup/chat-history/deleted-workspace-chat-history.ts"+++ "b/src/main/workspaces/cleanup/chat-history/deleted-workspace-chat-history.ts"@@ -125,17 +125,25 @@
// Re-read Orca's rows after each folder was seen gone, but stat them again only when they changed.
type CurrentRows = { fingerprint: string; listed: ListedFolders; parentIds: Set<string> }
let current: CurrentRows | null = null
const readCurrent = async (): Promise<CurrentRows> => {
- const fingerprint = listedCatalogFingerprint(deps.store)- // Claims also follow symlinks, which can be retargeted without any catalog change.- if (current?.fingerprint === fingerprint && (await listedLinksUnchanged(current.listed))) {- return current- }- const listedNow = await readListedFolders(deps.store)- const parentsNow = await readWorkspaceParents(deps.store, listedNow)- current = { fingerprint, listed: listedNow, parentIds: parentsNow.ids }- return current+ for (;;) {+ const fingerprint = listedCatalogFingerprint(deps.store)+ // Claims also follow symlinks, which can be retargeted without any catalog change.+ if (+ current?.fingerprint === fingerprint &&+ (await listedLinksUnchanged(current.listed)) &&+ listedCatalogFingerprint(deps.store) === fingerprint+ ) {+ return current+ }+ const listedNow = await readListedFolders(deps.store)+ const parentsNow = await readWorkspaceParents(deps.store, listedNow)+ if (listedCatalogFingerprint(deps.store) === fingerprint) {+ current = { fingerprint, listed: listedNow, parentIds: parentsNow.ids }+ return current+ }+ }
}
// A workspace archived or renamed during the scan or earlier deletions keeps its row, and that
// row protects its chats; claims don't depend on whether the row's folder exists right now.
const isUnclaimed = async (key: string, folder: GoneFolder): Promise<boolean> => {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When Orca deletes a workspace, the Claude Code chats from that workspace stay on disk forever. On one machine that was 1,229 transcripts and 5 GB from workspaces that no longer exist. This adds a setting to Workspace Cleanup, off by default and marked Recommended, that deletes those chats once their workspace is gone.
What Changed
settings.updateis strict. The per-host switch hook is now generic (useHostBooleanSetting), shared with the Codex history-sharing switch.orca workspace cleanup run, and at most every 6 h from the hourly tick. It catches every way a workspace gets deleted (rules, the dialog, by hand,git worktree remove), because it looks at what is gone rather than hooking each delete path.{deleted, failed, freedBytes}. The Activity list, the status line and the CLI show it, and an open session history list refreshes.How a chat qualifies:
<workspaces root>/<repo>folders with no.git. Flat roots never count, because they hold Claude Code's own.claude/worktreesand the user's projects.Only Claude Code is swept for now. Claude records the cwd on every message, so a resumed chat can be told apart. Agents that record it once (Pi, OMP, Copilot, Cursor) can't show that and are left alone. Orca's own native chats and Codex follow in their own PRs.
Why
Part of #16776. Codex history is the remaining part, and that PR will close the issue and credit @maxmilian for #16990.
#16990 used a 90-day age cutoff. Review found it could delete live and same-path chats, and that deleting one hardlinked copy frees nothing. Tying deletion to "this chat's workspace is gone" deletes nothing anyone can still open in Orca, and needs no age cutoff. One switch next to the existing rules keeps it inside Workspace Cleanup instead of adding a sixth rule.
Linked Issue
Part of #16776
Visual Proof
Turning it on asks first:
Testing
deleted-workspace-chat-history.test.tsruns the sweep against real temp folders. It deletes the gone workspace's chats, including one recorded through the physical (/private/var) spelling. It keeps:..sibling base, an unrelated clone with.git, and an old flat workspace named like a repoEach guard was checked by removing it and seeing the test fail.
pnpm check:changed: all 38 checks pass.Measured on macOS against real data: 1,229 Claude transcripts (5.06 GB) whose nested Orca workspace folder is gone, 20 kept for live workspaces, 695 outside Orca workspaces kept.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
The risky part is permanent deletion of chat history. Every check fails toward keeping the chat: unknown, unreadable, recently written, resumed elsewhere, or still listed all mean keep. The setting is off by default, and turning it on asks first.
chatHistoryrun field.Level: Medium
AI Disclosure
Review
Agent skill upstream boundary
Notes
\is kept.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)