Omniscio

OmniscioGuidesDelete a Claude Code session

Deleting a Claude Code session, and deleting what it left behind

Three different actions get called "deleting a session": clearing the context so the next prompt starts fresh, removing a session from the list, and deleting the files Claude Code wrote to disk. Of the three, only the purge deletes the transcripts now, and it is the one people skip.

This page covers all three and which one you want. The transcript guide covers reading a conversation after the fact, the command history guide covers the prompt history you scroll back through in a session, and the .claude directory guide maps every file Claude Code keeps.

Sources read November 25, 2026. By the Omniscio team. Updated .

Three deletes, and what each one removes

The first is /clear. It starts a fresh conversation with an empty context, and Claude Code saves the one you left so you can resume it. Nothing is deleted; the old conversation simply stops being the current one.

The second removes a session from the list: Ctrl+X twice within two seconds in agent view, or claude rm <id> from a shell. The session disappears from the list, and Anthropic's wording is explicit that its transcript stays on your machine and remains available through claude --resume.

Both routes act on background sessions. Claude Code treats every session listed in agent view as a background session, while a session started by running claude directly is tied to that terminal and ends when it closes, unless you send it to the background first.

The third is claude purge, which deletes the state Claude Code holds for one project. That is the one that removes transcripts on the spot, and it is the only one of the three that does.

And underneath all of them, nobody has to do anything: the retention sweep deletes old files on its own after cleanupPeriodDays.

Clearing the context, or just the screen

/clear starts fresh with an empty context. Claude Code saves the previous session, so you can resume it with /resume or, in the same process, from the rewind menu's previous-session entry.

With no argument the new session keeps a name you set with --name or /rename, but not an AI-generated title. To name the session you are leaving instead, pass the name: /clear release-prep, and the new one starts unnamed.

Clearing is the cheapest thing you can do to a long session, and it is not a delete. If the goal is to stop paying for a context you no longer need, it is also not a compaction: Anthropic documents /compact as replacing history with a summary, and /context as showing what is currently taking the space.

Taking a session out of the list

Delete a session with Ctrl+X twice within two seconds in agent view, or with claude rm. The first press stops the session and asks you to confirm; the second, inside two seconds, deletes it, and Esc dismisses the confirmation without deleting anything. The session then disappears from the list unless Claude Code refuses to delete it.

claude rm <id>

Every background session has a short id you can use from a shell. It is printed when you start a session with claude --bg, and it is the session's directory name under ~/.claude/jobs/; claude agents --json prints the sessions, ids included, if you would rather read them from a script.

What happens to a worktree Claude created for the session is the part worth reading before you confirm, because the two routes differ:

  • Agent view removes the worktree, including uncommitted changes, so commit what you want to keep first.
  • claude rm keeps the worktree, and the session row, when the worktree has uncommitted changes.

One documented reason for a refusal is unpushed commits in the session's worktree. Anthropic's advice is to push them before you delete the session. If you are refused anyway, follow the message: claude rm offers a command that retries with the worktree discarded.

Among the cases Anthropic lists where a worktree stays on disk either way: one you created yourself and started the session from, and a worktree directory inside your repository that has lost its .git file, whose branch stays in the repository so the commits survive.

The transcript is the part that survives both routes. Removing a row is tidying the list, not deleting the work.

Purging a project: the delete that removes transcripts

Run claude purge to delete the state Claude Code holds for one project. It deletes transcripts and auto memory under projects/, the per-session tasks/, debug/ and file-history/ entries, the matching prompt lines in history.jsonl, and the project's entry in ~/.claude.json.

claude purge ~/work/my-repo --dry-run

The dry run prints a plan that lists each matching item and why it is included: the project's transcript directory, its entry in ~/.claude.json, and how many prompt lines in history.jsonl it would remove. Anthropic's example ends with a count of the items that would be deleted.

Without --dry-run the command prints the same plan and asks for confirmation before removing anything. Before v2.1.288 it was named claude project purge, which is the name older notes and scripts still use.

What a purge does not reach

Among the things a purge leaves behind: images you pasted or attached in the project's sessions, and each session's scratchpad, both stored under Claude Code's temp directory rather than ~/.claude. The retention sweep still deletes those images once they are older than cleanupPeriodDays, and a purged session's scratchpad stays until you delete it or the operating system clears the temp directory.

