agentleFS
surasakchosurasakcho/claude-skills/rotate-session/SKILL.md

rotate-session

Skill0 starsChanged 5 months agoMITView on GitHub

Refresh (rotate) the CURRENT Claude session in place — hand off, wrap, then drop and relaunch a fresh same-name successor with an empty context window. Only rotates the session you are inside, and only in a repo that has opted in with a committed .claude/rotate.conf.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run from inside the session you want to refresh.

    line 40
  2. Very specific:

    Preflight — refuse early if not permitted: Run assets/rotate.sh --preflight.

    line 42
  3. Very specific:

    Handoff note (inlined): Write the deliberate ## Next Session note (from the focus argument) into the repo's committed handoff file …

    line 46

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

rotate-session — refresh the current session in place

Rotate the current Claude session: preserve continuity to disk, then replace this session with a fresh same-name successor (empty context window). Continuity is reconstructed from committed, pushed files — not from the discarded conversation.

This is the promoted, every-repo version of the sandbox session-sandbox mechanism. The sandbox is safe because only sbx-* names are targetable; here the guard is self-rotation only — the sole session this skill can ever kill is the one it is running inside (target == tmux display-message -p '#S'). A typo or bad config cannot reach another repo's session.

Activation (why it may refuse)

A repo rotates only if it contains a committed .claude/rotate.conf whose SESSION equals the live session name. Absent that file, the skill hard-refuses. This is the gate: the skill is installed in every repo but active only where a config has been added. Until the mechanism is verified in the sandbox, only the sandbox repo carries a rotate.conf.

.claude/rotate.conf fields:

SESSION=ebiz               # REQUIRED: the tmux session name this repo runs under
MODEL=opus                 # optional: --model for the successor
EFFORT=high                # optional: --effort for the successor
RC_NAME=Factory-$(hostname) # optional: --remote-control name (default: SESSION)
PERMISSION_MODE=acceptEdits # optional: --permission-mode for the successor
DELAY=60                   # optional: seconds until the successor launches (default 60)

Steps (run in this order)

Run from inside the session you want to refresh.

  1. Preflight — refuse early if not permitted. Run assets/rotate.sh --preflight. It verifies: inside tmux; .claude/rotate.conf present; its SESSION equals the current session (the self-target guard); systemd-run available. On PREFLIGHT FAIL, print the reason and STOP — change nothing.
  2. Handoff note (inlined). Write the deliberate ## Next Session note (from the focus argument) into the repo's committed handoff file (CONTEXT.md / HANDOFF.md / TODO.md) and commit + push just that file. This is the /handoff action performed inline: handoff is a user-invoked skill and, per this repo's docs/invocation.md, a user-invoked skill (this one) can never invoke another user-invoked skill — so do the note yourself rather than calling /handoff.
  3. /wrap — invoke the /wrap skill (it is model-invoked, so this user-invoked skill may call it). It summarises, updates project logs, and commits and pushes everything. Capture the resulting commit SHA (the successor verifies it). If /wrap does not push cleanly, ABORT: do not schedule a successor, do not kill. The session stays alive with work intact. /wrap's successful push is the hard gate on the irreversible kill.
  4. Rotate — run assets/rotate.sh <pushed_sha>. It schedules the same-name successor (detached via systemd-run --user, so it survives this session dying) then does the guarded self-kill. Scheduling happens before the kill, so a scheduling failure leaves the predecessor alive — never a coverage gap.
  5. Report — the session drops now and reappears fresh under the same name in ~DELAYs; the successor reads the committed handoff and confirms the predecessor SHA before acting.

Assets

  • assets/rotate-env.sh — the self-target guard (rotate_assert_self, rotate_kill). Source first.
  • assets/rotate.sh — --preflight checks; else schedule-before-kill (the mechanical half).
  • assets/rotate-launch.sh — launch a same-name successor on a real TTY (tmux pipe-pane logging).
  • assets/rotate-status.sh — read-only: is a session on a TTY and relay-connected?
  • assets/selftest-guard.sh — proves the guard accepts only the current session; run it anywhere.

Notes

  • Adding this skill is a global ~/.claude change → file the FYI issue your project requires.
  • v1 is manual only. Auto-firing at a context ceiling (~30%) is a separate, later change.
  • The sandbox sbx-* scripts are NOT modified — they remain the isolated dev harness.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.