Skip to content

Review: cleanupPeriodDays retention sweep — PAI dependencies and archival strategy #152

@virtualian

Description

@virtualian

Context

Claude Code's cleanupPeriodDays setting drives a background retention sweep. Per the changelog, the sweep now covers:

  • ~/.claude/projects/ — conversation history / transcripts (long-standing behaviour)
  • tool result files
  • ~/.claude/tasks/ (added recently)
  • ~/.claude/shell-snapshots/ (added recently)
  • ~/.claude/backups/ (added recently)

Defaults and quirks worth noting:

  • Default horizon is 30 days.
  • cleanupPeriodDays: 0 is now rejected with a validation error (previously silently disabled transcript persistence).
  • --setting-sources without user previously caused the sweep to ignore the configured value; fixed.

PAI does not currently set cleanupPeriodDays anywhere in ~/.pai/ or ~/.claude/settings*.json (checked 2026-04-22), so it inherits the default 30-day sweep.

Why review now

PAI's MEMORY/LEARNING/ pipeline (FAILURES/, REFLECTIONS/, SIGNALS/, mine-output.md, review.md) depends on session artefacts that originate under ~/.claude/projects/. If the retention sweep deletes a transcript before the learning pipeline consumes or copies it, signals and failure analyses are lost silently. The new dirs added to the sweep (tasks/, shell-snapshots/, backups/) may also contain data PAI hooks touch.

What to review

  1. Dependency audit: enumerate every PAI hook, skill, or script that reads from ~/.claude/projects/, ~/.claude/tasks/, ~/.claude/shell-snapshots/, or ~/.claude/backups/. For each, determine whether it consumes within a predictable window or assumes indefinite retention.
  2. Consumption horizon: what is the longest delay between a Claude Code session ending and a PAI pipeline consuming its artefacts? (E.g. monthly review.md synthesis may reach back further than the default 30 days.)
  3. Archive vs sweep: should PAI's learning pipeline copy any required session data into ~/.pai/MEMORY/ at end-of-session (hook) so it is independent of Claude Code's sweep, rather than depending on live ~/.claude/projects/ files?
  4. Recommended value: pick one of —
    • Leave default (30d), rely on end-of-session archival hooks for anything PAI needs beyond that horizon.
    • Ship PAI with an explicit higher value (e.g. 90d) in a PAI-managed settings.json fragment.
    • Make it user-configurable with a documented recommendation and guard-rails.
  5. Interaction with --setting-sources: PAI loads rules at startup (loadAtStartup). Verify the current Claude Code CLI respects cleanupPeriodDays in whichever settings source PAI writes to; do not rely on the prior bug being the only issue.

Decision criteria

  • If any PAI pipeline assumes retention beyond 30 days without making its own copy, the current default is a silent data-loss risk — raise the value and add an archival hook.
  • If all PAI consumption happens within the default window, leaving the value alone is correct — do not over-configure.
  • Archival hook is preferred over raising retention, because raised retention is a user-disk-space cost PAI shouldn't impose without cause.

Deliverable

  • Audit output: a short table of PAI → ~/.claude/ directory dependencies with consumption windows.
  • A decision: change default, add archival hook, or document current behaviour as sufficient.
  • If config change: a proposed settings.json fragment with rationale.
  • If archival hook: a hook script plus where it plugs into PAI (likely an end-of-session hook).

Out of scope

  • Replacing Claude Code's sweep with a PAI-owned sweep.
  • Broader review of ~/.claude/ directory layout (track separately if wanted).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions