docs(coding-agent): document extension resource lifecycle

This commit is contained in:
Armin Ronacher
2026-06-14 02:05:11 +02:00
Unverified
parent c48f656f88
commit 3fcfb7abf7
+7 -1
View File
@@ -216,6 +216,12 @@ export default async function (pi: ExtensionAPI) {
This pattern makes the fetched models available during normal startup and to `pi --list-models`.
### Long-lived resources and shutdown
Extension factories may run in invocations that never start a session. Do not start background resources such as processes, sockets, file watchers, or timers from the factory.
Defer background resource startup until `session_start` or the command/tool/event that needs the resource. Register an idempotent `session_shutdown` handler to close any session-scoped resources you start.
### Extension Styles
**Single file** - simplest, for small extensions:
@@ -471,7 +477,7 @@ pi.on("session_tree", async (event, ctx) => {
#### session_shutdown
Fired before an extension runtime is torn down.
Fired before a started session runtime is torn down. Use this to clean up resources opened from `session_start` or other session-scoped hooks.
```typescript
pi.on("session_shutdown", async (event, ctx) => {