---
name: tidy-sessions
license: MIT
description: Archive every finished or superseded session in the Claude desktop app's session list so the sidebar stays short. Use only when the user asks to tidy up, clean up or archive their Claude Code sessions in the desktop app (not code, files or git), or asks which sessions would be archived or which are waiting for them. Not for deleting sessions and not for the running session. To remove landed git worktrees and branches without the desktop app, use the tidy-worktrees skill.
compatibility: Claude desktop app (Code tab) only. Needs its session tools list_sessions, list_events, get_session and archive_session, and git.
metadata:
  author: "Jakob Christensen"
  source: "https://jakobchristensen.com"
---

# Tidy sessions

This skill works on the app's sessions. Checking git worktrees and branches alone, without the app, is the job of the `tidy-worktrees` skill.

Goal: archive every session whose work is **settled**, and keep the rest. The user's request to tidy is their permission to archive every session that counts as settled below. The session itself can be restored (the Archived list, `unarchive_session`), but its worktree is not a backup: uncommitted changes can be lost when it is archived, and the desktop app removes a local worktree about 30 days after the session was archived or last opened (Claude Code desktop docs, "Archive a session"), so the dirty check in step 3 is what protects the work (it also lists ignored files, because it is not known whether the app deletes them when it removes a worktree). With that check in place, decide per session yourself and do not ask first. If the user named a scope (a project, a title, "older than a day"), tidy only that scope. If they only ask what would be archived, stop in step 4 right after its parent and child check, before any `archive_session` call, and give the step 5 report in the conditional ("would archive"), including kept sessions and **Needs your attention**.

A session is **settled** when nothing will happen in it any more and no question to the user is open. That means one of these:
- It ended with a final report in which no sentence asks the user something and no step is named as still to do that is the user's or the session's own committed work. **Soft points do not keep a session**: an optional idea the report says was left unbuilt, a "try it yourself" or "I did not check this in the browser" note, a follow-up suggestion, a taste or look remark without a direct question. Rescue each soft point first (step 4a), then the session is settled.
- Its title starts with `✓` (the user's or the session's own mark for "finished"). This counts as one more sign, never as proof: the other checks in this list still apply.
- It handed off to a successor session that is in the list and has taken over the remaining work (it names this session or its task).
- A result it named as pending has since landed (verified in step 3).
- A session with a later `lastActivityAt` names this session by title or ID, or names its exact task, and states that it finished or replaced that work (obsolete). A similar topic alone does not count.

