<!--
SPDX-FileCopyrightText: Amolith <amolith@secluded.site>

SPDX-License-Identifier: CC0-1.0
-->

# `@amolith/pi-handoff`

[![pi-handoff on NPM](https://img.shields.io/npm/v/@amolith/pi-handoff)](https://www.npmjs.com/package/@amolith/pi-handoff)
[![Licensed under MutuaL-1.2](https://img.shields.io/badge/License-MutuaL--1.2-af2e1a?style=flat&labelColor=110402&link=https%3A%2F%2Fcodeberg.org%2FMutualism%2FMutualist-License)](https://codeberg.org/Mutualism/Mutualist-License)
[![REUSE status](https://api.reuse.software/badge/git.secluded.site/pi-extensions)](https://api.reuse.software/info/git.secluded.site/pi-extensions)
[![scratchanitch.dev badge](https://img.shields.io/badge/scratchanitch-dev-FFC4B5)](https://scratchanitch.dev)
[![Liberapay donation status](https://img.shields.io/liberapay/receives/Amolith.svg?logo=liberapay)](https://liberapay.com/Amolith/)

Get to the end of the thing you're doing, then use a subagent to extract
relevant bits from the current session and create a new one from them with
`/handoff thorough goal description`. You can tell Pi to hand something off
because it has a handoff tool too.

After extraction, whether triggered by you or Pi, the draft handoff goes in the
new session's prompt editor and an auto-submit countdown starts that's cancelled
by pressing most any key.

## Install

```sh
pi install npm:@amolith/pi-handoff
```

If you try it and find that it doesn't behave as expected, please send me your
session file, the goal, and the resulting handoff so I can debug. Contact me via
the methods listed at the bottom of [my website](https://secluded.site), or if
you know me elsewhere, you're welcome to DM me there.

## Do it yourself

Run `/handoff` with whatever the next session should do:

```text
/handoff finish the release notes and publish both packages
```

If you omit the goal, Pi asks for one. Before the new session starts, the
extension opens the generated handoff draft in the editor so you can review or
tweak it. After the session switch, it starts an auto-submit countdown and
pressing most any key cancels it.

To use a different model in the new session, pass `-model provider/modelId`:

```text
/handoff -model neuralwatt/glm-5.1 finish the release notes
```

## Let the agent do it

The package also registers a `handoff` tool. The agent should only use it when
you explicitly ask for a handoff. It accepts:

- `goal`: the goal for the new session
- `model`: optional `provider/modelId` for the new session

The handoff happens after the current agent turn completes and still opens the
editor so you can tweak before starting the new session.

## Configure the extraction model

It uses the current session model by default. Interactively select a
cheaper/faster model by running:

```text
/handoff:set-extraction-model
```

It opens Pi's model picker and saves the selected model in
`$PI_CODING_AGENT_DIR/settings.json` as `handoffExtractionModel`.

You can also set a `provider/modelId` with one of these:

1. Startup flag: `--handoff-extraction-model provider/modelId`
2. Env var: `$PI_HANDOFF_EXTRACTION_MODEL`
3. Settings value: `handoffExtractionModel` in `$PI_CODING_AGENT_DIR/settings.json`

If you set more than one, that list is the precedence order.

Example settings:

```json
{
  "handoffExtractionModel": "neuralwatt/qwen3.6-35b-fast"
}
```

If the configured value is malformed or doesn't match a registered model, the
extension falls back to the current session model.

## Ask about the old session

New handoff prompts include the parent session path when available. The package
registers a `session_query` tool so the next agent can ask focused questions
about that prior session when the handoff summary isn't enough.
