Skip to main content

What Claude Code Leaves on Your Mac After a Session (and How to Clean It Up)

· 15 min read
Pere Pages
Software Engineer
A dark desk with an open laptop in the middle; on the right, paper scraps float up and dissolve into dust, and on the left a filing cabinet keeps its drawers full of glowing paper scrolls, with a small broom leaning against it

Claude Code gives every session a scratch folder under /private/tmp, and it is easy to think that this folder is where all of its leftovers live. It is the smallest part: more temporary files sit next to it, and the long-term record of every session stays in ~/.claude for a month by default.

note

This describes Claude Code 2.1.295 on macOS 27 in October 2026. File locations and cleanup rules change between versions, so check the current documentation before you delete anything. Deleting a session's files also means you can't resume that session later.

The gist​

macOS empties the scratch folder you see in Claude Code's messages within days. The part that needs a decision is ~/.claude, where Claude Code keeps a plain-text copy of every session for 30 days.

  • Let macOS empty the temporary folders. A restart, or 3 days without use, removes them. Delete them by hand only if you rarely restart.
  • Keep sessions only as long as you go back to them. Set cleanupPeriodDays to that number of days, for example 14 instead of the default 30.
  • Treat a secret that passed through a session as exposed. Change the secret first, then delete that session's saved text.
  • Add an end-of-session hook only if the scratch folder must go at once. The cost: a resumed session no longer finds its scratch files.

Three places, three lifetimes​

Claude Code writes files to three places on your Mac, and each place is cleaned on a different schedule.
  1. The session's own scratch folder. Claude writes its helper scripts, drafts and test outputs here while it works. One folder per session.
  2. The shared temporary folder around it. Commands that Claude runs write their temporary files here: logs, caches, browser profiles. All sessions share it.
  3. Claude Code's home folder, ~/.claude. This is the long-term record: the full text of every conversation, copies of the files Claude changed, and the plans it wrote.

The first two are temporary folders. macOS removes their contents after a few days, and when the computer restarts. The third is not temporary at all. Claude Code removes old files from it on its own schedule, and nothing else ever touches it.

The rest of this post goes through the three places in order, from the most temporary to the most permanent.

Why the path says "private"​

On this Mac, one session's scratch folder was /private/tmp/claude-501/-Users-pearpages-Projects-pearpages/68e8ffeb-…/scratchpad. The word "private" in that path has nothing to do with Claude. On macOS, /tmp is a link to /private/tmp: the two names point to the same folder, and /private/tmp is its real location. You can check this yourself:

ls -ld /tmp
# lrwxr-xr-x 1 root wheel 11 Sep 3 12:34 /tmp -> private/tmp

/tmp is shared by every user and every program on the computer. The rest of the path is Claude Code's own structure, which its documentation describes:

  • claude-501: one folder per user account. 501 is your user identifier (UID), the number macOS uses for your account. Run id -u to see yours.
  • -Users-pearpages-Projects-pearpages: one folder per project. It is the project's path with every character that is not a letter or a number replaced by -.
  • 68e8ffeb-…: one folder per session, named after the session's identifier (ID).
  • scratchpad: the folder Claude is told to use for files that don't belong in your project.

Claude Code gives Claude this folder so that a quick test script or a large intermediate result doesn't end up in your repository. That works well. But the folder doesn't disappear when the session ends, and that is the next question.

How long the scratch folder lives​

The scratch folder stays after you quit. Two cleanup processes can remove it, and the first one to run removes it.

The first is Claude Code's own cleanup. The documentation says that "scratchpad files last as long as the session's transcript". The transcript is the saved text of the session, and Claude Code deletes transcripts older than the number of days in its cleanupPeriodDays setting: 30 by default. This cleanup runs in the background after a new session starts.

The second is macOS. Since macOS 14, a system program called tmp_cleaner runs every day at midnight. Its manual page says it removes old content from /tmp. On this Mac, the program removes files that nobody has opened, modified or changed for more than 3 days, and then removes the folders that are left empty. (Older versions of macOS did the same job with a script called periodic, which Apple removed in macOS 15.) macOS also empties /private/tmp when the computer restarts. Apple doesn't document this, but Chromium's source code relies on it, and on this Mac nothing in /private/tmp was older than the last restart.