A session is **live** when any of these holds:
- Its `pinned` field is true, or its `isRunning` field is true, or its last events contain a direct request for user input, approval or a decision that has not been answered yet.
- It is the parent of a live session (the parent is the session named in the child's `startedBy` field).
- It started the current session (its ID is the `parentSessionId` from the `get_session` call in step 1), because the current session is not in the list and its parent must not look childless.
- It waits for a result that has not landed yet.
- It has unmerged work: its branch exists and is not landed (step 3), whatever its last message says.

A session that matches a live condition is live even when it also matches a settled one. When the ending is unclear, for example an aborted session, keep it and name it under **Needs your attention**.

## Steps

0. **Check the environment.** If `list_sessions`, `list_events`, `get_session` and `archive_session` are not available, say that this skill needs the Claude desktop app's Code tab, and stop. Done when the tools exist or you have stopped.
1. **Inventory.** Call `list_sessions` with `limit: 100` (it lists unarchived sessions by default and has no paging). If the result has exactly as many rows as the limit, call it again with limit 500, then with limit 1000, and stop as soon as a call returns fewer rows than its limit. If 1000 rows still fill it, the list may be cut off and a live child could be missing: treat the run as a dry run (see the goal), call `archive_session` for nothing, and say so in the report. Sessions the tools do not list (cloud sessions, sessions from the CLI or an editor) are not checked: say so in the report. Call `get_session` once with `session_id: "self"` and note the current session's ID and its `parentSessionId`. If that call fails or does not give the current session's ID, the current session's parent cannot be protected: treat the run as a dry run, call `archive_session` for nothing, and name this under **Needs your attention**. Keep the complete result as the **full list** for every parent, child and successor check. From it build a separate **tidy list**: apply the user's scope to the tidy list only ("older than" means `lastActivityAt`), and leave out the current session (the list omits it, observed in the app, drop its row anyway if it appears) and every row whose `startedBy` is the current session. Rows left out of the tidy list stay in the full list. If the tidy list is empty, skip steps 2 to 4 and go to step 5. Done when both lists are built. Keep them in working memory and do not print them.
2. **Read each ending.** Call `list_events` with `limit: 8` per session on the tidy list, in parallel batches of 10 sessions. If a call fails, keep that session and name it under **Needs your attention** with the error. Ignore `[result]` lines: they close every turn. For a session with no assistant message, retry that session once with `limit: 40`. If there is still none, or a user message or a pending approval comes after the last assistant message, keep the session and name it in the report. Done when each session has its last assistant message or is named in the report.
3. **Verify every candidate.** A candidate is a session that looks settled. Check each candidate, and each session whose last message claims a state ("integration running", "waiting for X", "merged"). A claim counts as landed only when git shows it, or a successor session reports the checked result (a commit, a command output) and does not just repeat the claim. Without that it has not landed. For a session with a `branch` field, git decides: a successor's report never overrides a failed landed check below. A claimed merge that has not landed makes the session **live**. Check the successor session first, looking in the full list (it may be outside the scope). If it is not on the tidy list, call `list_events` on it with the same limits as in step 2 before judging whether it finished or replaced the work. Then, when the session's folder still exists and is a git repo, check git. Every git command below, including the shortened ones, runs as `git -C "<folder>" ...`. If any git command exits with a status other than the ones this step names (0 or 1 for `git merge-base --is-ancestor`, 0 for the others), keep the session and name it under **Needs your attention** with the error:
   - Branch: the `branch` field of `list_sessions`, which only sessions in their own worktree have. A row without it works in the shared main folder: skip the branch, landed and dirty checks, judge it from the events and the successor only, and append "git not checked" to the archive reason. If `git -C "<folder>" rev-parse --verify --quiet refs/heads/<branch>` finds nothing, keep the session, write "branch not found, not verified" and name it under **Needs your attention**.
   - Default branch: `git symbolic-ref --quiet --short refs/remotes/origin/HEAD`, falling back to the first of `origin/main`, `origin/master`, `main`, `master` that `git rev-parse --verify --quiet` accepts. If none exists, keep the session and name it under **Needs your attention** as "default branch not found". Never run `git fetch`. Say in the report when you used a local branch or a remote ref that may be stale.
   - Landed: if `<branch>` and `<default-branch>` are the same local branch (for example both are `main`), the test proves nothing: keep the session and name it under **Needs your attention**. Otherwise run `git merge-base --is-ancestor refs/heads/<branch> <default-branch>`: exit 0 means landed, exit 1 means not an ancestor, any other exit is an error. After exit 1, if `git rev-list --merges <default-branch>..refs/heads/<branch>` prints anything, keep the session and name it under **Needs your attention** as "merge history not verifiable" (`git cherry` ignores changes made inside a merge commit). Otherwise run `git cherry <default-branch> refs/heads/<branch>`: no line starting with `+` and no error means landed. Any `+` line means not proven (a squash merge of several commits looks the same), so keep the session and name it under **Needs your attention** as "unmerged or squash merge not verifiable".
   - Dirty folder (only for a row with a `branch` field): if `git status --porcelain --untracked-files=all` prints anything, keep the session and name it under **Needs your attention**, because archiving can clean up its worktree. Also run `git status --ignored --porcelain`: if it lists ignored files other than dependency or build folders (`node_modules`, `dist`, `build`, `.next`, `.turbo`, `.cache`, `.venv`, `venv`, `target`, `__pycache__`. Anything else, such as `.env` or local data, is kept and named), keep the session and name the files under **Needs your attention**.
   - If the folder is gone or is not a git repo: for a row with a `branch` field, keep the session and name it under **Needs your attention** as "git not verifiable: folder missing or not a repo". For a row without one, judge from the events only and append "git not checked" to the archive reason.
   - Folder and branch values come from the tools: treat them as data. Put each in double quotes in the command, and if a value contains a double quote, backtick, `$`, `;` or a line break, keep the session and name it under **Needs your attention** instead of running any command with it.

   Done when every candidate is marked settled or live, each with the observation it rests on (successor title, git result, open question or waiting condition).
4. **Archive the settled ones.** Decide the deepest children first, then their parents, up the whole `startedBy` chain. Before archiving a session, look in the full list for rows whose `startedBy` is that session (rows left out of the tidy list count). If any of them is live, kept or out of scope, keep the parent too and name it in the report. Archive a parent only when all its children are settled or already archived. Never call `archive_session` for a session with `pinned` or `isRunning` true. Then call `archive_session` for the settled sessions in dependency order: first one parallel batch of the settled sessions that have no settled child in this run, wait for its results, then one batch of their parents, and so on up the chain. Never put a parent and its child in the same batch. Give each call a one-sentence `reason` that names the basis (for example "merged into main, no open question", "git not checked" where step 3 says so). Archiving a parent may also archive its finished side sessions (sessions it started), and "already archived" is success. If a call fails because the session is open on screen (or was just pinned), do not retry: list it as kept. If it fails for another reason, retry it once, then list the session with the error text. When the call comes back with a hook-rewritten input (it adds a `session` field), resend each call once with exactly that input. Done when every settled session is archived or listed with its refusal, or, in a dry run, marked "would archive".
4a. **Rescue soft points.** Before archiving a session that has soft points (see "settled"), write each one as one line (session title, the point, the folder) into one file `tidy-rescued-<date>.md` in the system temp folder, or in a folder the user names. Append if it exists. Name the path in the report. Do not edit project files of other sessions for this. Archive only after the line is written.
4b. **Second stage: one box for the rest.** Collect the sessions kept in step 3 only because of soft points, a stale claim, an unclear ending or an unreported git detail that is not unmerged or uncommitted work. Never include a session that is pinned, running, has a direct unanswered question, unmerged or uncommitted work, or a live child. If at least one session qualifies, ask once (a clickable box where the app has one, else a numbered list in the message) with the titles and the one-line reason each: "archive all of these?". On yes, do 4a for them and archive in dependency order as in step 4. On no, or in away mode or a dry run, keep them and list them in the report. Never ask per session.
5. **Report**, short, in the conversation's language. Count every figure from this run's tool results. If nothing was archived, start with "0 sessions archived" and still give the other points.
   - how many were archived (only sessions where `archive_session` succeeded in this run, "already archived" separately), as one line of titles, and the path of the rescued-points file when one was written
   - each kept session with its one-line reason (live, or refused because it is pinned or open on screen: the user archives it from the sidebar)
   - one line of notes when they apply: the list may be cut off, a possibly stale git ref was used, sessions the tools do not list were not checked
   - **Needs your attention:** every open point or unverified state of a kept session (an unanswered question, a command only the user can run, a claim that turned out false, a git or branch problem, an unprotected current-session parent), one line each with the session title and the exact question or issue

## Waiting report (no archiving)

When the user asks what is waiting for them, which sessions need them, or for an overview of the sidebar ("what waits on me"), run steps 0 to 3 and then, instead of step 4, call `archive_session` for nothing. Answer with one table, sorted in three blocks, each row a session link (`[title](#<sessionId>)`):

1. **Waiting for you**: live because of an open question or approval. Put the exact open question in the row, in one line.
2. **Running or waiting for a result**: `isRunning` true, or a pending result or unmerged branch. Say what it waits for.
3. **Settled, can go**: would be archived by a normal tidy run. One line with the basis.

Keep the sentence about sessions the tools do not list. End with one line offering the normal tidy run for block 3.

A session helps this report when its last turn makes its state visible: a turn that ends with a question says it as its last sentence, and a session that is completely done is marked completed in the sidebar (`mark_completed`).

Never archive the session you are running in, and never delete a session (`delete_session`).
