diff --git a/packages/coding-agent/docs/extensions.md b/packages/coding-agent/docs/extensions.md index 076208e9..e47e04e5 100644 --- a/packages/coding-agent/docs/extensions.md +++ b/packages/coding-agent/docs/extensions.md @@ -944,6 +944,38 @@ Options: - `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended - `label`: Label to attach to the branch summary entry (or target entry if not summarizing) +### ctx.switchSession(sessionPath) + +Switch to a different session file: + +```typescript +const result = await ctx.switchSession("/path/to/session.jsonl"); +if (result.cancelled) { + // An extension cancelled the switch via session_before_switch +} +``` + +To discover available sessions, use the static `SessionManager.list()` or `SessionManager.listAll()` methods: + +```typescript +import { SessionManager } from "@mariozechner/pi-coding-agent"; + +pi.registerCommand("switch", { + description: "Switch to another session", + handler: async (args, ctx) => { + const sessions = await SessionManager.list(ctx.cwd); + if (sessions.length === 0) return; + const choice = await ctx.ui.select( + "Pick session:", + sessions.map(s => s.file), + ); + if (choice) { + await ctx.switchSession(choice); + } + }, +}); +``` + ### ctx.reload() Run the same reload flow as `/reload`.