context-handoff

Code on GitHubHow to try it

I built context-handoff so a Claude Code session can pass its job to a fresh one before its context runs out. At 85 % it prepares a handoff, at the latest at 89 % it opens a new terminal window with the same model and effort, and the old session closes itself. It's free and open source, and it comes from the handoff skill I run every day on my own Mac.

Needs macOS, Claude Code, Python 3.9+, bash and jq. Runs in Warp, Ghostty 1.3+ or Terminal. MIT license.

Illustration of one handoff between two terminal windows. Window A reaches 85 % context and writes a brief. Window B starts on that brief with the same model and effort. Window A then closes itself.
An illustration of one context handoff, not a screenshot: window A hits 85 %, writes a brief, window B starts on it with the same model and effort, and A closes itself.

What do I do when my Claude Code context is almost full?

I run several Claude Code windows per project at the same time, and all of them follow one rule: from 85 % context prepare, at the latest at 89 % hand over to a fresh session. The fresh one takes over the same job with the same model and effort, and the old window closes.

My private handoff skill has run since 31 August 2026. On 11 November 2026 I counted 534 brief files and 528 start markers. The oldest is a self-test, so more than 500 sessions started this way.

Since 7 November 2026 the script switches the closing of the old window on by itself at 85 %. The reason is a check of four days, in which 13 of 15 context handoffs were clean. In the other 2 the session had left out the closing, and I had to close the old window myself.

The repo is the public part. My private version has more, such as other model engines and a task register, and that stays private. I designed it, set the rules and accept the result. Claude Code wrote the code. Four models from other labs reviewed the code: Codex, GLM, Muse and Grok. In two rounds they reported 32 real problems and 3 false alarms. All 32 are fixed, each with a test where a test can show it.

What does the /handoff skill do in Claude Code?

Task handoff

Use it when you want a task done in a session of its own. A new terminal window opens with a fresh session, and this session keeps working. The brief is short, and the new session asks you for the rest.

Context handoff

The watcher reports 85 % or 89 % context. The new session gets the same model and effort, you get no question, and the old session ends itself after the new one has started. The brief holds the full state of the work.

Role handoff

The new session takes over this session's job, for example a fresh lead. It runs like a context handoff, at any context level.

The brief

The new session starts on a Markdown file. For a task handoff it holds one or two sentences and one or two pointers. For a context or role handoff it holds the full state: what is done, decisions and why, what is open, the next step, your rules and the handoff rule itself.

How does a Claude Code session hand over at 85 % context?

The status line saves the context number

Claude Code hands a JSON status to the status line command, with the context fill in percent, the model and the effort. The helper saves it as a file only you can read and prints one line, for example Opus 5.5 · context 42 %. If you already have a status line, copy its marked lines into yours.

The watcher reads it after every tool call

A PostToolUse hook reads that file. From 85 % it tells the session once to prepare: start no new step, finish the running one, wait for its own background jobs and save the work (commit, notes). From 89 % it says to hand over now, again at every new percent point. It never blocks a tool call and stays silent on any error. Subagents get no message.

The session writes a brief and runs the spawn script

The session writes the brief and runs the spawn script (Python, standard library only). For each spawn the script makes a fresh private folder under /tmp and writes a one-time start script and a go token into it. The start script deletes itself when it runs and starts claude in the working folder with the model, the effort, a session name and the prompt to read the brief.

The script checks that the new session started

The check passes when the marker is there within 60 seconds and the process still runs 3 seconds later. If no marker came, the script withdraws the go token, so a late window starts nothing. Exit 1, and a retry is safe. If the start script had already taken the token, the script waits 30 seconds more. If the marker still does not come, it says the start may still come. Look for the new window before you try again.

The old session ends itself

With the close option the script waits 10 seconds, then ends the old session with a hangup signal (SIGHUP), but only if the new one still runs with the same process id and start time. If the old session ran directly in the window's login shell, that shell ends too and the window closes. A session hands over once, and the script switches the close option on by itself at 85 % or more.

