Skip to content

Instantly share code, notes, and snippets.

@fayimora
Created March 19, 2026 01:27
Show Gist options
  • Select an option

  • Save fayimora/71292fb127749589285de3f3fd83bc33 to your computer and use it in GitHub Desktop.

Select an option

Save fayimora/71292fb127749589285de3f3fd83bc33 to your computer and use it in GitHub Desktop.
/**
* oh-pi Auto Session Name Extension
*
* Automatically names sessions based on the first user message.
*/
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
export default function (pi: ExtensionAPI) {
let named = false;
pi.on("session_start", async (_event, ctx) => {
named = !!pi.getSessionName();
});
pi.on("agent_end", async (event) => {
if (named) return;
const userMsg = event.messages.find((m) => m.role === "user");
if (!userMsg) return;
const text = typeof userMsg.content === "string"
? userMsg.content
: userMsg.content.filter((b) => b.type === "text").map((b) => (b as { text: string }).text).join(" ");
if (!text) return;
const name = text.slice(0, 60).replace(/\n/g, " ").trim();
if (name) {
pi.setSessionName(name);
named = true;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment