docs: add switchSession to ExtensionCommandContext in extensions.md

fixes #2735
This commit is contained in:
Mario Zechner
2026-04-01 23:51:22 +02:00
parent e2f29b0523
commit d98b563165

View File

@@ -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`.