Attached images have moved once already: releases up to v2.1.274 kept theirs inside ~/.claude, in image-cache/, and later versions save them per session under the temp directory. Anthropic's note for that older location is that the sweep removes other sessions' leftovers there whatever their age.

Two more things it leaves alone for a different reason: shell-snapshots/ and backups/ are not project-scoped, and the plan output warns about both. If anyone ran /heapdump on the machine, its .heapsnapshot files survive too, and Anthropic warns they contain the full conversation and any credentials the process held.

If the path you name is not a project Claude Code holds state for, it prints an error and exits with status 1, so the dry run is a safe first check on a machine you did not set up.

How long it lasts if you do nothing

Claude Code deletes files older than cleanupPeriodDays on its own, as long as it can safely determine the retention period. The default is 30 days and the minimum is 1; setting 0 fails with a validation error. The same age cutoff applies to automatic removal of orphaned worktrees.

Not everything follows that cutoff. Auto memory files in a project's memory directory are not deleted by it at all; the directory is removed only if it has been empty for the whole period. A Claude Desktop or Cowork transcript is kept at any age until you set desktopSessionCleanupPeriodDays, which needs v2.1.248 or later; earlier versions delete them after cleanupPeriodDays, as does a machine where managed settings set that key or the HIPAA configuration applies. Files in sessions/ are not part of the age-based sweep at all.

If Claude Code cannot safely determine the retention period, it pauses the sweep, and a retention_sweep event reports why. When the cause is a settings file it cannot read or parse, or a settings error involving cleanupPeriodDays or desktopSessionCleanupPeriodDays, /status shows a warning until you fix the cause.

Turning transcript writing off

By default, transcripts are written as JSONL to ~/.claude/projects/<project>/<session-id>.jsonl, where the project folder is your working directory path with non-alphanumeric characters replaced by dashes. The 30-day retention is the cleanupPeriodDays key in settings.json, which is where you change it.

Two switches stop them being written at all: CLAUDE_CODE_SKIP_PROMPT_HISTORY, which suppresses transcript writes in all modes, and --no-session-persistence, which suppresses them for one non-interactive claude -p run.

Anthropic's table of transcript settings also names CLAUDE_CONFIG_DIR for moving storage off ~/.claude. The .claude directory guide covers what else lives there, and the transcript guide covers reading one before you delete it.

Sources

Every line on this page rests on one of these. The date beside each one is the day we read it.

  • Manage sessions, for /clear, where transcripts are stored, the switches that turn writing off, and the delete-session-data summary. Read November 25, 2026.
  • Agent view, for Ctrl+X, claude rm, what deleting a session removes from a worktree, and the refusal that protects unpushed commits. Read November 25, 2026.
  • Explore the .claude directory, for what claude purge deletes, the dry run, the pre-v2.1.288 command name, and the retention sweep with its 30-day default and 1-day minimum. Read November 25, 2026.

The purge command and its list have both changed before, and the retention sweep gained its own rules per file type. Re-read the Clear local data and Cleaned up automatically sections before you trust a copy of this page from a few months back.

Common questions

How do I delete a Claude Code session?

Press Ctrl+X twice within two seconds on the session's row in agent view, or run claude rm with the session id. Either removes it from the list, and Anthropic says the transcript stays on your machine and is still reachable through claude --resume.

Does deleting a session delete the conversation?

No. Anthropic documents that the transcript stays on disk after claude rm or agent view's delete, and remains available through claude --resume. To remove a project's transcripts themselves, run claude purge on that project.

What does claude purge delete?

Transcripts and auto memory under projects/, the per-session tasks, debug and file-history entries, the project's prompt lines in history.jsonl, and the project's entry in ~/.claude.json. It prints the deletion plan and asks for confirmation, and --dry-run shows the plan without deleting.

How long does Claude Code keep transcripts?

Thirty days by default. The retention sweep deletes files older than cleanupPeriodDays, whose default is 30 and minimum is 1; setting it to 0 fails with a validation error.

Can I stop Claude Code writing a transcript at all?

Yes. CLAUDE_CODE_SKIP_PROMPT_HISTORY suppresses transcript writes in all modes, and --no-session-persistence suppresses them for one non-interactive claude -p run.

Close a session without losing the work

Omniscio runs several agent sessions in one window, each with its own context and its own diff view, so ending one is a button rather than a cleanup. The Delete a chat page sets out, for Omniscio’s own Delete, what stays and what goes. Any model, any harness: Claude Code, Codex, OpenCode, Devin, Pi and Hermes are all supported.