Claude Code has no bulk delete for archived sessions. The web UI at claude.ai/code lets you filter Active, Archived, or All, but each row only has a single trash control. To clear hundreds of sessions, open the browser console on that page and run the script below. It calls the same sessions API the UI uses, in batches of 10, and reloads when it finishes.
I hit this with more than 300 archived sessions in the sidebar. I was not going to click trash 300 times.
How to bulk delete Claude Code sessions
- Sign in and open claude.ai/code.
- Open the browser console:
Cmd+Option+Jon Mac,Ctrl+Shift+Jon Windows or Linux. - Paste the script, press Enter, and wait for the progress logs.
- When it prints
Done!, the page reloads.
(async () => {
const headers = {
"anthropic-beta": "ccr-byoc-2025-07-29",
"anthropic-client-feature": "ccr",
"anthropic-client-platform": "web_claude_ai",
"anthropic-version": "2023-06-01",
"content-type": "application/json"
};
// Fetch all session IDs (handles pagination)
let allIds = [];
let url = '/v1/sessions';
while (url) {
const resp = await (await fetch(url, { headers })).json();
const sessions = resp.data || resp;
sessions.forEach(s => allIds.push(s.id));
url = resp.has_more && resp.last_id
? '/v1/sessions?after_id=' + resp.last_id
: null;
}
console.log(`Found ${allIds.length} sessions. Deleting...`);
// Delete in batches of 10
let deleted = 0, failed = 0;
for (let i = 0; i < allIds.length; i += 10) {
const batch = allIds.slice(i, i + 10);
await Promise.all(batch.map(id =>
fetch('/v1/sessions/' + id, { method: 'DELETE', headers, body: '{}' })
.then(r => r.ok ? deleted++ : failed++)
.catch(() => failed++)
));
console.log(`Progress: ${deleted + failed}/${allIds.length} (deleted=${deleted}, failed=${failed})`);
}
console.log(`Done! Deleted ${deleted}, failed ${failed}`);
location.reload();
})(); That is the whole fix for “how do I delete all Claude Code sessions” and the usual variants: delete session, delete old sessions, clear archived sessions.
What the script does
It page-walks GET /v1/sessions (about 200 sessions per page in my runs), collects every id, then fires DELETE /v1/sessions/{id} ten at a time so you do not hammer the endpoint. Progress prints to the console. When finished, it reloads the tab so the sidebar matches the API.
No API key, no personal access token, no third-party extension. The request runs in your logged-in tab, so the browser sends the auth the product already trusts.
Optional: delete only archived sessions
The default script deletes every session ID the list endpoint returns. If you only want archived rows gone, log one object first and filter on the status field your account actually uses:
// After fetching `sessions`, keep only archived before pushing ids:
// sessions.forEach(s => {
// if (s.status === 'archived' || s.archived === true) allIds.push(s.id);
// }); Field names can change. Inspect console.log(sessions[0]) once before you delete at scale.
Why not click the UI?
I tried automating the trash icon first. It is a bad path:
- Synthetic
.click()often lies. React handlers do not always fire. You get a “Session deleted” toast while the DELETE never lands. - The sidebar is paginated. You only see a couple dozen rows. The API can return hundreds. Scroll, wait, repeat.
- It is slow. Roughly a second plus animation per delete. Three hundred sessions is several minutes of watching UI. The API path finished under 30 seconds for me.
If you came here from “claude code archive session” or “claude code delete old sessions,” the API path is the reliable one.
Limitations (read these)
- Scope is the web sessions API, not local Claude Code / CLI history on disk.
- Default run deletes every listed session, not “archived only,” unless you add a filter.
- Beta request headers can change. If deletes start failing, compare Network tab traffic from a manual delete and update the header set.
- This is destructive. There is no undo in the script. If a session still has work you need, leave the page and do not run it.
- Only run it on claude.ai while you are logged into your own account. Never paste it on another origin.
Related
If you are still setting up Claude Code itself, I wrote up my Claude Code setup separately. That post is about plugins and workflow. This one is only about clearing the session list.