How do you run several Claude Code windows at once?

In my setup, one window is the Team-Lead. It runs the project, keeps the decision log and hands tasks to worker windows with /handoff. I run the Team-Lead on Claude Fable 5.2 with effort max.

Some windows run for a long time, for example a lab that runs model tests. They do not talk to me in their own window. Their questions, approvals and requests, such as a login or a click, go to one window: the Key account. It bundles them and asks me in one question dialog. It passes my answer back and reports it to the Team-Lead, which writes it into the decision log. I run the Key account on Claude Sonnet 5.5 with effort xhigh.

Worker windows for a short task talk to me directly. When the task is done, they save their work and close their own window.

Every window follows the same context rule, so the team keeps running while each window starts fresh. The context watcher has run since 6 October 2026, and the old window has closed itself since 21 October 2026.

Does context-handoff work in Warp, Ghostty and Terminal?

On 11 November 2026 the tests ran on my Mac with macOS 27.0.1, Claude Code 2.1.322, Warp 0.2026.11.04.08.17.01, Ghostty 1.3.1 and Terminal 2.15.

In each of the three terminals, session A started session B with the close option. B started, A ended about 10 seconds later and its window closed. In Ghostty the test also covered a cold start (Ghostty not running) and confirm-close-surface = always.

A real Claude Code session (Sonnet 5.5) started in a new Warp window from a brief, with model, effort and session name, and answered. Its window closed after the session ended.

The 67 offline tests pass. The end-to-end tests ran the spawn script with the system Python 3.9 of macOS. While the Mac was under heavy load (load average above 270), Warp sometimes failed to start the shell in a new window. The spawn then reported that nothing started, withdrew the go token, and nothing started twice.

It runs on macOS only, in Warp, Ghostty 1.3 or newer and Apple's Terminal. For other terminals, the window part is one function in the spawn script, open_window. The context number comes from the status line, so without the status line helper there is no watcher message and no automatic closing at 85 %. The known limits are listed below.

What are the known limits of context-handoff?

  • The new session does not report back to the old one. The only start check is the marker and the process.
  • A session you end yourself in Terminal leaves its window open if your Terminal profile says so (Settings, Profiles, Shell, When the shell exits).
  • A session that runs in a sub-shell of its window ends after a handoff, but its window stays open.
  • Only CLAUDE_CONFIG_DIR is passed on to the new session. Everything else it gets from its terminal.
  • The script finds the calling session by its process name, which starts with claude. If it finds none, the new session runs, the old one stays open with a note to close its window by hand, and it does not hand over again.
  • Under very heavy load a terminal can take longer than 60 seconds to open a window. The spawn then reports that nothing started, and nothing starts later.

How do I install context-handoff?

You need macOS with Warp, Ghostty 1.3 or newer, or Terminal, plus Claude Code (tested with 2.1.322). The spawn uses its options for model, effort and name. You also need Python 3.9 or newer, bash and jq. Clone the repo, copy the skill and the two scripts into your Claude Code config folder, run the tests and check the spawn script's help:

git clone https://github.com/kevintheo-ai/context-handoff.git
cd context-handoff
mkdir -p ~/.claude/skills ~/.claude/hooks
cp -R skills/handoff ~/.claude/skills/
cp hooks/context-handoff-watch.sh statusline/save-status.sh ~/.claude/hooks/

Then merge the settings block from the README into your settings.json. It sets up the status line and the PostToolUse hook, and the env block with the 85 and 89 thresholds is optional. The 67 offline tests need pytest. They open no window and end only processes they started themselves. The README has every detail.

Read the README on GitHub

Let's talk

“Are you hiring for agent operations, or do you run your company with AI agents too?”

Email meLinkedInFollow on XGitHub

x@kevintheo.com

I post my new test results on X. Follow me there if you want to see them.