Klein Kit

Resume

Pick up a conversation after your app restarts

Every provider persists sessions natively. Klein Kit exposes the backend's id as session.nativeSessionId — persist it, and resume later even after your process restarts:

import { createAgent, resumeSession } from "@klein-kit/core";

const session = await createAgent({ provider: "codex" });
await session.prompt("start refactoring the auth module");

const id = session.nativeSessionId; // save this
await session.close();

// …hours later, new process:
const restored = await resumeSession({
  provider: "codex",
  sessionId: id!,
  permissionMode: "ask",
});
await restored.prompt("continue where you left off");

ResumeSessionOptions is SessionOptions plus provider and sessionId — you can change model, permission mode, or handlers on resume.

Notes:

  • nativeSessionId is undefined until the backend reports it — it arrives with the session.started event.
  • Resume is native on all five providers (see Providers).
  • Cross-agent continuity is different from resume: no provider can read another's session. For that, Klein Kit carries a task document across handoffs.