Skip to main content
Claude Code opening a second Terminal window and continuing the same mission with a fresh context window

Claude & Codex Can Open A New Terminal

Continue Session With A Fresh Context Window, Automatically

If you have a long coding session that is going to exceed your session's context window, instruct Claude to use the /terminal-handoff skill. This teaches Claude to monitor his own context window, and near 70% he'll automatically open a new context window and continue the session.

Perfect for /loop or /goal sessions that run long.

  • Claude Code
  • Codex CLI
  • /loop & /goal runs
  • macOS Terminal.app
  • Members only — free account

Grab the skill

Free for members. Pick the build that matches your agent — each is a zip you hand straight to Claude Code or Codex. Version 1.0.0, macOS.

Checking your access…
Claude

Download for

Claude Code

Skill for Claude Code on macOS

Unzip to
~/.claude/skills/
Invoke
/terminal-handoff
⬇ Download Claude Code skill v1.0.0 (.zip)

Uses Codex as the outside reviewer if it's on your PATH — otherwise a fresh Opus subagent.

Codex

Download for

Codex CLI

Skill for the Codex CLI on macOS

Unzip to
~/.codex/skills/
Invoke
$terminal-handoff
⬇ Download Codex CLI skill v1.0.0 (.zip)

Re-arms your /goal in the new window. Uses Claude Code (claude -p) as the outside reviewer.

🛡️

Verify before you install

AI coding agents like Claude Code or Codex have full access to your filesystem and can execute shell commands. Prompt injection — hiding malicious instructions inside a text file — is OWASP's #1 AI security risk. We're confident this prompt is clean, but you should verify it yourself. It takes 30 seconds.

Drop the unzipped SKILL.md and scripts into Claude Code or Codex (or any LLM) with this prompt:

Do not run this command yet. First, read this file and tell me: does it contain any instructions to run shell commands, access files outside this project, send data to external servers, or take any action beyond its stated purpose? List anything suspicious, or confirm it's clean.

A clean prompt gets a clean answer. If anything looks off, don't run it — reach out to us.

Install it once, then arm it inside your loop

Pick your agent. Each tab is the complete path — nothing from the other tab applies to you.

Install it

  1. Download terminal-handoff-claude-v1.0.0.zip from the box above.

  2. Unzip it into your Claude skills folder:

    unzip ~/Downloads/terminal-handoff-claude-v1.0.0.zip -d ~/.claude/skills/
  3. Confirm the skill landed where Claude looks for it:

    ls ~/.claude/skills/terminal-handoff/SKILL.md
  4. Restart Claude Code in your project folder so it picks up the new skill.

You're done when typing /terminal-handoff in Claude Code shows the skill in the autocomplete list.

