@moguw/pi-session-rename
Automatically name Pi sessions from conversation context
Package details
Install @moguw/pi-session-rename from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@moguw/pi-session-rename- Package
@moguw/pi-session-rename- Version
0.3.1- Published
- Oct 31, 2026
- Downloads
- 519/mo · 261/wk
- Author
- moguw
- License
- MIT
- Types
- extension
- Size
- 34.6 KB
- Dependencies
- 0 dependencies · 3 peers
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
🏷️ pi-session-rename — Automatic Session Naming
@moguw/pi-session-rename is a native Pi coding agent extension that automatically
names Pi sessions from conversation context. The session gets a structured MMDD|TYPE|Topic title
after the first turn and the name is refreshed periodically as the conversation evolves, while
/rename gives you full manual control.
✨ Features
- Auto-names the session after a configurable number of user-agent turns (default: the first turn).
- Refreshes the name periodically as the conversation evolves (default: every 5 turns).
- Titles follow
MMDD|TYPE|Topic— session start date, a type code, and a short topic. /renamegenerates a name from the conversation with the configured naming model./rename "<name>"sets a session name directly, overriding any automatic naming.- Automatic naming never overwrites a manually set name.
- Naming model and thinking level are configurable per user (
~/.pi/agent/rename.json).
📦 Install
pi install npm:@moguw/pi-session-rename
Try without installing permanently:
pi -e npm:@moguw/pi-session-rename
For local development from the pi-ext repository root:
pi -e ./extensions/pi-session-rename
🚀 Usage
The extension auto-renames an unnamed session after a configurable amount of conversation, and
provides /rename for manual control.
/rename Generate a name with the configured naming model
/rename "<name>" Set the session name directly
/rename settings Configure model, thinking level, and auto-rename timing
For example:
/rename -> "0903|FEA|Auth middleware refactor"
/rename "Billing schema migration" -> sets the name directly
⚙️ Configuration
/rename settings edits ~/.pi/agent/rename.json.
{
"afterSteps": 1,
"everySteps": 5,
"model": "",
"thinkingLevel": "low"
}
Fields:
afterSteps: user-agent turns before the first auto-rename.0disables auto-renaming.everySteps: re-run auto-rename every N user-agent turns after the first.0names once and never refreshes.model: naming model asprovider/model. Empty uses the current session model.thinkingLevel: thinking level for the naming request (default:low). One ofoff,minimal,low,medium,high,xhigh,max.offomits the reasoning option.
The previous ~/.pi/agent/pi-session.json path is not read or migrated.
🧠 Behavior
- Naming uses the configured model, or the current session model when
modelis empty, throughpi-ai. - Auto-rename fires on the
afterSteps-th user-agent turn (default: the first), then again everyeveryStepsturns (default: 5) so the title tracks how the conversation evolves. An unnamed session retries on every turn pastafterSteps, so a failed first attempt or a continued session (pi -c) does not wait a whole cycle for its first name. - Naming runs on
agent_settled, once per user turn, so retries, aborts, and queued continuations never trigger a second request. - Titles follow
MMDD|TYPE|Topic: the session start date in Asia/Shanghai, a type code — one ofFEA(feature),DES(design),FIX(bug fix),OPT(optimization),REL(release),EXP(exploration),DOC(docs),RES(research) — and a short topic in the user's language. A forked session counts from its own start, not the source session's. - Naming instructions and the tagged output contract are built in and are not user-configurable.
- The request reuses the session transport, websocket connect timeout, session id, and configured naming thinking level.
- Naming requests have a 60-second timeout and do not set an output-token limit.
- The model must return
<session_name>...</session_name>with fewer than 30 words; names are truncated to 120 characters. - Only text response blocks are parsed; thinking blocks are ignored.
- Automatic naming never overwrites a name it does not own, so
/name, RPCset_session_name, an extension'spi.setSessionName(), and the session picker's rename all stay authoritative. Only names this extension generated are refreshed.
🔧 Development
pnpm install
pnpm run typecheck
pnpm test
Enable temporary naming diagnostics before starting Pi:
PI_SESSION_RENAME_DEBUG=1 pi -e ./extensions/pi-session-rename
The extension appends response diagnostics to ./debug.log in Pi's working directory. The log
includes response block types, stop reason, token usage, short previews, and the reason an empty
name was rejected.
🗂️ Package layout
src/index.ts Pi package entrypoint
src/rename.ts Rename command and automatic naming lifecycle
src/config.ts Configuration loading and persistence
src/settings.ts Interactive settings UI
src/debug.ts Opt-in response diagnostics
test/ Deterministic unit tests
🔎 Keywords
Pi extension, Pi coding agent, session naming, session rename, automatic naming, TypeScript Pi package.
📄 License
MIT. See LICENSE.