Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): honor the extended-thinking toggle in the Claude Agent provider

Elian Doranf29c1b774bd8
diff --git a/apps/server/src/services/llm/providers/claude_agent.spec.ts b/apps/server/src/services/llm/providers/claude_agent.spec.ts
index b3788444c9..814845b5c8 100644
--- a/apps/server/src/services/llm/providers/claude_agent.spec.ts
+++ b/apps/server/src/services/llm/providers/claude_agent.spec.ts
@@ -337,6 +337,22 @@ describe("ClaudeAgentProvider.chatChunks", () => {
expect(options.settingSources).toEqual([]);
});
+ it("enables adaptive extended thinking when the turn requests it", async () => {
+ scriptAgent([successResult()]);
+ const provider = new ClaudeAgentProvider();
+ await collect(provider.chatChunks([{ role: "user", content: "hi" }], { enableExtendedThinking: true }));
+
+ expect(queryMock.mock.calls[0][0].options.thinking).toEqual({ type: "adaptive", display: "summarized" });
+ });
+
+ it("disables extended thinking by default", async () => {
+ scriptAgent([successResult()]);
+ const provider = new ClaudeAgentProvider();
+ await collect(provider.chatChunks([{ role: "user", content: "hi" }], {}));
+
+ expect(queryMock.mock.calls[0][0].options.thinking).toEqual({ type: "disabled" });
+ });
+
it("drives the user's resolved claude binary (bring-your-own-binary)", async () => {
resolveClaudeBinaryMock.mockReturnValueOnce("/opt/homebrew/bin/claude");
scriptAgent([successResult()]);
diff --git a/apps/server/src/services/llm/providers/claude_agent.ts b/apps/server/src/services/llm/providers/claude_agent.ts
index 5b47615f1d..ef141233cb 100644
--- a/apps/server/src/services/llm/providers/claude_agent.ts
+++ b/apps/server/src/services/llm/providers/claude_agent.ts
@@ -367,8 +367,8 @@ export class ClaudeAgentProvider implements LlmProvider {
return systemPrompt;
}
- /** Options shared by every agent invocation, independent of the turn. */
- private buildBaseOptions(config: Pick<LlmProviderConfig, "enableNoteTools" | "enableWebSearch">): AgentOptions {
+ /** Options shared by every agent invocation. */
+ private buildBaseOptions(config: Pick<LlmProviderConfig, "enableNoteTools" | "enableWebSearch" | "enableExtendedThinking">): AgentOptions {
// Built-in Claude Code tools (file access, bash, …) stay disabled — the
// agent runs on the server host and must only ever touch notes. Web
// search is the one opt-in exception.
@@ -383,7 +383,14 @@ export class ClaudeAgentProvider implements LlmProvider {
tools: builtinTools,
settingSources: [],
strictMcpConfig: true,
- permissionMode: "dontAsk"
+ permissionMode: "dontAsk",
+ // Extended thinking: `adaptive` lets these (modern) models decide how
+ // much to think and stream summarized reasoning, mirroring the metered
+ // Anthropic provider. Adaptive is the SDK's default for supporting
+ // models, so the toggle's meaningful effect is the disabled path.
+ thinking: config.enableExtendedThinking
+ ? { type: "adaptive", display: "summarized" }
+ : { type: "disabled" }
};
if (areNoteToolsAvailable(config)) {