claude-code-driver / ClaudeSession
Class: ClaudeSession
Defined in: api/claude-session.ts:99
Implements
AsyncDisposable
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
[asyncDispose] | public | () => Promise<void> | - | api/claude-session.ts:105 |
cwd | readonly | string | - | api/claude-session.ts:101 |
debug | readonly | object | - | api/claude-session.ts:104 |
debug.tracePath? | readonly | string | - | api/claude-session.ts:104 |
debug.captureScreen | public | () => Promise<string> | - | api/claude-session.ts:104 |
debug.viewCommand | public | () => string | - | api/claude-session.ts:104 |
exited | readonly | Promise<SessionExitInfo> | Always resolves (D-31). | api/claude-session.ts:103 |
key | readonly | SessionKey | - | api/claude-session.ts:100 |
Accessors
claudeSessionId
Get Signature
get claudeSessionId(): string;Defined in: api/claude-session.ts:205
Returns
string
state
Get Signature
get state(): SessionSnapshot;Defined in: api/claude-session.ts:209
Returns
status
Get Signature
get status(): AgentStatus;Defined in: api/claude-session.ts:213
Returns
Methods
answerQuestion()
answerQuestion(key, answers): Promise<void>;Defined in: api/claude-session.ts:270
Parameters
| Parameter | Type |
|---|---|
key | PermissionKey |
answers | Readonly<Record<string, string>> |
Returns
Promise<void>
approvePlan()
approvePlan(key, o): Promise<void>;Defined in: api/claude-session.ts:274
Parameters
| Parameter | Type |
|---|---|
key | PermissionKey |
o | { approve: boolean; feedback?: string; mode?: "default" | "acceptEdits"; } |
o.approve | boolean |
o.feedback? | string |
o.mode? | "default" | "acceptEdits" |
Returns
Promise<void>
close()
close(opts?): Promise<SessionExitInfo>;Defined in: api/claude-session.ts:484
Idempotent; a kill while a graceful close is still running escalates it.
Parameters
| Parameter | Type |
|---|---|
opts? | { graceMs?: number; mode?: "graceful" | "kill"; waitForBackgroundMs?: number; } |
opts.graceMs? | number |
opts.mode? | "graceful" | "kill" |
opts.waitForBackgroundMs? | number |
Returns
Promise<SessionExitInfo>
command()
command(
name,
args?,
opts?
): Promise<{
output?: string;
}>;Defined in: api/claude-session.ts:251
Parameters
| Parameter | Type |
|---|---|
name | string |
args? | string |
opts? | { unsafe?: boolean; } |
opts.unsafe? | boolean |
Returns
Promise<{ output?: string; }>
events()
events(opts?): AsyncIterableIterator<SessionEvent>;Defined in: api/claude-session.ts:340
Parameters
| Parameter | Type |
|---|---|
opts? | { fromSeq?: number; highWaterMark?: number; types?: readonly ( | "channel" | "security" | "exited" | "text" | "turnStarted" | "compaction" | "warning" | "ready" | "suspended" | "usageLimited" | "authRequired" | "status" | "claudeSessionChanged" | "turnQueued" | "externalTurn" | "textRetracted" | "message" | "toolStarted" | "toolEnded" | "permissionRequested" | "permissionResolved" | "inputRequested" | "subagentStarted" | "subagentEnded" | "modelCall" | "turnEnded" | "authRestored" | "gap" | "resumed")[]; } |
opts.fromSeq? | number |
opts.highWaterMark? | number |
opts.types? | readonly ( | "channel" | "security" | "exited" | "text" | "turnStarted" | "compaction" | "warning" | "ready" | "suspended" | "usageLimited" | "authRequired" | "status" | "claudeSessionChanged" | "turnQueued" | "externalTurn" | "textRetracted" | "message" | "toolStarted" | "toolEnded" | "permissionRequested" | "permissionResolved" | "inputRequested" | "subagentStarted" | "subagentEnded" | "modelCall" | "turnEnded" | "authRestored" | "gap" | "resumed")[] |
Returns
AsyncIterableIterator<SessionEvent>
interrupt()
interrupt(): Promise<{
turnKey?: TurnKey;
}>;Defined in: api/claude-session.ts:261
Returns
Promise<{ turnKey?: TurnKey; }>
on()
on<T>(type, l): Unsubscribe;Defined in: api/claude-session.ts:327
Type Parameters
Parameters
| Parameter | Type |
|---|---|
type | T |
l | (e) => void |
Returns
onAny()
onAny(l): Unsubscribe;Defined in: api/claude-session.ts:335
Parameters
| Parameter | Type |
|---|---|
l | (e) => void |
Returns
respondToPermission()
respondToPermission(key, decision): Promise<void>;Defined in: api/claude-session.ts:266
Parameters
| Parameter | Type |
|---|---|
key | PermissionKey |
decision | PermissionDecision |
Returns
Promise<void>
resume()
resume(): Promise<void>;Defined in: api/claude-session.ts:459
Resume a suspended session now (resolves at ready; no-op when live). Rejects with the start error and stays suspended.
Returns
Promise<void>
send()
send(prompt, opts?): Turn;Defined in: api/claude-session.ts:217
Parameters
| Parameter | Type |
|---|---|
prompt | string |
opts? | { signal?: AbortSignal; whenBusy?: "reject" | "wait"; } |
opts.signal? | AbortSignal |
opts.whenBusy? | "reject" | "wait" |
Returns
setMode()
setMode(mode): Promise<void>;Defined in: api/claude-session.ts:284
Parameters
| Parameter | Type |
|---|---|
mode | PermissionMode |
Returns
Promise<void>
suspend()
suspend(): Promise<void>;Defined in: api/claude-session.ts:448
Stop Claude now and keep the session (ICR 0041). The next send, command, usage or setMode resumes the same conversation. Rejects E_BUSY (details.blocker names the first blocker, e.g. permission; details.blockers lists all) when anything is in progress or waiting for an answer; a suspend never denies or drops a prompt.
Returns
Promise<void>
turn()
turn(key): Turn | undefined;Defined in: api/claude-session.ts:469
Parameters
| Parameter | Type |
|---|---|
key | TurnKey |
Returns
Turn | undefined
turns()
turns(): readonly TurnSnapshot[];Defined in: api/claude-session.ts:473
Returns
readonly TurnSnapshot[]
usage()
usage(opts?): Promise<UsageInfo>;Defined in: api/claude-session.ts:292
Current subscription usage, read from Claude's /usage dialog. Costs no model call; the dialog is dismissed afterwards. Rejects E_ENVIRONMENT (details.reason: 'noMeters') when the dialog shows no usage meters.
Parameters
| Parameter | Type |
|---|---|
opts? | { signal?: AbortSignal; timeoutMs?: number; } |
opts.signal? | AbortSignal |
opts.timeoutMs? | number |
Returns
Promise<UsageInfo>
waitFor()
waitFor(pred, opts?): Promise<SessionSnapshot>;Defined in: api/claude-session.ts:405
Rejects E_TIMEOUT{E_WAIT_TIMEOUT}, E_SESSION_CLOSED/… for kernel failures, the caller's own signal.reason as is when the signal aborts (a DOMException AbortError/TimeoutError, or whatever the host passed to abort(reason)), and the host predicate's own exception as is: neither is a library invariant failure (ICR 0029).
Parameters
| Parameter | Type |
|---|---|
pred | (s) => boolean |
opts? | { signal?: AbortSignal; timeoutMs?: number; } |
opts.signal? | AbortSignal |
opts.timeoutMs? | number |
Returns
Promise<SessionSnapshot>
waitForIdle()
waitForIdle(opts?): Promise<SessionSnapshot>;Defined in: api/claude-session.ts:428
Idle with an empty library queue (a suspended session counts); rejects E_SESSION_EXITED if the session exits first.
Parameters
| Parameter | Type |
|---|---|
opts? | { signal?: AbortSignal; timeoutMs?: number; } |
opts.signal? | AbortSignal |
opts.timeoutMs? | number |
Returns
Promise<SessionSnapshot>
waitForQuiescence()
waitForQuiescence(opts?): Promise<SessionSnapshot>;Defined in: api/claude-session.ts:436
Idle, nothing queued, no background agents or tasks (P-LIFE-21; a suspended session counts).
Parameters
| Parameter | Type |
|---|---|
opts? | { signal?: AbortSignal; timeoutMs?: number; } |
opts.signal? | AbortSignal |
opts.timeoutMs? | number |
Returns
Promise<SessionSnapshot>
wakeNow()
wakeNow(): Promise<void>;Defined in: api/claude-session.ts:323
Returns
Promise<void>
closeAll()
static closeAll(): Promise<void>;Defined in: api/claude-session.ts:201
Closes every live session of this process (every package copy).
Returns
Promise<void>
start()
static start(opts): Promise<ClaudeSession>;Defined in: api/claude-session.ts:174
Resolves at ready; rejects ClaudeSessionError (E_CONFIG for invalid options, E_SESSION_CLOSED{aborted} on abort, startup codes otherwise).
Parameters
| Parameter | Type |
|---|---|
opts | ClaudeSessionOptions |
Returns
Promise<ClaudeSession>