Klein Kit

Quickstart

Detect providers and run your first turn

Install

pnpm add @klein-kit/core

Requires Node 20+, and at least one supported agent CLI installed and logged in (Codex, Claude Code, OpenCode, or Pi). macOS, Linux, and Windows are supported.

Detect, prompt, stream

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

// What's installed and logged in on this machine?
console.log(await detectProviders());

const session = await createAgent({
  provider: "codex",
  permissionMode: "ask",
  onPermissionRequest: async (req) => {
    // Your UI decides. req carries the native payload on req.raw.
    return { behavior: req.kind === "shell" ? "deny" : "allow" };
  },
});

const turn = session.prompt("Fix the failing test in src/auth.ts");
for await (const event of turn) {
  switch (event.type) {
    case "message.delta":   process.stdout.write(event.text); break;
    case "plan.updated":    renderPlan(event.plan); break;
    case "tool.started":    console.log(`→ ${event.tool.name}`); break;
    case "usage.updated":   showContextMeter(event.usage); break;
  }
}
const result = await turn; // { text, usage, filesChanged, stopReason }

// Resume later, even after your app restarts:
const id = session.nativeSessionId;

A Turn is both an async iterable of events and a promise of the final result — iterate it for streaming UI, await it for the outcome.

Next steps

On this page