So in practice a scratch folder lives until the next restart or for about 3 days without use, not 30 days. That is still long enough to matter. On the day this post was written, the scratch folder of a session that had already ended held 207 megabytes (MB): three copies of a 69 MB memory snapshot from a debugging session. Nothing was wrong. The files were simply still there, on a Mac that hadn't restarted for two days.

The files next to the scratch folder​

The scratch folder is where Claude chooses to write. But Claude also runs commands, such as builds, linters (tools that check code for mistakes and style) and test browsers, and those commands decide for themselves where to write their temporary files. Most of them ask the system for the temporary folder, which they find in the $TMPDIR environment variable (a setting every program can read).

When Claude Code runs commands in its sandbox, it sets $TMPDIR to the shared per-user folder, /tmp/claude-501, not to the session's scratch folder. (The sandbox is the protection that limits which files and network addresses a command can reach.) So every temporary file from every command lands one level above the sessions, outside any one session's folder. On this Mac, the shared folder held these, next to the session folders:

WhatWhere it came from
node-compile-cache (26 MB), jiti, node-jitiCaches that Node.js and its tools create to start faster
Three puppeteer_dev_chrome_profile-… foldersBrowser profiles that Puppeteer (a tool that controls Chrome) created for test runs
lint.log, build.log, sb-main.log, sb-branch.logCommand output that Claude saved to $TMPDIR to read later
mmparse.mjs, a, b, xSmall scripts and comparison files that Claude wrote to $TMPDIR instead of to the scratch folder

These files belong to no session, so Claude Code's own cleanup never removes them. Only macOS does, after 3 days or at the next restart. They are small and harmless. But they are the reason why "Claude cleans up its scratch folder" and "Claude leaves nothing in /tmp" are two different statements.

What stays in ~/.claude​

The temporary folders hold working files. ~/.claude holds the record of the work itself, and macOS never cleans it. The documentation lists every folder and which ones Claude Code cleans. These are the ones that grow:

  • projects/ holds the transcripts: one file per session, in JSON Lines (JSONL) format, one JSON (JavaScript Object Notation) record per line. A transcript contains everything in the conversation, including the contents of every file Claude read and the output of every command it ran. claude --resume and claude --continue read these files to bring a session back.
  • file-history/ holds a copy of each file before Claude changed it. Rewind uses these copies to undo Claude's edits (checkpointing).
  • plans/ holds the plans Claude writes in plan mode, the mode where Claude writes a plan for you to approve before it changes anything.
  • paste-cache/ and shell-snapshots/ hold large pasted texts and a copy of your shell settings for each session.
  • history.jsonl holds every prompt you typed, for the up-arrow key.
FolderSize on this MacRemoved by Claude Code's cleanup?Safe to delete by hand?
projects/ (transcripts)564 MBYes, after 30 daysYes, but you lose resume
file-history/18 MBYes, after 30 daysYes, but you lose rewind
plans/0.5 MBYes, after 30 daysYes
paste-cache/, shell-snapshots/under 1 MBYes, after 30 daysYes
history.jsonlsmallNoYes, but you lose up-arrow history

The size is rarely the problem. The content is. Transcripts are plain text and not encrypted, so any secret Claude read during a session, for example from a .env file, now also sits in ~/.claude/projects for 30 days. Any program that can read your home folder can read it there. Your .env has a new reader explains how to keep secrets out of the agent's reach in the first place. This post is about what to do with what is already on disk.

The settings that control what stays​

You can't turn the scratch folder off. You can control how long the rest stays, and whether some of it is written at all. Each of these is documented by Claude Code:

  • cleanupPeriodDays in ~/.claude/settings.json sets how many days Claude Code keeps transcripts, file copies, plans and scratch folders. The default is 30 and the minimum is 1. 0 is not allowed: Claude Code rejects the setting.
  • plansDirectory moves plan files into your project, for example "./plans", if you prefer to keep them with the code (settings reference).
  • CLAUDE_CODE_SKIP_PROMPT_HISTORY=1, an environment variable, stops Claude Code from writing transcripts and prompt history at all. Sessions started with it don't appear in --resume (environment variables).
  • --no-session-persistence does the same for one run of claude -p, where you give the prompt on the command line and Claude answers without a conversation (command-line reference).
  • CLAUDE_CODE_TMPDIR moves the temporary folder somewhere other than /tmp. Claude Code adds /claude-<UID>/ to the path you give.

The shorter you set cleanupPeriodDays, the less there is to leak, and the fewer old sessions you can resume. Fourteen days is a reasonable middle: long enough to come back to last week's work.

