Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ai/claude: add an opt-in stream setting
Add stream to the claude settings. It makes the provider ask for an
event stream and rebuild the message from it, so a gateway that closes
requests with no upstream bytes for a while no longer cuts off long
generations. It is off by default, so existing configurations send the
same requests as before.

Link: #947
Signed-off-by: Shang En Sim <sim@shangen.org>
  • Loading branch information
12458 committed Nov 26, 2026
commit 112791ac58ae076dbd2d17acf96a0effce5e3684
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Settings specific to the Claude API provider (`provider = "claude"`).
| `client_cert` | path | -- | PEM file holding a certificate and its private key, presented as the TLS client identity to endpoints that authenticate callers with mutual TLS. |
| `thinking` | string | -- | Thinking mode, sent as `thinking.type`: `"adaptive"` (Opus 4.6, Sonnet 4.6, and later), or `"disabled"` where the model allows it. |
| `effort` | string | -- | Effort level, sent as `output_config.effort`: `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"`. Which levels a model accepts, and its default, vary by model. |
| `stream` | bool | `false` | Request server-sent events to help keep idle connections open during generation. Sashiko assembles the full message before returning it to the review stage and also accepts a regular JSON reply. |

#### `[ai.claude_cli]`

Expand Down
11 changes: 11 additions & 0 deletions docs/llm-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ base_url = "https://gateway.example.com/v1/messages"
client_cert = "/path/to/cert-and-key.pem"
```

Set `stream = true` to let the endpoint send events during generation.
This can help when a proxy or gateway closes idle requests, sometimes
with an HTTP 524. Sashiko assembles the full message before handing it
to a review stage. If the stream ends before `message_stop`, a retry
starts the request again.

```toml
[ai.claude]
stream = true
```

## Claude Code CLI

Uses a local [Claude Code](https://claude.com/claude-code) installation as
Expand Down
37 changes: 28 additions & 9 deletions src/ai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,18 @@ pub fn create_provider_from_ai(ai: &AiSettings) -> Result<Arc<dyn AiProvider>> {
let thinking = claude.and_then(|c| c.thinking.clone());
let effort = claude.and_then(|c| c.effort.clone());
let client_cert = claude.and_then(|c| c.client_cert.as_deref());
Ok(Arc::new(claude::ClaudeClient::new(
model,
enable_caching,
max_tokens,
base_url,
thinking,
effort,
client_cert,
)?))
Ok(Arc::new(
claude::ClaudeClient::new(
model,
enable_caching,
max_tokens,
base_url,
thinking,
effort,
client_cert,
)?
.with_stream(claude.is_some_and(|c| c.stream)),
))
}
"stdio-claude" => Ok(Arc::new(claude::StdioClaudeClient::new())),
#[cfg(feature = "bedrock")]
Expand Down Expand Up @@ -2039,6 +2042,22 @@ mod tests {
Ok(())
}

/// The Claude stream setting parses, is off when unset, and builds.
#[test]
fn test_claude_stream_setting_is_opt_in() -> Result<()> {
let parsed: crate::settings::ClaudeSettings = toml::from_str("stream = true")?;
assert!(parsed.stream);
let unset: crate::settings::ClaudeSettings = toml::from_str("")?;
assert!(!unset.stream, "streaming is opt-in");

let mut settings = Settings::new().expect("Failed to load settings");
settings.ai.provider = "claude".to_string();
settings.ai.model = "claude-test".to_string();
settings.ai.claude = Some(parsed);
assert!(create_provider(&settings).is_ok());
Ok(())
}

/// The stream setting reaches both transports, and a chat stream
/// refuses extra_body fields that would override its own.
#[test]
Expand Down
6 changes: 6 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ pub struct ClaudeSettings {
pub thinking: Option<String>,
#[serde(default)]
pub effort: Option<String>,
/// Ask for each reply as an event stream and rebuild the message from
/// its events. Bytes then keep flowing while the model works, which
/// keeps gateways that close idle requests from cutting off long
/// generations. Off by default.
#[serde(default)]
pub stream: bool,
}

/// Also the default when the `[ai.claude]` table is absent. Thinking counts
Expand Down