Example
Constructors
Constructor
Parameters
ctx
SessionContext
Returns
Session
Properties
directory
id
workspaceId?
Accessors
usage
Get Signature
stream() / send() / command() consume events and reconciles with
each turn’s authoritative result (which includes subagent child-session
cost). Attached/resumed handles start at zero. Returns a defensive
snapshot.
Returns
SessionUsage
Methods
abort()
Returns
Promise<void>
Completion of the abort request.
Throws
Transport errors.Example
checkpoint()
Parameters
label?
string
Optional human-readable label.
Returns
Promise<CheckpointHandle>
A session-owned checkpoint handle.
Throws
Snapshot or transport errors.Example
close()
sessions.resume(id).
Bounded by construction, because close() is what you call when you want
to stop waiting: a consumer-owned generator’s finally gets a short grace
period, and an abandoned turn’s abort request is awaited for at most about
a second so an unreachable server cannot wedge teardown. Against a
responsive server it settles in well under 100 ms.
Idempotent: concurrent and repeated calls share one teardown.
Returns
Promise<void>
A promise that settles once every owned resource is handled.
Throws
When one or more teardown stages fail; several are combined in anAggregateError.
Example
command()
Parameters
name
string
args?
string = ""
options?
Command name, arguments and optional execution overrides.agent?
string
model?
ModelId
variant?
string
Returns
Promise<ResultMessage>
The terminal command result.
Throws
If the command is unavailable or another query is active.Example
compact()
Parameters
options?
Optional model and additional instructions for the summary.customInstructions?
string
model?
ModelId
Returns
Promise<CompactResult>
Compaction identity, preserved messages, token count, and summary text.
getAppliedSettings()
Returns
Promise<AppliedSettings>
A normalized settings snapshot without callback implementations.
Throws
Transport errors.Example
getTodos()
Returns
Promise<Todo[]>
Todo entries in runtime order.
Throws
Transport errors.Example
interrupt()
Returns
Promise<void>
Completion of the abort request.
Throws
Transport errors.Example
listCheckpoints()
Returns
Promise<CheckpointHandle[]>
Persisted checkpoint metadata.
Throws
Transport errors.Example
messages()
Returns
Promise<AgentMessage[]>
Stored transcript messages, including supported tool and attachment parts.
Throws
Transport errors.Example
rename()
Parameters
title
string
New title.
Returns
Promise<void>
Completion after metadata is updated.
Throws
Transport errors.Example
rewind()
Parameters
checkpointId
string
Checkpoint owned by this session.
Returns
Promise<RewindResult>
The affected files and checkpoint identity.
Throws
Invalid checkpoint, restore or transport errors.Example
send()
Parameters
prompt
PromptInput
Text, typed turn, or asynchronous turns.
Returns
Promise<ResultMessage>
The completed result; inspect subtype before using output.
Throws
If closed, another query is active, or transport fails.Example
setAgents()
Parameters
agents
Record<string, AgentDefinition>
Every agent definition that should remain available.
Returns
Promise<void>
Completion after the replacement is accepted.
Throws
Invalid definitions or transport errors.Example
setModel()
Parameters
model
ModelId
Provider/model identifier.
Returns
Promise<void>
Completion after runtime configuration is updated.
Throws
Invalid model identifiers or transport errors.Example
setPermissionMode()
Parameters
_mode
PermissionMode
New runtime permission mode.
Returns
Promise<void>
Completion after the runtime accepts the policy.
Throws
Invalid mode or transport errors.Example
stream()
Parameters
prompt
PromptInput
Text, typed turn, or asynchronous turns.
options?
StreamOptions
Partial-message and cancellation settings.
Returns
AsyncGenerator<AgentMessage, ResultMessage>
An async generator of messages with a terminal return value.
Throws
Closed/conflicting session or transport failures.Example
tag()
Parameters
tag
string
Tag text, trimmed by the SDK.
Returns
Promise<void>
Completion after tags are updated.
Throws
Transport errors.Example
todos()
Parameters
options?
Optional abort signal.signal?
AbortSignal
Returns
AsyncGenerator<Todo[]>
An async generator of todo lists.
Throws
Transport errors.Example
untag()
Parameters
tag
string
Tag to remove.
Returns
Promise<void>
Completion after tags are updated.