@moxxy/plugin-provider-claude-code 0.41.2 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,11 @@
1
1
  import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process';
2
2
  import { EventEmitter } from 'node:events';
3
3
  import { PassThrough } from 'node:stream';
4
- import { chmod, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises';
4
+ import { chmod, mkdtemp, readFile, realpath, writeFile } from 'node:fs/promises';
5
5
  import { tmpdir } from 'node:os';
6
6
  import { join } from 'node:path';
7
7
  import { afterEach, describe, expect, it } from 'vitest';
8
+ import { posixShell } from '@moxxy/vitest-preset/platform';
8
9
  import { z } from 'zod';
9
10
  import type { ProviderEvent, ProviderRequest } from '@moxxy/sdk';
10
11
  import {
@@ -14,6 +15,7 @@ import {
14
15
  createClaudeCodeClient,
15
16
  __setClaudeCommandRunner,
16
17
  } from './index.js';
18
+ import { removeDir } from '@moxxy/vitest-preset/fs';
17
19
 
18
20
  class ControlledProviderChild extends EventEmitter {
19
21
  readonly stdin = new PassThrough();
@@ -37,7 +39,7 @@ class ControlledProviderChild extends EventEmitter {
37
39
 
38
40
  const tempDirs: string[] = [];
39
41
  afterEach(async () => {
40
- await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
42
+ await Promise.all(tempDirs.splice(0).map((dir) => removeDir(dir)));
41
43
  });
42
44
 
43
45
  describe('claude-code provider definition', () => {
@@ -54,18 +56,18 @@ describe('claude-code provider definition', () => {
54
56
  it('registers the exact Claude Code catalog and its native web-search capability', () => {
55
57
  expect(claudeCodeProviderDef.name).toBe('claude-code');
56
58
  expect(claudeCodeProviderDef.auth?.kind).toBe('oauth');
57
- expect(CLAUDE_CODE_DEFAULT_MODEL).toBe('claude-sonnet-5');
59
+ expect(CLAUDE_CODE_DEFAULT_MODEL).toBe('claude-sonnet-5-5');
58
60
  expect(claudeCodeProviderDef.models).toBe(claudeCodeModels);
59
- expect(claudeCodeProviderDef.models.map((model) => model.id)).toEqual([
60
- 'claude-fable-5',
61
- 'claude-opus-5',
62
- 'claude-sonnet-5',
63
- 'claude-haiku-4-5',
61
+ expect(claudeCodeProviderDef.models.map((model) => [model.id, model.contextWindow, model.maxOutputTokens])).toEqual([
62
+ ['claude-fable-5-1', 1_000_000, 128_000],
63
+ ['claude-opus-5-5', 1_000_000, 128_000],
64
+ ['claude-sonnet-5-5', 1_000_000, 128_000],
65
+ ['claude-haiku-4-5', 200_000, 64_000],
64
66
  ]);
65
67
  for (const model of claudeCodeProviderDef.models) {
66
68
  expect(model).toMatchObject({
67
69
  supportsStreaming: true,
68
- supportsTools: false,
70
+ supportsTools: true,
69
71
  supportsImages: false,
70
72
  supportsDocuments: false,
71
73
  supportsAudio: false,
@@ -75,7 +77,7 @@ describe('claude-code provider definition', () => {
75
77
  }
76
78
  });
77
79
 
78
- it('streams text through a fake Claude executable with structured non-interactive arguments', async () => {
80
+ it.skipIf(!posixShell)('streams text through a fake Claude executable with structured non-interactive arguments', async () => {
79
81
  const dir = await makeFakeClaude([
80
82
  { type: 'system', subtype: 'init' },
81
83
  { type: 'rate_limit_event', rate_limit_info: { status: 'allowed' } },
@@ -92,7 +94,7 @@ describe('claude-code provider definition', () => {
92
94
  const events = await collect(client.stream(textRequest()));
93
95
 
94
96
  expect(events).toEqual([
95
- { type: 'message_start', model: 'claude-sonnet-5' },
97
+ { type: 'message_start', model: 'claude-sonnet-5-5' },
96
98
  { type: 'text_delta', delta: 'Hello ' },
97
99
  { type: 'text_delta', delta: 'world' },
98
100
  { type: 'message_end', stopReason: 'end_turn', usage: { inputTokens: 8, outputTokens: 2 } },
@@ -110,7 +112,7 @@ describe('claude-code provider definition', () => {
110
112
  expect(input).not.toContain('oauth-secret');
111
113
  });
112
114
 
113
- it('can disable native WebSearch without enabling any other Claude tools', async () => {
115
+ it.skipIf(!posixShell)('can disable native WebSearch without enabling any other Claude tools', async () => {
114
116
  const dir = await makeFakeClaude([
115
117
  { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
116
118
  ]);
@@ -125,7 +127,7 @@ describe('claude-code provider definition', () => {
125
127
  expect(args).not.toContain('--allowedTools');
126
128
  });
127
129
 
128
- it('consumes streamed thinking blocks without exposing their deltas', async () => {
130
+ it.skipIf(!posixShell)('consumes streamed thinking blocks without exposing their deltas', async () => {
129
131
  const dir = await makeFakeClaude([
130
132
  { type: 'stream_event', event: { type: 'message_start', message: {} } },
131
133
  { type: 'stream_event', event: { type: 'content_block_start', content_block: { type: 'thinking', thinking: '' } } },
@@ -140,7 +142,7 @@ describe('claude-code provider definition', () => {
140
142
  const events = await collect(createClaudeCodeClient({ executable: join(dir, 'claude') }).stream(textRequest()));
141
143
 
142
144
  expect(events).toEqual([
143
- { type: 'message_start', model: 'claude-sonnet-5' },
145
+ { type: 'message_start', model: 'claude-sonnet-5-5' },
144
146
  { type: 'text_delta', delta: 'Visible answer' },
145
147
  { type: 'message_end', stopReason: 'end_turn', usage: { inputTokens: 3, outputTokens: 2 } },
146
148
  ]);
@@ -148,7 +150,7 @@ describe('claude-code provider definition', () => {
148
150
  expect(JSON.stringify(events)).not.toContain('private-signature');
149
151
  });
150
152
 
151
- it('accepts complete assistant records containing thinking blocks without exposing them', async () => {
153
+ it.skipIf(!posixShell)('accepts complete assistant records containing thinking blocks without exposing them', async () => {
152
154
  const dir = await makeFakeClaude([
153
155
  { type: 'assistant', message: { content: [
154
156
  { type: 'thinking', thinking: 'private chain of thought', signature: 'private-signature' },
@@ -159,14 +161,14 @@ describe('claude-code provider definition', () => {
159
161
  const events = await collect(createClaudeCodeClient({ executable: join(dir, 'claude') }).stream(textRequest()));
160
162
 
161
163
  expect(events).toEqual([
162
- { type: 'message_start', model: 'claude-sonnet-5' },
164
+ { type: 'message_start', model: 'claude-sonnet-5-5' },
163
165
  { type: 'message_end', stopReason: 'end_turn', usage: { inputTokens: 3, outputTokens: 2 } },
164
166
  ]);
165
167
  expect(JSON.stringify(events)).not.toContain('private chain of thought');
166
168
  expect(JSON.stringify(events)).not.toContain('private-signature');
167
169
  });
168
170
 
169
- it('reconstructs two turns for each stateless CLI invocation without a session id', async () => {
171
+ it.skipIf(!posixShell)('reconstructs two turns for each stateless CLI invocation without a session id', async () => {
170
172
  const dir = await makeFakeClaude([
171
173
  { type: 'stream_event', event: { type: 'content_block_start', content_block: { type: 'text', text: '' } } },
172
174
  { type: 'stream_event', event: { type: 'content_block_delta', delta: { type: 'text_delta', text: 'first answer' } } },
@@ -196,7 +198,7 @@ describe('claude-code provider definition', () => {
196
198
  expect(args.some((arg) => /session|resume/i.test(arg))).toBe(false);
197
199
  });
198
200
 
199
- it('projects prior moxxy tools and unsafe content deterministically as inert text', async () => {
201
+ it.skipIf(!posixShell)('projects prior moxxy tools and unsafe content deterministically as inert text', async () => {
200
202
  const dir = await makeFakeClaude([
201
203
  { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
202
204
  ]);
@@ -236,7 +238,7 @@ describe('claude-code provider definition', () => {
236
238
  expect(first).not.toContain(rawBase64);
237
239
  });
238
240
 
239
- it('runs native tools in the configured workspace without emitting dispatcher tool events', async () => {
241
+ it.skipIf(!posixShell)('runs native tools in the configured workspace without emitting dispatcher tool events', async () => {
240
242
  const workspace = await mkdtemp(join(tmpdir(), 'moxxy-claude-workspace-'));
241
243
  tempDirs.push(workspace);
242
244
  const dir = await makeFakeClaude([
@@ -271,7 +273,7 @@ describe('claude-code provider definition', () => {
271
273
  expect(args).not.toEqual(expect.arrayContaining(['--tools', '']));
272
274
  });
273
275
 
274
- it('leaves the safe permission default to Claude and uses a valid no-tools invocation for an empty native allow-list', async () => {
276
+ it.skipIf(!posixShell)('leaves the safe permission default to Claude and uses a valid no-tools invocation for an empty native allow-list', async () => {
275
277
  const dir = await makeFakeClaude([
276
278
  { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
277
279
  ]);
@@ -288,7 +290,7 @@ describe('claude-code provider definition', () => {
288
290
  expect(args).not.toContain('bypassPermissions');
289
291
  });
290
292
 
291
- it.each(['claude-fable-5', 'claude-opus-5'])('passes the selected %s model as an exact structured argument', async (model) => {
293
+ it.skipIf(!posixShell).each(['claude-fable-5-1', 'claude-opus-5-5'])('passes the selected %s model as an exact structured argument', async (model) => {
292
294
  const dir = await makeFakeClaude([
293
295
  { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
294
296
  ]);
@@ -300,18 +302,18 @@ describe('claude-code provider definition', () => {
300
302
  expect(args.filter((arg) => arg === '--model')).toHaveLength(1);
301
303
  });
302
304
 
303
- it('uses the persisted provider-item model as its default selection', async () => {
305
+ it.skipIf(!posixShell)('uses the persisted provider-item model as its default selection', async () => {
304
306
  const dir = await makeFakeClaude([
305
307
  { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
306
308
  ]);
307
- const client = claudeCodeProviderDef.createClient({ model: 'claude-fable-5', executable: join(dir, 'claude') });
309
+ const client = claudeCodeProviderDef.createClient({ model: 'claude-fable-5-1', executable: join(dir, 'claude') });
308
310
  await collect(client.stream({ ...textRequest(), model: '' }));
309
311
 
310
312
  const args = JSON.parse(await readFile(join(dir, 'args.json'), 'utf8')) as string[];
311
- expect(args.slice(-2)).toEqual(['--model', 'claude-fable-5']);
313
+ expect(args.slice(-2)).toEqual(['--model', 'claude-fable-5-1']);
312
314
  });
313
315
 
314
- it('returns actionable errors for locally unsupported and CLI-rejected models', async () => {
316
+ it.skipIf(!posixShell)('returns actionable errors for locally unsupported and CLI-rejected models', async () => {
315
317
  const supported = claudeCodeModels.map((model) => model.id);
316
318
  const unsupported = await collect(createClaudeCodeClient({
317
319
  spawn: () => { throw new Error('should not spawn'); },
@@ -328,17 +330,17 @@ describe('claude-code provider definition', () => {
328
330
  ]);
329
331
  const rejected = await collect(createClaudeCodeClient({ executable: join(dir, 'claude') }).stream({
330
332
  ...textRequest(),
331
- model: 'claude-fable-5',
333
+ model: 'claude-fable-5-1',
332
334
  }));
333
335
  expect(rejected[1]).toMatchObject({
334
336
  type: 'error',
335
- message: expect.stringMatching(/Claude Code rejected model "claude-fable-5".*Model is unavailable/),
337
+ message: expect.stringMatching(/Claude Code rejected model "claude-fable-5-1".*Model is unavailable/),
336
338
  retryable: false,
337
339
  });
338
340
  for (const model of supported) expect((rejected[1] as { message: string }).message).toContain(model);
339
341
  });
340
342
 
341
- it.each([
343
+ it.skipIf(!posixShell).each([
342
344
  ['Not logged in. Authentication required', /signed out|authentication/i, false],
343
345
  ['Rate limit exceeded (429)', /service failure.*rate limit/i, true],
344
346
  ['Service temporarily unavailable', /service failure.*unavailable/i, true],
@@ -368,7 +370,7 @@ describe('claude-code provider definition', () => {
368
370
  expect(child.kills).toEqual(['SIGTERM']);
369
371
  });
370
372
 
371
- it('reports a missing executable and an unexpected exit as actionable non-retryable errors', async () => {
373
+ it.skipIf(!posixShell)('reports a missing executable and an unexpected exit as actionable non-retryable errors', async () => {
372
374
  const missing = Object.assign(new Error('spawn claude ENOENT'), { code: 'ENOENT' });
373
375
  const missingEvents = await collect(createClaudeCodeClient({
374
376
  executable: '/missing/claude',
@@ -390,7 +392,7 @@ describe('claude-code provider definition', () => {
390
392
  expect(exitEvents.filter((event) => event.type === 'error')).toHaveLength(1);
391
393
  });
392
394
 
393
- it('surfaces a permission denial as a clear non-retryable error', async () => {
395
+ it.skipIf(!posixShell)('surfaces a permission denial as a clear non-retryable error', async () => {
394
396
  const dir = await makeFakeClaude([
395
397
  { type: 'result', subtype: 'error_during_execution', is_error: true, result: 'Permission denied for Edit' },
396
398
  ]);
@@ -430,7 +432,7 @@ describe('claude-code provider definition', () => {
430
432
  }
431
433
  });
432
434
 
433
- it('orders the identity, message-derived system text, and extra system text', async () => {
435
+ it.skipIf(!posixShell)('orders the identity, message-derived system text, and extra system text', async () => {
434
436
  const dir = await makeFakeClaude([
435
437
  { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
436
438
  ]);
@@ -449,9 +451,108 @@ describe('claude-code provider definition', () => {
449
451
  expect(input.indexOf('message system')).toBeLessThan(input.indexOf('system instructions'));
450
452
  });
451
453
 
452
- it('rejects capabilities that the text-only descriptors disable', async () => {
454
+ it.skipIf(!posixShell)('turns a streamed moxxy tool-call block into tool_use events and stops at it', async () => {
455
+ const delta = (text: string) => ({
456
+ type: 'stream_event',
457
+ event: { type: 'content_block_delta', delta: { type: 'text_delta', text } },
458
+ });
459
+ const dir = await makeFakeClaude([
460
+ { type: 'stream_event', event: { type: 'content_block_start', content_block: { type: 'text', text: '' } } },
461
+ delta("I'll read it.\n<moxxy_tool"),
462
+ delta('_calls>\n<call name="Read">{"file_path": "x.yaml"}</call>\n'),
463
+ delta('<call name="Grep">not json</call>\n</moxxy_tool_calls>'),
464
+ delta('The first line is: invented'),
465
+ { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
466
+ ]);
467
+ const client = createClaudeCodeClient({ executable: join(dir, 'claude') });
468
+ const events = await collect(client.stream({
469
+ ...textRequest(),
470
+ tools: [{
471
+ name: 'Read',
472
+ description: 'Read a <file>',
473
+ inputSchema: z.object({ file_path: z.string() }),
474
+ handler: async () => 'unused',
475
+ }, {
476
+ name: 'web_search',
477
+ description: 'Local search fallback',
478
+ inputSchema: z.object({ query: z.string() }),
479
+ hosted: { type: 'web_search' },
480
+ handler: async () => 'unused',
481
+ }],
482
+ }));
483
+
484
+ const ids = events.flatMap((event) => (event.type === 'tool_use_start' ? [event.id] : []));
485
+ expect(ids).toHaveLength(2);
486
+ expect(new Set(ids).size).toBe(2);
487
+ expect(events).toEqual([
488
+ { type: 'message_start', model: 'claude-sonnet-5-5' },
489
+ { type: 'text_delta', delta: "I'll read it.\n" },
490
+ { type: 'tool_use_start', id: ids[0], name: 'Read' },
491
+ { type: 'tool_use_end', id: ids[0], input: { file_path: 'x.yaml' } },
492
+ { type: 'tool_use_start', id: ids[1], name: 'Grep' },
493
+ { type: 'tool_use_end', id: ids[1], input: 'not json' },
494
+ { type: 'message_end', stopReason: 'tool_use' },
495
+ ]);
496
+ const input = await readFile(join(dir, 'input.txt'), 'utf8');
497
+ expect(input).toContain('<tool name="Read">');
498
+ expect(input).toContain('<description>Read a &lt;file&gt;</description>');
499
+ expect(input).toContain('"file_path":{"type":"string"}');
500
+ expect(input).toContain('<moxxy_tool_calls>');
501
+ expect(input).not.toContain('<tool name="web_search">');
502
+ expect(input.trimEnd().endsWith('as described in the system section.]')).toBe(true);
503
+ const args = JSON.parse(await readFile(join(dir, 'args.json'), 'utf8')) as string[];
504
+ expect(args).toEqual(expect.arrayContaining(['--tools', 'WebSearch']));
505
+ expect(args).not.toContain('Read');
506
+ });
507
+
508
+ it.skipIf(!posixShell)('continues past an internal CLI tool round trip to the moxxy tool-call block', async () => {
509
+ // Shape captured from the live CLI: the model first tries a native Read,
510
+ // the CLI rejects it, then the model uses the moxxy protocol.
511
+ const dir = await makeFakeClaude([
512
+ { type: 'stream_event', event: { type: 'content_block_start', content_block: { type: 'tool_use', id: 'toolu_1', name: 'Read', input: {} } } },
513
+ { type: 'stream_event', event: { type: 'content_block_delta', delta: { type: 'input_json_delta', partial_json: '{"file_path":"x.yaml"}' } } },
514
+ { type: 'stream_event', event: { type: 'content_block_stop' } },
515
+ { type: 'stream_event', event: { type: 'message_delta', delta: { stop_reason: 'tool_use' } } },
516
+ { type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: 'toolu_1', is_error: true, content: 'No such tool available: Read' }] } },
517
+ { type: 'stream_event', event: { type: 'message_stop' } },
518
+ { type: 'stream_event', event: { type: 'content_block_start', content_block: { type: 'text', text: '' } } },
519
+ { type: 'stream_event', event: { type: 'content_block_delta', delta: { type: 'text_delta', text: '<moxxy_tool_calls>\n<call name="Read">{"file_path":"x.yaml"}</call>\n</moxxy_tool_calls>' } } },
520
+ { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
521
+ ]);
522
+ const events = await collect(createClaudeCodeClient({ executable: join(dir, 'claude') }).stream({
523
+ ...textRequest(),
524
+ tools: [{ name: 'Read', description: 'Read', inputSchema: z.object({ file_path: z.string() }), handler: async () => 'unused' }],
525
+ }));
526
+
527
+ expect(events.filter((event) => event.type === 'error')).toEqual([]);
528
+ expect(events).toContainEqual(expect.objectContaining({ type: 'tool_use_end', input: { file_path: 'x.yaml' } }));
529
+ expect(events.at(-1)).toEqual({ type: 'message_end', stopReason: 'tool_use' });
530
+ });
531
+
532
+ it.skipIf(!posixShell)('keeps call-shaped text as plain output when no tools were offered or the block never closes', async () => {
533
+ const records = [
534
+ { type: 'stream_event', event: { type: 'content_block_start', content_block: { type: 'text', text: '' } } },
535
+ { type: 'stream_event', event: { type: 'content_block_delta', delta: { type: 'text_delta', text: 'a <moxxy_tool_calls><call name="Read">{}' } } },
536
+ { type: 'result', subtype: 'success', is_error: false, usage: { input_tokens: 1, output_tokens: 1 } },
537
+ ];
538
+ const tool = { name: 'Read', description: 'Read', inputSchema: z.object({}), handler: async () => 'unused' };
539
+ for (const tools of [undefined, [tool]]) {
540
+ const dir = await makeFakeClaude(records);
541
+ const events = await collect(createClaudeCodeClient({ executable: join(dir, 'claude') }).stream({
542
+ ...textRequest(),
543
+ ...(tools ? { tools } : {}),
544
+ }));
545
+ expect(events.filter((event) => event.type.startsWith('tool_use'))).toEqual([]);
546
+ expect(events.flatMap((event) => (event.type === 'text_delta' ? [event.delta] : [])).join(''))
547
+ .toBe('a <moxxy_tool_calls><call name="Read">{}');
548
+ expect(events.at(-1)).toMatchObject({ type: 'message_end', stopReason: 'end_turn' });
549
+ }
550
+ });
551
+
552
+ it('does not advertise or accept moxxy tools in native-tools mode', async () => {
453
553
  const spawn = () => { throw new Error('should not spawn'); };
454
- const client = createClaudeCodeClient({ spawn });
554
+ const client = createClaudeCodeClient({ spawn, mode: 'native-tools' });
555
+ expect(client.models.every((model) => model.supportsTools === false)).toBe(true);
455
556
 
456
557
  const withTools = await collect(client.stream({
457
558
  ...textRequest(),
@@ -464,9 +565,14 @@ describe('claude-code provider definition', () => {
464
565
  }));
465
566
  expect(withTools[1]).toMatchObject({
466
567
  type: 'error',
467
- message: expect.stringContaining('does not support tools'),
568
+ message: expect.stringContaining('does not support moxxy tools'),
468
569
  retryable: false,
469
570
  });
571
+ });
572
+
573
+ it('rejects capabilities that the descriptors disable', async () => {
574
+ const spawn = () => { throw new Error('should not spawn'); };
575
+ const client = createClaudeCodeClient({ spawn });
470
576
 
471
577
  const withReasoning = await collect(client.stream({ ...textRequest(), reasoning: true }));
472
578
  expect(withReasoning[1]).toMatchObject({
@@ -498,7 +604,7 @@ describe('claude-code provider definition', () => {
498
604
 
499
605
  function textRequest(): ProviderRequest {
500
606
  return {
501
- model: 'claude-sonnet-5',
607
+ model: 'claude-sonnet-5-5',
502
608
  system: 'system instructions',
503
609
  messages: [
504
610
  { role: 'user', content: [{ type: 'text', text: 'prior user' }] },
package/src/provider.ts CHANGED
@@ -4,7 +4,7 @@ import { CLAUDE_CODE_PROVIDER_ID } from './constants.js';
4
4
  import { ClaudeProcessError, runClaudeProcess, type ClaudeSpawn } from './process.js';
5
5
  import { createProtocolState, parseClaudeRecord, serializeClaudePrompt } from './protocol.js';
6
6
 
7
- export const CLAUDE_CODE_DEFAULT_MODEL = 'claude-sonnet-5';
7
+ export const CLAUDE_CODE_DEFAULT_MODEL = 'claude-sonnet-5-5';
8
8
  const NON_TEXT_BLOCK_TOKENS = 256;
9
9
 
10
10
  /**
@@ -12,11 +12,12 @@ const NON_TEXT_BLOCK_TOKENS = 256;
12
12
  *
13
13
  * This is deliberately independent of the Anthropic API catalog: the CLI has
14
14
  * its own availability policy, and this adapter only preserves streamed text.
15
- * Unsupported capabilities are explicit so every host sees the same text-only
16
- * contract rather than relying on how it interprets absent optional flags.
15
+ * moxxy tools ride a text protocol (see protocol.ts). Unsupported capabilities
16
+ * are explicit so every host sees the same contract rather than relying on how
17
+ * it interprets absent optional flags.
17
18
  */
18
19
  const textOnlyCapabilities = {
19
- supportsTools: false,
20
+ supportsTools: true,
20
21
  supportsStreaming: true,
21
22
  supportsImages: false,
22
23
  supportsDocuments: false,
@@ -26,8 +27,8 @@ const textOnlyCapabilities = {
26
27
  } as const;
27
28
 
28
29
  export const claudeCodeModels: ReadonlyArray<ModelDescriptor> = [
29
- { id: 'claude-fable-5', contextWindow: 1_000_000, maxOutputTokens: 128_000, ...textOnlyCapabilities },
30
- { id: 'claude-opus-5', contextWindow: 1_000_000, maxOutputTokens: 128_000, ...textOnlyCapabilities },
30
+ { id: 'claude-fable-5-1', contextWindow: 1_000_000, maxOutputTokens: 128_000, ...textOnlyCapabilities },
31
+ { id: 'claude-opus-5-5', contextWindow: 1_000_000, maxOutputTokens: 128_000, ...textOnlyCapabilities },
31
32
  { id: CLAUDE_CODE_DEFAULT_MODEL, contextWindow: 1_000_000, maxOutputTokens: 128_000, ...textOnlyCapabilities },
32
33
  { id: 'claude-haiku-4-5', contextWindow: 200_000, maxOutputTokens: 64_000, ...textOnlyCapabilities },
33
34
  ];
@@ -63,7 +64,7 @@ export interface ClaudeCodeProviderConfig {
63
64
 
64
65
  export class ClaudeCodeProvider implements LLMProvider {
65
66
  readonly name = CLAUDE_CODE_PROVIDER_ID;
66
- readonly models = claudeCodeModels;
67
+ readonly models: ReadonlyArray<ModelDescriptor>;
67
68
 
68
69
  private readonly executable: string;
69
70
  private readonly defaultModel: string;
@@ -82,6 +83,11 @@ export class ClaudeCodeProvider implements LLMProvider {
82
83
  this.executable = config.executable ?? 'claude';
83
84
  this.defaultModel = config.defaultModel ?? CLAUDE_CODE_DEFAULT_MODEL;
84
85
  this.nativeTools = config.mode === 'native-tools';
86
+ // Native-tools mode hands the task to Claude's own tools; moxxy tools are
87
+ // only offered through the text transport.
88
+ this.models = this.nativeTools
89
+ ? claudeCodeModels.map((model) => ({ ...model, supportsTools: false }))
90
+ : claudeCodeModels;
85
91
  this.webSearch = config.webSearch !== false;
86
92
  if (config.permissionMode) this.permissionMode = config.permissionMode;
87
93
  this.allowedTools = config.allowedTools ?? [];
@@ -97,17 +103,21 @@ export class ClaudeCodeProvider implements LLMProvider {
97
103
  const model = req.model || this.defaultModel;
98
104
  yield { type: 'message_start', model };
99
105
 
106
+ // Native WebSearch replaces moxxy's web_search fallback when it is enabled.
107
+ const tools = this.webSearch
108
+ ? req.tools?.filter((tool) => tool.hosted?.type !== 'web_search')
109
+ : req.tools;
100
110
  let prompt: string;
101
111
  try {
102
112
  assertSupportedModel(model);
103
- assertTextOnlyRequest(req);
104
- prompt = serializeClaudePrompt(req);
113
+ assertTextOnlyRequest(req, this.nativeTools);
114
+ prompt = serializeClaudePrompt({ ...req, ...(tools ? { tools } : {}) });
105
115
  } catch (error) {
106
116
  yield nonRetryableError(error);
107
117
  return;
108
118
  }
109
119
 
110
- const state = createProtocolState();
120
+ const state = createProtocolState({ toolCalls: (tools?.length ?? 0) > 0 });
111
121
  let terminal = false;
112
122
  let lines: ReturnType<typeof runClaudeProcess> | undefined;
113
123
  try {
@@ -199,9 +209,9 @@ function assertSupportedModel(model: string): void {
199
209
  );
200
210
  }
201
211
 
202
- function assertTextOnlyRequest(req: ProviderRequest): void {
203
- if (req.tools && req.tools.length > 0) {
204
- throw new Error('Claude CLI text transport does not support tools');
212
+ function assertTextOnlyRequest(req: ProviderRequest, nativeTools: boolean): void {
213
+ if (nativeTools && req.tools && req.tools.length > 0) {
214
+ throw new Error('Claude CLI native-tools transport does not support moxxy tools');
205
215
  }
206
216
  if (req.reasoning) {
207
217
  throw new Error('Claude CLI text transport does not support reasoning');