Install
Install with PiG
pig install npm:@tduyng/pi-sessionInstall with Pi
pi install npm:@tduyng/pi-sessionPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./src/auto-name.ts",
"./src/autoresume.ts",
"./src/peers.ts",
"./src/notify.ts",
"./src/rex-bridge.ts"
]
}README
Written by the package's publisher, shown as published in version 0.0.6 (README.md). PiG does not review it.
@tduyng/pi-session
Three gaps in session handling, all filled from what is already on disk. A session names itself from the first user message. A turn killed by a usage limit resumes when the limit resets. Sessions in the same directory can message each other.
Nothing is configured beyond one environment variable, and no tool is registered.
Two sessions in one directory
Each session writes its pid to .pi/peers/live/ and removes it on shutdown, so a session whose pid is still running is live. Nothing warns about it: pi-guard's reserve refuses an edit to a path a live peer holds, and a notice on top of that only interrupted work that was already committed.
Sending by hand
/peer on its own names the sessions live in this directory. /peer <name or id> <message> sends one, and says whether it landed. The same mailbox the tool uses carries it, so the recipient reads it at its next turn, and the command costs nothing until it is typed.
Messaging that session
peer is declared on every request at 140 tokens. It used to arm itself once another session was live in the directory, and that arming rewrote the cached prefix for 140 tokens of schema, so the tool is now always there. It has three actions. list names the live sessions and the name pi-session gave each one. send delivers a note and returns. ask delivers a question and waits up to ten minutes for the answer, which comes back as the tool result. send and ask take the name list shows, and with one live peer they can leave it out: four recorded calls asked a question with no name and were refused.
Mail is a file under .pi/peers/mail/<session id>/, written to a temp name and renamed into place, so two writers never own the same path and a reader never sees a half-written message. Claiming a message deletes its file, and only one unlink of a path can succeed, so two readers never both take it. A message lives 24 hours and a mailbox holds 256, dropping the oldest, and a read sweeps the temp file a crashed write left, so an abandoned mailbox does not grow.
A session collects its mail on session_start and turn_end, and an idle one looks every five seconds, because a question has to reach a session that is sitting still or the asker waits for a turn that may never come. PI_PEER_POLL_SECONDS sets that interval and 0 turns it off. A session that collected its mail and then finds itself idle hands it to pi as an extension message, so it is in the transcript and the next request sees it. wake: false marks a note as information: it waits for the next turn instead of starting one, while a question always wakes its recipient. A plain answer completes the question it answers, because the delivered text names the sender and the action, and the ask sits in a ten-minute window that matches the asker's own wait. A late answer is not lost: it arrives as an ordinary message.
Naming
A new session starts unnamed, so a picker fills with 2026-09-01 14:22 rows and the session wanted is the one that cannot be identified.
On agent_end the extension reads the first user message and uses it: first line, a leading / or # stripped, whitespace collapsed, 60 characters at most, cut at a word boundary.
A week of timestamps becomes fix retry backoff, review auth diff, migrate schema.
An expanded skill uses its argument when there is one, otherwise the skill name. A /skill:name task command uses task. A name set with /name always wins, and naming runs last and swallows its own errors, because it is cosmetic and must never block a turn.
Resuming after a quota reset
When a provider quota kills a turn, the error usually carries a reset time. The parser accepts the shapes that appear in practice: epoch, ISO, try again in 2h 15m, resets 11:30pm (Europe/Paris), retry-after: 3600.
For a claude-bridge session with no time in the error, it asks the Anthropic OAuth usage endpoint and takes the latest reset among the exhausted windows. The usage API wins over the error text, since the error is a snapshot and the API is the current state.
The resume is a real user message on the same session: "The usage limit has reset. Continue the previous task from where it stopped." Nothing is replayed and nothing is stored.
A scheduled resume adds a 5 second safety delay past the reset and caps at 24 hours. Further out than that it warns and schedules nothing. Any user turn, session shutdown or new session cancels it, so a timer never fires over work already resumed by hand. That last case is deliberate: after a reload the schedule is gone rather than firing into a context the old session owned, and /autoresume status is how you find out it is no longer pending.
/autoresume status, including the pending resume time
/autoresume on
/autoresume off
/autoresume cancel
The quota lookup reads the Claude Code OAuth credential from the macOS keychain item Claude Code-credentials, or from ~/.claude/.credentials.json. Nothing else is read, and no value is logged.
Notifications
With several sessions open, finding the one that finished or is waiting means checking each pane. On macOS a session sends a notification, titled with its name, when a run of 30 seconds or more settles, and when a running agent opens a prompt that blocks on you, such as ask_user or a tool confirm. A prompt you opened yourself while idle, /cost for one, sends nothing: you are already there. A short run, a run stopped with Escape, and a session without a UI (a subagent child, pi -p) send nothing.
Install
pi install npm:@tduyng/pi-session
Naming needs nothing. The quota lookup needs network access to api.anthropic.com and either keychain access (macOS may prompt once) or the credentials file.
Limits
- Names are cut at 60 characters on a word boundary.
- The resume polls its timer every 10 seconds, so it can fire up to 10 seconds late.
- The quota lookup is Anthropic only. Other providers get the error-text path.
- A provider that changes its error wording gets no resume.