Skip to content

Commit 75f18f6

Browse files
github-actions[bot]claude-yolo[bot]
authored andcommitted
docs: Claude Code v2.1.310 - mods can intercept settings reads, 3 new Agent SDK query methods, Desktop SSH via OpenSSH on Windows
Co-Authored-By: claude-yolo[bot] <claude-yolo@lroole.com>
1 parent 7dae239 commit 75f18f6

71 files changed

Lines changed: 685 additions & 328 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎content/.metadata.json‎

Lines changed: 139 additions & 141 deletions
Large diffs are not rendered by default.

‎content/en/docs/claude-code/agent-sdk/hooks.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,9 @@ Claude Code runs each callback with a timeout, which you set in seconds with the
771771

772772
When a callback exceeds its timeout, Claude Code cancels it and discards its output, and the session continues rather than hanging. What happens next depends on the event:
773773

774-
* `PreToolUse`: Claude Code blocks the tool call. In its place, Claude receives a tool result saying the hook didn't respond before its timeout, and the turn continues. Before v2.1.210, Claude Code reported the timeout to Claude as a user rejection, which made unattended sessions stop and wait for input.
774+
* `PreToolUse`: Claude Code blocks the tool call. If every other hook returned nothing or only an `allow` decision, the tool result tells Claude the hook didn't respond before its timeout, and the turn continues. If another of your hooks already denied the call, its deny still reaches Claude: the tool result includes that hook's reason, and the timeout text can follow it.
775+
776+
Before v2.1.210, Claude Code reported the timeout to Claude as a user rejection, which made unattended sessions stop and wait for input.
775777
* `PostToolUse` and `PostToolUseFailure`: Claude Code keeps the tool result and the turn continues.
776778
* `UserPromptSubmit` and [`UserPromptExpansion`](https://code.claude.com/docs/en/hooks#userpromptexpansion): Claude Code blocks the prompt with a message naming the hook and the timeout, and the session continues. Before v2.1.208, Claude Code ended the query with `error_during_execution` when a callback on these events timed out.
777779
* `Stop` and `SubagentStop`: the timed-out callback counts as returning no decision. The agent or subagent stops as if that callback had allowed it, and a decision from your other hooks on the event still applies. Before Claude Code v2.1.273, a timed-out `Stop` or `SubagentStop` callback counted as a failed hook run, and Claude Code discarded the decisions of your other hooks on the event.

‎content/en/docs/claude-code/agent-sdk/typescript.md‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,13 @@ function getSessionMessages(
309309
| `options.dir` | `string` | `undefined` | Project directory to find the session in. When omitted, searches all projects |
310310
| `options.limit` | `number` | `undefined` | Maximum number of messages to return |
311311
| `options.offset` | `number` | `undefined` | Number of messages to skip from the start |
312+
| `options.includeSystemMessages` | `boolean` | `false` | When `true`, also return system messages such as compact boundaries alongside user and assistant messages |
312313

313314
#### Return type: `SessionMessage`
314315

315316
| Property | Type | Description |
316317
| :- | :- | :- |
317-
| `type` | `"user" \| "assistant"` | Message role |
318+
| `type` | `"user" \| "assistant" \| "system"` | Message role. `"system"` appears only when `options.includeSystemMessages` is `true` |
318319
| `uuid` | `string` | Unique message identifier |
319320
| `session_id` | `string` | Session this message belongs to |
320321
| `message` | `unknown` | Raw message payload from the transcript |
@@ -632,13 +633,19 @@ interface Query extends AsyncGenerator<SDKMessage, void> {
632633
}): Promise<SDKControlReloadPluginsResponse>;
633634
reloadSkills(): Promise<SDKControlReloadSkillsResponse>;
634635
reloadOutputStyles(): Promise<SDKControlReloadOutputStylesResponse>;
636+
seedReadState(path: string, mtime: number): Promise<void>;
635637
accountInfo(): Promise<AccountInfo>;
636638
reconnectMcpServer(serverName: string): Promise<void>;
637639
toggleMcpServer(serverName: string, enabled: boolean): Promise<void>;
638640
setMcpServers(servers: Record<string, McpServerConfig>): Promise<McpSetServersResult>;
641+
setMcpPermissionModeOverride(
642+
serverName: string,
643+
mode: 'default' | 'auto' | null
644+
): Promise<{ warning?: string }>;
639645
readMcpResource(serverName: string, uri: string): Promise<SDKControlMcpReadResourceResponse>;
640646
streamInput(stream: AsyncIterable<SDKUserMessage>): Promise<void>;
641647
stopTask(taskId: string): Promise<void>;
648+
backgroundTasks(toolUseId?: string): Promise<boolean>;
642649
close(): void;
643650
}
644651
```
@@ -665,15 +672,55 @@ interface Query extends AsyncGenerator<SDKMessage, void> {
665672
| `reloadPlugins(options?)` | Reloads plugins from disk, so plugins you install or edit mid-session reach the running session. Resolves with an [`SDKControlReloadPluginsResponse`](#sdkcontrolreloadpluginsresponse) listing the session's commands, subagents, plugins, and MCP server status. Requires Agent SDK v0.2.85 or later. The [`holdOnCacheImpact` option](#sdkcontrolreloadpluginsresponse) requires Agent SDK v0.3.268 or later |
666673
| `reloadSkills()` | Reloads skills from disk, so skills you add or edit mid-session become available to the running session. Resolves with an [`SDKControlReloadSkillsResponse`](#sdkcontrolreloadskillsresponse) listing the skills available after the reload. Requires Agent SDK v0.3.163 or later |
667674
| `reloadOutputStyles()` | Re-reads [output styles](https://code.claude.com/docs/en/output-styles.md) from disk, so a style file you add or edit mid-session becomes available to the running session. Resolves with an [`SDKControlReloadOutputStylesResponse`](#sdkcontrolreloadoutputstylesresponse) listing the style names available after the reload. Requires Agent SDK v0.3.261 or later |
675+
| `seedReadState(path, mtime)` | Marks a file as already read so a later Edit doesn't fail with `File has not been read yet`. See [`seedReadState()`](#seedreadstate). Requires TypeScript SDK v0.2.83 or later |
668676
| `accountInfo()` | Returns account information |
669677
| `reconnectMcpServer(serverName)` | Reconnect an MCP server by name. If the name also matches an entry in a settings file such as `.mcp.json` or `~/.claude.json`, Claude Code reconnects the server you configured through [`mcpServers`](#options) or `setMcpServers()`, not the settings-file entry. That resolution order requires Claude Code v2.1.257 or later |
670678
| `toggleMcpServer(serverName, enabled)` | Enable or disable an MCP server by name, with the same name resolution as `reconnectMcpServer()`. Disabling a server disconnects it and removes its tools. See [`toggleMcpServer()`](#togglemcpserver) for the Claude Code version this needs for each kind of server |
671679
| `setMcpServers(servers)` | Replace the MCP servers this method manages: servers added through it and [in-process SDK servers](#createsdkmcpserver). Resolves with an [`McpSetServersResult`](#mcpsetserversresult) naming which servers were added and removed, and any errors; that section says which other servers stay connected |
680+
| `setMcpPermissionModeOverride(serverName, mode)` | Overrides the permission mode for one MCP server's tools with a stricter mode than the session's, or clears the override with `null`. Only available in streaming input mode. See [`setMcpPermissionModeOverride()`](#setmcppermissionmodeoverride). Requires TypeScript SDK v0.3.187 or later |
672681
| `readMcpResource(serverName, uri)` | *Alpha.* Reads one MCP Apps `ui://` resource from a connected MCP server so your application can render a tool's widget. Resolves with an [`SDKControlMcpReadResourceResponse`](#sdkcontrolmcpreadresourceresponse). Requires TypeScript Agent SDK v0.3.280 or later |
673682
| `streamInput(stream)` | Stream input messages to the query for multi-turn conversations |
674683
| `stopTask(taskId)` | Stop a running background task by ID |
684+
| `backgroundTasks(toolUseId?)` | Moves the running Bash commands and subagents that the turn is waiting on to the background, the same as pressing Ctrl+B in the interactive terminal. See [`backgroundTasks()`](#backgroundtasks). Requires TypeScript SDK v0.2.139 or later |
675685
| `close()` | Close the query and terminate the underlying process. Forcefully ends the query and cleans up all resources |
676686

687+
#### `setMcpPermissionModeOverride()`
688+
689+
Overrides the permission mode for one MCP server's tools with a stricter mode than the session's, or clears the override with `null`. Use it when a session runs in a mode that skips per-action prompts but one server's tools should still be reviewed. Requires TypeScript SDK v0.3.187 or later.
690+
691+
Pass one of three values as `mode`:
692+
693+
* `'default'`: Claude Code evaluates that server's tool calls as [Manual mode](https://code.claude.com/docs/en/permission-modes.md#available-modes) does.
694+
* `'auto'`: Claude Code routes that server's tool calls through the [auto mode](https://code.claude.com/docs/en/permission-modes.md#eliminate-prompts-with-auto-mode) classifier. Claude Code rejects this value when the classifier isn't available to the session.
695+
* `null`: clears the override.
696+
697+
The override only takes effect while the session is in a mode that skips per-action prompts: `bypassPermissions` or `auto`. In any other session mode Claude Code ignores the override, so it can never widen what the session allows.
698+
699+
The promise resolves with `{ warning }` when no server by that name is known yet. Claude Code stores the override anyway and applies it once a server with that exact name connects, so the warning is a typo check, not a failure.
700+
701+
Only available in streaming input mode, the same constraint as `setModel()` and `setPermissionMode()`.
702+
703+
#### `seedReadState()`
704+
705+
Marks a file as already read so a later Edit doesn't fail with `File has not been read yet`. Use it when your application has dropped an earlier `Read` result from the conversation context and Claude will edit that file next. Requires TypeScript SDK v0.2.83 or later.
706+
707+
Pass `mtime` as the file's modification time at the moment of that earlier read, in whole milliseconds since the epoch, for example `Math.floor(stat.mtimeMs)`. If the file on disk changed after that time, Claude Code skips the mark.
708+
709+
The promise resolves whether or not the file was marked, so a resolved promise doesn't tell you which happened.
710+
711+
#### `backgroundTasks()`
712+
713+
Moves the running Bash commands and subagents that the turn is waiting on to the background, the same as pressing Ctrl+B in the interactive terminal. Pass the `toolUseId` of a tool call to background only the Bash command or subagent that call started, or omit it to background every foreground task. Requires TypeScript SDK v0.2.139 or later.
714+
715+
Each backgrounded tool call returns to Claude immediately with a running-in-the-background result, the turn continues, and Claude Code emits an [`SDKTaskNotificationMessage`](#sdktasknotificationmessage) when the task finishes.
716+
717+
In a session where background tasks are enabled, the promise resolves to a boolean:
718+
719+
* **`true`**: a task was backgrounded, or you omitted `toolUseId`.
720+
* **`false`**: the `toolUseId` you passed matched no foreground task.
721+
722+
If background tasks are disabled for the session, such as with [`CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`](https://code.claude.com/docs/en/env-vars), the promise rejects instead and nothing is backgrounded.
723+
677724
#### `applyFlagSettings()`
678725

679726
Changes [settings](https://code.claude.com/docs/en/settings.md) on a running session without restarting the query. Use it when a setting that has no dedicated setter needs to change mid-session, such as tightening `permissions` after the agent reads untrusted input. `setModel()` and `setPermissionMode()` are dedicated setters for those two keys; `applyFlagSettings()` is the general form that accepts any subset of the settings keys, and passing `model` here behaves the same as `setModel()`.
@@ -1472,11 +1519,20 @@ type SDKMessage =
14721519
| SDKPermissionDeniedMessage
14731520
| SDKPromptSuggestionMessage
14741521
| SDKAPIRetryMessage
1522+
| SDKControlRequestProgressMessage
1523+
| SDKModelRefusalFallbackMessage
1524+
| SDKModelRefusalNoFallbackMessage
14751525
| SDKMirrorErrorMessage
14761526
| SDKInformationalMessage
14771527
| SDKConversationResetMessage;
14781528
```
14791529

1530+
Three messages in this union report control-request progress and model refusals. Each has `type: "system"`, so tell them apart by the `subtype` listed with each one:
1531+
1532+
* `SDKControlRequestProgressMessage`, `subtype: "control_request_progress"`: reports progress on a long-running control request that your client sent. `request_id` matches the message to that request, and `status` is `"started"` or `"api_retry"`. Requires Agent SDK v0.3.203 or later.
1533+
* `SDKModelRefusalFallbackMessage`, `subtype: "model_refusal_fallback"`: emitted when the model ends the stream with a refusal and the turn is retried on a fallback model. Carries `original_model` and `fallback_model`. Requires Agent SDK v0.3.170 or later.
1534+
* `SDKModelRefusalNoFallbackMessage`, `subtype: "model_refusal_no_fallback"`: emitted when the model ends the stream with a refusal and no retry runs, for example because no fallback model is configured. Carries `original_model`. Requires Agent SDK v0.3.193 or later.
1535+
14801536
### `SDKAssistantMessage`
14811537

14821538
Assistant response message.
@@ -1636,6 +1692,7 @@ type SDKResultMessage =
16361692
stop_reason: string | null;
16371693
ttft_ms?: number;
16381694
ttft_stream_ms?: number;
1695+
time_to_request_ms?: number;
16391696
user_message_uuid?: string;
16401697
user_message_uuids?: string[];
16411698
resume_reason?: string;
@@ -1701,6 +1758,7 @@ Several fields on the result carry diagnostic detail beyond `subtype`:
17011758
* `api_error_status`: the HTTP status code of the API error that terminated the conversation. Absent or `null` when the turn ended without an API error.
17021759
* `ttft_ms`: time to first token in milliseconds, measured when the first complete assistant message arrives. Present on the success arm only.
17031760
* `ttft_stream_ms`: time in milliseconds until the first `message_start` stream event, when the response stream opens. Lower than `ttft_ms`; the gap between the two is time spent streaming the first message. Present on the success arm only.
1761+
* `time_to_request_ms`: time in milliseconds from the start of the turn until Claude Code sends the API request. Present on the success arm only. Requires Claude Code v2.1.162 or later.
17041762
* `user_message_uuid`: the `uuid` of the message you sent that this turn answered. See [`user_message_uuid`](#user_message_uuid) for which results carry it.
17051763
* `user_message_uuids`: the `uuid`s of every message you sent that Claude Code answered in this turn. See [`user_message_uuids`](#user_message_uuids).
17061764
* `resume_reason`: why this turn continues one that a restart interrupted. Present on both arms. See [`resume_reason`](#resume_reason).

0 commit comments

Comments
 (0)