{
"cleanupPeriodDays": 14
}

A cleanup routine​

These steps go from looking to deleting. Run them in a normal terminal, outside Claude Code: one of them deletes the folder a running session works in.

Look before you delete​

This shows how much space each place uses:

T=/private/tmp/claude-$(id -u)
du -sh "$T" ~/.claude/projects ~/.claude/file-history ~/.claude/plans

This lists the files in the shared folder that belong to no session. Session folders are named after a project path, so their names start with -:

find "$T" -mindepth 1 -maxdepth 1 ! -name '-*'

And this counts the transcripts that contain something that looks like a key: an Anthropic, AWS (Amazon Web Services) or GitHub token, or a private key. A count of 0 is good news. If the count is higher, run the command again without | wc -l to see which files they are:

grep -lE 'sk-ant-[A-Za-z0-9_-]{20}|AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{36}|-----BEGIN [A-Z ]*PRIVATE KEY' \
~/.claude/projects/*/*.jsonl | wc -l

On this Mac it found none in 179 transcripts. The pattern only catches the common formats, so a 0 doesn't prove there are no secrets. It only means none of these well-known ones.

Clean the temporary folder​

Quit every Claude Code session first, because a running session is still using its scratch folder. Then remove the whole per-user folder. Everything in it is temporary, and Claude Code creates it again on the next start:

rm -rf "/private/tmp/claude-$(id -u)"

A restart does the same thing. If you restart your Mac every few days, you can skip this step.

If a transcript holds a secret​

Change the secret first: it has been on disk, and deleting the file doesn't change that. Then delete that session's transcript and its folder of the same name in ~/.claude/projects/<project>/. If Claude also edited the file that held the secret, delete ~/.claude/file-history/<session-id>/ too, because it keeps a copy of the file from before the edit. You can no longer resume that session.

Remove the scratch folder when a session ends​

If you want the scratch folder gone the moment you quit, a SessionEnd hook can do it. A hook is a command that Claude Code runs at a fixed moment, and SessionEnd runs when a session ends. Claude Code sends the hook a description of the session in JSON, including scratchpad_dir, the path of the scratch folder (from version 2.1.257). This script reads that path with jq and deletes the folder. The case line deletes only a path that looks like a scratch folder, so an empty or unexpected value deletes nothing:

#!/bin/bash
# ~/.claude/hooks/clean-scratchpad.sh
# Delete this session's scratch folder when the session ends.
dir=$(jq -r '.scratchpad_dir // empty')
case "$dir" in
*/claude-*/*/scratchpad) rm -rf -- "$dir" ;;
esac

Make it executable with chmod +x ~/.claude/hooks/clean-scratchpad.sh, then register it in ~/.claude/settings.json:

{
"hooks": {
"SessionEnd": [
{
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/clean-scratchpad.sh",
"timeout": 5
}
]
}
]
}
}

Two limits apply. SessionEnd hooks get only 1.5 seconds by default, which is why the example sets timeout to 5 seconds. And a resumed session finds its scratch folder empty, so any file Claude wanted to keep must go in the project instead. The hook doesn't touch the shared files next to the session folders: they don't belong to any one session, so there is no safe way to tell which ones are finished.

What to remember​

The scratch folder is the part of what Claude Code leaves behind that you see, because its path appears in the conversation. It is also the first part to go: macOS empties it within days. The shared temporary folder around it collects the files of every command Claude runs, and only macOS cleans it. The part that deserves your attention is ~/.claude/projects: a plain-text copy of every session, kept for 30 days unless you choose a shorter period.

References​

  1. Claude Code docs, Explore the .claude directory — scratch folder, automatic cleanup, plain-text storage
  2. Claude Code docs, Settings reference — cleanupPeriodDays, plansDirectory
  3. Claude Code docs, Sandboxing: temporary directories
  4. Claude Code docs, Sessions: where transcripts are stored
  5. Claude Code docs, Checkpointing
  6. Claude Code docs, Environment variables
  7. Claude Code docs, CLI (command-line interface) reference
  8. Claude Code docs, Hooks: SessionEnd
  9. Apple, tmp_cleaner(8) manual page (mirror)
  10. heise online, Cleanup scripts: macOS 15 removes periodic
  11. Chromium source, code_sign_clone_manager.mm — comment on how macOS cleans /private/tmp