@blueocean223/pi-btw
/btw for pi: ask a side question against the main conversation's context without interrupting the running task
Package details
Install @blueocean223/pi-btw from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@blueocean223/pi-btw- Package
@blueocean223/pi-btw- Version
1.0.0- Published
- Nov 16, 2026
- Downloads
- 303/mo · 303/wk
- Author
- blueocean223
- License
- MIT
- Types
- extension
- Size
- 95.4 KB
- Dependencies
- 0 dependencies · 4 peers
Pi manifest JSON
{
"extensions": [
"./index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-btw
English | 简体中文
A Pi extension that adds /btw: ask a question about the conversation you are already in, get one answer, and leave the main task running.
/btw what is WBC in this diff
The main agent does not stop, is not steered, and never sees the question. The answer appears in a panel where the editor was and goes nowhere else — not into the transcript, not into the session file.
Why not just ask
Three things already in Pi almost do this and each one costs something:
| What it does | |
|---|---|
| Enter while streaming | Steers the main task. Your question becomes part of the work. |
| Alt+Enter | Queues a follow-up. You get the answer after the task finishes. |
| A second session | Answers with no idea what "this diff" refers to. |
/btw is the fourth option: the same context, a separate one-shot agent, and nothing written back.
What it does
- Answers from the conversation's own context — the system prompt, the tool schemas and the messages the main loop last sent, so "this diff" and "that function" mean what you think they mean
- Reuses the main request's prefix, byte for byte, so a side question reads from the provider's prompt cache instead of paying to write a second copy of the context
- Cannot act. No tools run. The schemas are in the request for the cache, and nothing feeds a tool result back. A model that writes a tool call as prose gets a line under it saying none of it happened
- Remembers up to 20 exchanges per session, in memory only. Earlier side questions can see each other; the main task still cannot see any of them
- An empty
/btwreopens the last one, or reattaches to one still in flight
Keys
| Key | |
|---|---|
Esc |
Cancel the request and close |
Enter / Space / Ctrl+] |
Close. An open request keeps running — an empty /btw picks it back up |
↑ / ↓ |
Scroll the answer |
[ / ], or Shift+← / Shift+→ |
Step through recent side questions |
c |
Copy the answer as markdown |
x |
Clear the list above the panel. The answer on screen stays |
Escape is the only key that cancels. In Claude Code the panel can be put away and dismissed by separate paths, and only one of them aborts; here the panel owns the keyboard while it is up, so closing it has to be free.
Install
pi install npm:@blueocean223/pi-btw
Restart pi, or run /reload inside a session. Add -l to install into the project (.pi/settings.json) instead of globally, and pi remove npm:@blueocean223/pi-btw to uninstall.
To try it for a single run without installing:
pi -e npm:@blueocean223/pi-btw
From source (for development)
git clone https://github.com/BlueOcean223/pi-btw.git
cd pi-btw
pi install "$(pwd)"
A local path is added to settings without copying, so edits apply on the next /reload.
Notes
- Interactive only. In
print,jsonandrpcmodes/btwsays so and sends nothing. - A side question sees the main loop's last outbound request, not the response to it. A tool result recorded since then shows up in the next side question, after the main loop sends again.
- While the panel is up it owns the keyboard, so the main task's interrupt key is not reachable. Close the panel first.
- The exchange list lives for as long as the process does. Switching sessions and back keeps it; quitting or
/reloaddrops it, and an empty/btwis back to the usage line. - Snapshots cover the ten chat APIs Pi ships: Anthropic Messages, OpenAI Chat Completions, Responses (including Azure and Codex), Mistral, Google Gemini and Vertex, Bedrock Converse, and pi-messages. Where the turns are appended follows the model's API, not a guess from field names. An API an extension registered itself is rebuilt. Side questions pass the main session's
sessionIdand the headers the main loop added for that request (OpenCode session routing, headers frombefore_provider_headers). Credentials are still whatever resolves now. Cache hits still depend on the provider's cache lifetime and gateway routing. - Official Codex side questions go over SSE. The main loop keeps its WebSocket, and a side question does not clear that connection's continuation. The prefix and
prompt_cache_keystay as they were, so the cache still hits on the prefix. - Not every request makes a reusable prefix. On the Claude models that accept mid-conversation system messages, a body ending on a prompt-section update is left alone and the question is rebuilt instead, which misses the cache until the main loop sends again.
Debugging
With PI_BTW_DEBUG set, each side question leaves two things: a notify line, and one JSON line appended to btw/debug.jsonl in pi's agent directory (~/.pi/agent/btw/debug.jsonl, or under PI_CODING_AGENT_DIR). The file stays after pi exits, and it is outside the session directories, so pi does not list it as a session. The exchanges themselves are still kept in memory only, and nothing reads the log back. The line does include the question text: with debugging on, side questions reach disk in this file, never in the session file.
PI_BTW_DEBUG |
Writes |
|---|---|
unset, empty, 0, false, off |
nothing |
body |
the line, plus the full request body as a file in btw/bodies/ |
any other value, e.g. 1 |
the line |
The notify line reads /btw snapshot cacheRead=101233 cacheWrite=0 input=38, or /btw rebuild(model-changed) … when the snapshot was not used. The first write in a process also says where the log is.
| Field | |
|---|---|
ts, pid, session |
when the side question started, which pi process, which session |
provider, model, api |
the model it went to |
path |
snapshot: the main request's body with the question appended. rebuild: rebuilt from the session transcript |
reason |
why it was rebuilt: no-snapshot, capture-failed, other-session, model-changed, api-unsupported, body-shape, ends-with-system |
snapshotAgeMs |
age of the main request's snapshot when the question went out |
captureError |
the main loop's latest body could not be copied; a snapshot used is older than that request |
prefixBytes, bodyBytes |
JSON size of the captured main body (snapshot path only), and of the body sent |
historyTurns |
earlier exchanges replayed ahead of the question |
transport |
the transport, when one was set: sse for Codex, or the configured one |
durationMs, outcome, detail, stopReason, fallbackNotice |
how it ended. outcome is answered, aborted or synthetic; for synthetic, detail holds the extension's own text, such as an API error |
usage |
input (uncached), output, cacheRead, cacheWrite |
bodyFile, bodyError |
body mode only |
question |
the question. The answer is not logged |
On the snapshot path the prefix is the main request's own bytes, so a cacheRead near zero points at an expired cache entry or a gateway that routed elsewhere, not at a changed prefix. Compare snapshotAgeMs with the provider's cache lifetime (Anthropic's default is five minutes). On the rebuild path the prefix is re-derived and can differ from the main request's. OpenAI usually reports zero cacheWrite; compare input with cacheRead instead.
body mode writes the whole main context — files the agent read, tool output — to disk for every side question, and nothing deletes those files. The log and the bodies are created readable by their owner only. Request headers are never written.
Not in this version
- Promoting an answer into a real branch. Claude Code's
fsplices the exchange into a parallel fork while the main session keeps going. Pi'sctx.forktears the current runtime down and switches to the fork, which stops the main task — the thing/btwexists to avoid. - Tools for side questions. That is a different feature; the permission model here is that schemas exist for the cache and calls are never executed.
/btwin the middle of a sentence. Pi dispatches commands from the start of the input only.- Images. The question is text. Images already in the shared prefix come along with it.
Development
bun install
bun run test # unit tests and local HTTP capture; no model service calls
bun run typecheck
The tests and the type check import the packages pi supplies at runtime (@earendil-works/*, typebox). bun install leaves them out (bunfig.toml), so they come from the pi you run: link them from your pi install into node_modules/ here or in a parent directory.
npm publish runs the tests, the type check and scripts/verify-pack.mjs first; the script checks the tarball npm would ship against the import graph (nothing missing, no tests or local notes included).
License
MIT