Opuscule
  1. Home
  2. Journal
  3. Keep your Claude Code sessions

Claude Code

Claude Code deletes your sessions after 30 days. Here's how to keep them.

By default, a session older than a month disappears without warning. One setting keeps it for ten years, and a small hook can archive every session as it ends.

Published September 29, 2026 · 6 min read

You go looking for a session from last spring with /resume and it's gone. That's not a bug: Claude Code cleans up after itself. When a session starts, a background sweep deletes everything older than cleanupPeriodDays, 30 days by default, without showing a message. The session no longer appears in the /resume picker, and what's deleted can't be recovered.

What gets deleted

The sweep isn't limited to conversations. According to the Claude Code documentation, it removes files in ~/.claude/ older than the retention period, including:

Path under ~/.claude/Contents
projects/<project>/<session>.jsonlThe full conversation: every message, tool call and tool result
projects/<project>/<session>/subagents/Subagent conversations, removed along with the parent session
projects/<project>/<session>/tool-results/Tool outputs too large to inline, and images returned by MCP tools
file-history/<session>/Snapshots of files before they were edited, used to rewind
plans/Plans written in plan mode
paste-cache/The contents of large pastes
usage-data//insights reports

In other words, after a month nothing is left of what you asked, what the agent did, or the plan you agreed on together.

The one line that keeps everything for ten years

The setting is cleanupPeriodDays. It's a whole number of days, 1 at minimum. Add it to your user settings, ~/.claude/settings.json (create the file if it doesn't exist):

{
  "cleanupPeriodDays": 3650
}

If the file already has settings, just add the line inside the braces, with a comma after the previous line. 3650 days is ten years.

Don't use 0. You might expect 0 to mean "never." In fact, a value of 0 fails validation. The documentation recommends a large value such as 3650 for long retention.

Two details:

Going further: archive every session as it ends

Keeping ten years in ~/.claude is great, as long as that folder survives: a new Mac, a reinstall, an overly broad cleanup. For a separate copy, Claude Code has hooks, commands that run at specific moments. The SessionEnd hook fires when a session ends (exit, /clear, switching sessions with /resume) and receives the conversation's path as transcript_path.

This small script copies the ending conversation, with its subagents, into ~/Archives/claude-code. Save it as ~/.claude/hooks/archive-session.sh:

#!/bin/sh
# Copy the ending session (and its subagents) into ~/Archives/claude-code.
transcript=$(jq -r '.transcript_path // empty')
[ -f "$transcript" ] || exit 0
dest="$HOME/Archives/claude-code/$(basename "$(dirname "$transcript")")"
mkdir -p "$dest"
cp -p "$transcript" "$dest/"
folder="${transcript%.jsonl}"
[ -d "$folder" ] && cp -Rp "$folder" "$dest/"
exit 0

Then register it in ~/.claude/settings.json, next to cleanupPeriodDays:

{
  "cleanupPeriodDays": 3650,
  "hooks": {
    "SessionEnd": [
      {
        "hooks": [
          { "type": "command", "command": "sh ~/.claude/hooks/archive-session.sh", "timeout": 10 }
        ]
      }
    ]
  }
}

The timeout matters: by default, SessionEnd hooks only get 1.5 seconds. A per-hook value raises that budget, up to 60 seconds. The script uses jq, which ships with recent versions of macOS (otherwise, brew install jq).

The documentation warns that the conversation file is written asynchronously: when a hook fires, the very latest messages may be missing from the copy. The original stays complete in ~/.claude for as long as cleanupPeriodDays keeps it, and if you resume the session later, the hook copies it again when it ends.

What about images?

Since version 2.1.275, images you paste or attach to a session are no longer stored in ~/.claude: Claude Code saves them in an images/ folder per session under the temp directory (the one CLAUDE_CODE_TMPDIR controls). As for images the agent produces in your project, screenshots or renders, they live in your project and can be edited or overwritten the next day. If you want the image as it was that day, you have to copy it that day.

What Opuscule does

This is exactly the problem Opuscule started from. It archives your sessions as you go on your Mac, with their images as they were that day, so your volume can find them when it's time to print. Until the app is out, the "cleanupPeriodDays": 3650 line is enough to stop losing anything.

Sources

Checked against Claude Code 2.1.285 on September 29, 2026.