Skip to content

Default Claude Code transcript retention to 1 year (cleanupPeriodDays) — 30-day default wipes sessions from the persisted ~/.claude volume #173

Description

@gatezh

Summary

Claude Code deletes session transcripts older than cleanupPeriodDays (default 30) every time it starts. The template persists ~/.claude in a named volume, so transcripts survive rebuilds. The 30-day sweep still deletes them, and after a month /resume no longer finds those sessions. The images and templates should default to keeping transcripts for at least a year.

Why it has to be user scope

The cleanup runs at startup and sweeps every project under ~/.claude/projects, not just the current one. Setting cleanupPeriodDays in a project's .claude/settings.json isn't enough: any session started from another directory (a worktree, /tmp, a second repo on the same volume) falls back to 30 days and deletes the old transcripts from every project. The setting has to be in ~/.claude/settings.json (or managed settings).

Verification

claude --version          # 2.1.280
jq .cleanupPeriodDays ~/.claude/settings.json   # null -> 30-day default applies

The CLI's own schema text: "Number of days to retain chat transcripts before automatic cleanup (default: 30). Minimum 1. Use a large value for long retention."

Suggested fix

Set it only when it's missing (//=), so a value a user chose on purpose is kept:

SETTINGS="$HOME/.claude/settings.json"
[ -f "$SETTINGS" ] || echo '{}' > "$SETTINGS"
jq '.cleanupPeriodDays //= 365' "$SETTINGS" > /tmp/claude-settings.json \
    && mv /tmp/claude-settings.json "$SETTINGS"

Where to put it:

Affected files in this repo

  • claude-code/.devcontainer/devcontainer.json (postStartCommand)
  • claude-code/.devcontainer/claude-sandbox/devcontainer.json (postStartCommand)
  • claude-code/.devcontainer/Dockerfile (bake the script)
  • or claude-code/.devcontainer/managed-settings.json, ralphex-fe/managed-settings.json

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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