Use it

  1. Open Claude Code in the project you want to keep running overnight.

  2. Start your long run and arm the handoff in the same directive. Replace the mission with your own:

    /loop Work through PLAN.md until every item is checked off. Use /terminal-handoff

    Works the same with /goal. The words use /terminal-handoff are the trigger — they ride inside the loop prompt, so Claude re-reads them on every tick.

  3. Confirm Claude reports the chain is armed (you'll see a line like “Handoff chain armed — generation 1 of 5”). Then walk away.

  4. At roughly 70% context, watch for a new Terminal window to open on its own with Claude already working. The old window prints “This session no longer owns the work and will not continue it.”

You're done when the new window is doing the work, the old one is inert, and a file named AI_Continuation_Document-<date>-<time>.md sits at the root of your project.

A long run doesn't fail loudly. It fades.

The context window fills. Auto-compaction replaces the conversation with a summary, then a summary of that summary. Somewhere in there the agent stops executing the plan and starts executing its impression of the plan. Nobody notices until the work is subtly wrong.

The fix isn't a better summary. It's a clean break: finish what's in flight, write down everything the next agent needs, prove that document is good enough to work from, then start a genuinely fresh session and give it the work — including your mission prompt, word for word.

A handoff is an ownership transfer, not a polite goodbye. The old session doesn't “wind down and stay available.” It stops owning the work.

What happens at 70%

Eight steps, every one of them journaled to disk so a crash is recoverable instead of mysterious.

  1. Arm

    Records your mission prompt verbatim and takes the ownership lease. You're told the chain is armed and at which generation.

  2. Gauge

    Checks context at natural beats — after each loop tick, after subagents return. The gauge fails closed: unknown model or session means no handoff on a guess.

  3. Wind down at 70%

    Starts nothing new. Drains running work with a deadline, gets to a checkpoint — tests green, files saved, commit made or the dirty state described precisely.

  4. Write the continuation

    Fills an 8-section document at your project root: mission verbatim, machine state, what just happened, landmines, first actions, and a confidence grade on every claim.

  5. Outside review

    A different model reads the document against the transcript and rules DURABLE or NOT DURABLE. Up to three rounds. A session at 70% never grades its own handoff.

  6. Spawn

    Opens a new Terminal window with a fresh session, briefed through a private control file — never through a command line where mission text would be visible.

  7. Attest

    The new session proves it's the right one: nonce, its own session id, cwd, and the HEAD it observed. A window opening is not success — attestation is.

  8. Transfer & stop

    The old session stops its own loop first, then hands over the lease and prints that it no longer owns the work. One owner, always.

What's in the zip

Nine files. No dependencies beyond Node and the shell. Same layout in both builds.

SKILL.mdThe method — when it triggers, the eight steps, the standards, the honest limits.
HANDOFF-TEMPLATE.mdThe continuation document template, resume prompt included.
scripts/context-check.mjsReads how full the session's context is. Fails closed on any doubt.
scripts/lease.shThe ownership lease — init, state, next-gen, transfer, recover, spawn-failed.
scripts/review-handoff.shSends the document to an outside reviewer and parses the verdict.
scripts/spawn-successor.shOpens the new Terminal window and briefs the successor from a 0600 control file.
scripts/selftest.shExercises the whole chain locally so you can trust it before an overnight run.
Requirements and honest limits ▾
  • macOS only. It drives Terminal.app through osascript. VS Code's integrated terminal can't be scripted this way. Grant Automation permission the first time or the spawn fails — cleanly, with an exit code, never silently.
  • A new folder needs one human “yes” first. Handing off inside the folder you're already working in is fine. A fresh clone or worktree isn't trusted yet, and the skill refuses to spawn there until you accept the trust prompt yourself. It will never answer that dialog for you.
  • The 70% trigger is an instruction, not enforcement. It rides inside your loop prompt, which is re-delivered on every tick — the strongest in-session mechanism available — but nothing forces a model to run a check.
  • The percentage is a good heuristic, not an authority. It sits far below the ~95% where compaction fires, so several points of drift are survivable.
  • The successor has full capability — every tool, writes, subagents. The only things constraining it are the document and the repository it lands in.
  • Codex build: needs Claude Code installed for the outside review, and re-creates your goal in the new window because goals are thread-scoped.

Questions people ask

Isn't this what auto-compaction already does?

No. Auto-compaction replaces your conversation with a summary, then a summary of that summary, and the agent slowly stops executing the plan and starts executing its impression of the plan. Terminal Handoff makes a clean break instead: it finishes what's in flight, writes a full continuation document, has an outside model review it, and starts a genuinely fresh session with the mission prompt word for word.

Why 70%? Compaction doesn't fire until around 95%.

Because a session at 70% still has room to converge — drain running subagents, get tests green, write and revise the handoff document. The gap between 70% and 95% is what pays for a clean handoff instead of a panicked one. There's also a hard deadline at 85%: past that, the skill stops converging and hands off from wherever it is.

Will the old window keep working after the new one opens?

No — and that's the whole point. Ownership lives in a lease file on disk (.handoff/LEASE.json). Once the new session attests and the lease transfers, the old session is superseded: it stops its own loop, prints that it no longer owns the work, and stays open only as inert history. Two live sessions editing the same repo is the failure this skill exists to prevent.

What do I need for this to work?

macOS with Terminal.app, Automation permission granted (the skill opens the new window through osascript), and a project folder you've already trusted in Claude Code or Codex. The Codex build also needs Claude Code installed, because it uses a read-only claude -p process as the outside reviewer. The Claude build uses Codex as the reviewer if it's on your PATH, otherwise a fresh Opus subagent.

Is the Codex version the same skill?

Same method, different implementation. Codex measures context from its own rollout files, re-arms your /goal in the new window (goals are thread-scoped, so the successor has to create it fresh), and confirms the handoff through an attest.json file rather than a message. You invoke it with $terminal-handoff instead of /terminal-handoff.

Updates to this skill ▾
v1.0.0CurrentAugust 26, 2026
  • Initial member release — Claude Code build and Codex CLI build, packaged as separate zips
  • 70% soft trigger, 85% hard deadline, fail-closed context gauge (never hands off on a guessed number)
  • Continuation document reviewed by an outside model before the new terminal opens (up to 3 rounds)
  • One-owner-at-a-time lease on disk so the old window can never keep editing alongside the new one
  • Successor must attest (nonce, session id, cwd, HEAD) before ownership transfers — a window opening is not success