Get information about the authenticated account.
Account information including email, organization, and subscription type
Merge the provided settings into the flag settings layer, dynamically
updating the active configuration. Top-level keys are shallow-merged
across successive calls — a second call with {permissions: {...}}
replaces the entire permissions object from a prior call. The resulting
flag settings are then deep-merged with file-based settings at read time.
Equivalent to passing an object to the settings option of query(),
but applies mid-session. Only available in streaming input mode.
A partial settings object to merge into the flag settings
Close the query and terminate the underlying process. This forcefully ends the query, cleaning up all resources including pending requests, MCP transports, and the CLI subprocess.
Use this when you need to abort a query that is still running. After calling close(), no further messages will be received.
Get a breakdown of current context window usage by category (system prompt, tools, messages, MCP tools, memory files, etc.).
Context usage breakdown including token counts per category and total usage
Get the full initialization result, including supported commands, models, account info, and output style configuration.
The complete initialization response
Interrupt the current query execution. The query will stop processing and return control to the caller.
Get the current status of all configured MCP servers.
Array of MCP server statuses (connected, failed, needs-auth, pending)
Reconnect an MCP server by name. Throws on failure.
The name of the MCP server to reconnect
Reload plugins from disk and return the refreshed commands, agents, plugins, and MCP server status.
The refreshed session components after plugin reload
Rewind tracked files to their state at a specific user message.
Requires file checkpointing to be enabled via the enableFileCheckpointing option.
UUID of the user message to rewind to
Optionaloptions: { dryRun?: boolean }Options object with optional dryRun boolean to preview changes without modifying files
Object with canRewind boolean, optional error message, and file change statistics
Seed the CLI's readFileState cache with a path+mtime entry. Use when the client observed a Read that has since been removed from context (e.g. by snip), so a subsequent Edit won't fail "file not read yet". If the file changed on disk since the given mtime, the seed is skipped and Edit will correctly require a fresh Read.
Path to the file that was previously Read
File mtime (floored ms) at the time of the observed Read
Set the maximum number of thinking tokens the model is allowed to use when generating its response. This can be used to limit the amount of tokens the model uses for its response, which can help control cost and latency.
Use null to clear any previously set limit and allow the model to
use the default maximum thinking tokens.
Maximum tokens for thinking, or null to clear the limit
Dynamically set the MCP servers for this session. This replaces the current set of dynamically-added MCP servers with the provided set. Servers that are removed will be disconnected, and new servers will be connected.
Supports both process-based servers (stdio, sse, http) and SDK servers (in-process). SDK servers are handled locally in the SDK process, while process-based servers are managed by the CLI subprocess.
Note: This only affects servers added dynamically via this method or the SDK. Servers configured via settings files are not affected.
Record of server name to configuration. Pass an empty object to remove all dynamic servers.
Information about which servers were added, removed, and any connection errors
Change the model used for subsequent responses. Only available in streaming input mode.
Optionalmodel: stringThe model identifier to use, or undefined to use the default
Change the permission mode for the current session. Only available in streaming input mode.
The new permission mode to set
Stop a running task. A task_notification with status 'stopped' will be emitted.
The task ID from task_notification events
Stream input messages to the query. Used internally for multi-turn conversations.
Async iterable of user messages to send
Get the list of available subagents for the current session.
Array of available agents with their names, descriptions, and configuration
Get the list of available skills for the current session.
Array of available skills with their names and descriptions
Get the list of available models.
Array of model information including display names and descriptions
Enable or disable an MCP server by name. Throws on failure.
The name of the MCP server to toggle
Whether the server should be enabled
Query interface with methods for controlling query execution. Extends AsyncGenerator and has methods, so not serializable.