[Feature Request] Add automatic garbage collection for ~/.claude temporary files

Resolved 💬 2 comments Opened Mar 15, 2026 by yappu0 Closed Mar 15, 2026

Bug Description
Feature request: Add automatic cleanup / garbage collection for temporary files under ~/.claude

Currently, the following directories accumulate files indefinitely with no built-in TTL, expiry, or cleanup mechanism:

  • todos/ (legacy, replaced by tasks/)
  • debug/
  • file-history/
  • session-env/
  • shell-snapshots/
  • paste-cache/
  • tasks/
  • plans/
  • telemetry/

In my case, over 2,000 files had accumulated (todos alone had 1,097) and had to be manually deleted. Since these are all session-ephemeral data with no value after the session ends, they should be cleaned up automatically.

Suggested solutions (any of these would help):

  1. TTL-based auto-expiry (e.g., delete files older than 30 days on startup)
  2. A CLI command like claude cleanup or claude gc for manual bulk cleanup
  3. Session-scoped cleanup: remove session-specific files (session-env, shell-snapshots, paste-cache) when the session ends
  4. A configurable retention policy in settings.json (e.g., "cacheRetentionDays": 30)

Environment Info

  • Platform: darwin
  • Terminal: ghostty
  • Version: 2.1.76
  • Feedback ID: c71b34a8-81d3-41ee-a030-7f10cf0d62d4

Errors

[{"error":"Error: NON-FATAL: Lock acquisition failed for /Users/yappu/.local/share/claude/versions/2.1.76 (expected in multi-process scenarios)\n    at FvT (/$bunfs/root/src/entrypoints/cli.js:2417:2026)\n    at Lxq (/$bunfs/root/src/entrypoints/cli.js:2417:1170)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T07:56:58.266Z"},{"error":"Error: Request was aborted.\n    at yXT (/$bunfs/root/src/entrypoints/cli.js:1187:68107)\n    at next (native:1:11)\n    at nz9 (/$bunfs/root/src/entrypoints/cli.js:6251:6932)\n    at next (native:1:11)\n    at oz9 (/$bunfs/root/src/entrypoints/cli.js:6256:9186)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T07:59:57.325Z"},{"error":"MaxFileReadTokenExceededError: File content (48874 tokens) exceeds maximum allowed tokens (25000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.\n    at C67 (/$bunfs/root/src/entrypoints/cli.js:1515:8032)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T08:02:37.475Z"},{"error":"Error\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:79:10580)\n    at emit (node:events:92:22)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:78:3321)\n    at request (/$bunfs/root/src/entrypoints/cli.js:81:2149)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T08:04:01.693Z"},{"error":"Error: 1P event logging: 20 events failed to export (code=ECONNABORTED, timeout of 10000ms exceeded)\n    at queueFailedEvents (/$bunfs/root/src/entrypoints/cli.js:6853:2694)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T08:04:01.696Z"},{"error":"Error: {\"message\":\"Failed to export 20 events (code=ECONNABORTED, timeout of 10000ms exceeded)\",\"originalLine\":\"6853\",\"originalColumn\":\"1715\",\"line\":\"6853\",\"column\":\"1715\",\"sourceURL\":\"/$bunfs/root/src/entrypoints/cli.js\",\"stack\":\"Error: Failed to export 20 events (code=ECONNABORTED, timeout of 10000ms exceeded)\\n    at doExport (/$bunfs/root/src/entrypoints/cli.js:6853:1715)\\n    at processTicksAndRejections (native:7:39)\",\"name\":\"Error\"}\n    at error (/$bunfs/root/src/entrypoints/cli.js:2363:23759)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:104:81715)\n    at tA4 (/$bunfs/root/src/entrypoints/cli.js:104:82259)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:105:17366)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T08:04:01.696Z"},{"error":"MaxFileReadTokenExceededError: File content (48874 tokens) exceeds maximum allowed tokens (25000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.\n    at C67 (/$bunfs/root/src/entrypoints/cli.js:1515:8032)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T08:08:04.160Z"},{"error":"MaxFileReadTokenExceededError: File content (26519 tokens) exceeds maximum allowed tokens (25000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.\n    at C67 (/$bunfs/root/src/entrypoints/cli.js:1515:8032)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-15T08:29:44.174Z"},{"error":"Error: Request was aborted.\n    at yXT (/$bunfs/root/src/entrypoints/cli.js:1187:68107)\n    at next (native:1:11)\n    at nz9 (/$bunfs/root/src/entrypoints/cli.js:6251:6932)\n    at next (native:1:11)\n    at oz9 (/$bunfs/root/src/entrypoints/cli.js:6256:9186)\n    at processTicksAndRejections (native:7:39)","t…

Note: Content was truncated.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