ai-claude-code: add an extraArgs option instead of splitting claudeExecutable on spaces #2225
TanStack AI version#
@tanstack/ai 1.8.0, @tanstack/ai-claude-code 1.0.3, @tanstack/ai-sandbox 1.5.0, @tanstack/ai-sandbox-local-process 1.0.0 (all latest on npm)
Framework/Library version#
Node 26.12.0, server only (no UI framework involved)
Describe the bug and the steps to reproduce it#
The adapter has no option for extra claude CLI flags (the config at src/adapters/text.ts:95-175 has none, and extraArgs appears nowhere in the package). The only way to pass flags such as --settings <json>, --thinking-display or --disable-slash-commands is to put them in claudeExecutable, which the adapter splits on spaces (adapters/text.ts:281, (config.claudeExecutable ?? 'claude').split(' ')). A --settings JSON value that contains a space arrives as two broken arguments, and so does an executable path that contains a space.
Steps:
- Install
@tanstack/ai@1.8.0,@tanstack/ai-claude-code@1.0.3,@tanstack/ai-sandbox@1.5.0and@tanstack/ai-sandbox-local-process@1.0.0in an ESM package, and create an emptywork/folder. - Save
fake-claude.mjsandrepro.mjsbelow next to each other, and runchmod +x fake-claude.mjs. - Run
node repro.mjs.
fake-claude.mjs (make it executable with chmod +x):
#!/usr/bin/env node
// Stands in for the `claude` CLI. Records argv and the thinking env, then prints the
// stream-json lines that @tanstack/ai-claude-code parses.
import { writeFileSync } from 'node:fs'
for await (const _ of process.stdin); // read the prompt, as the CLI does (exiting first gives the runner EPIPE)
const argv = process.argv.slice(2)
writeFileSync(new URL('./last-call.json', import.meta.url), JSON.stringify({ argv, MAX_THINKING_TOKENS: process.env.MAX_THINKING_TOKENS }))
// On --resume the CLI restores the session's saved totals, so result.total_cost_usd is the
// session total (https://code.claude.com/docs/en/agent-sdk/cost-tracking). Here
// run 1 costs $0.25 and the resumed run 2 costs $0.50, so run 2 reports $0.75.
const resumed = argv.includes('--resume')
const say = (line) => console.log(JSON.stringify(line))
say({ type: 'system', subtype: 'init', session_id: 'sess-1', model: 'x', tools: [] })
say({ type: 'assistant', parent_tool_use_id: null, message: { id: resumed ? 'm2' : 'm1', content: [{ type: 'text', text: 'ok' }] } })
say({ type: 'result', subtype: 'success', usage: { input_tokens: 1, output_tokens: 1 }, total_cost_usd: resumed ? 0.75 : 0.25 })
repro.mjs:
// #2225: claudeExecutable is split on spaces, so a --settings JSON value with a space breaks.
import { readFileSync } from 'node:fs'
import { chat } from '@tanstack/ai'
import { claudeCodeText } from '@tanstack/ai-claude-code'
import { defineSandbox, withSandbox } from '@tanstack/ai-sandbox'
import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
const sandbox = defineSandbox({ id: 'repro', provider: localProcessSandbox({ dir: new URL('./work', import.meta.url).pathname }) })
const fake = new URL('./fake-claude.mjs', import.meta.url).pathname
const stream = chat({
adapter: claudeCodeText('claude-opus-4-8', { claudeExecutable: `${fake} --settings {"a": 1}`, emitDiff: false }),
messages: [{ role: 'user', content: 'hi' }],
threadId: 't1',
middleware: [withSandbox(sandbox)],
})
for await (const c of stream) if (c.type === 'RUN_ERROR') console.log(c.message)
const { argv } = JSON.parse(readFileSync(new URL('./last-call.json', import.meta.url)))
console.log(JSON.stringify(argv.slice(0, argv.indexOf('-p'))))
// Fixed (an extraArgs: ['--settings', '{"a": 1}'] option): ["--settings","{\"a\": 1}","--setting-sources","project"]
Output:
["--settings","{\"a\":","1}","--setting-sources","project"]
Expected: the JSON value arrives as one argument: ["--settings","{\"a\": 1}","--setting-sources","project"]. An extraArgs: string[] adapter option, placed before -p, would let flags be passed without the split, and claudeExecutable would then be a single path.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
Inline above. Plain Node script with no network, no model and no API key. fake-claude.mjs stands in for the claude CLI through claudeExecutable: it records the argv the adapter passes and prints the stream-json lines the adapter parses.
Screenshots or Videos (Optional)#
None.
Do you intend to try to help solve this bug with your own PR?#
Maybe, I'll investigate and start debugging
Terms & Code of Conduct#
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
github-actions[bot](GitHub profile, opens in a new tab) assignedjherr
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-repro
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-repro
I added a minimal, runnable reproduction to the description: a plain Node script with no network, no model and no API key, tested on the current npm releases.
Sign in to join this conversation.
Thanks for the report, @ozolcar! To help us reproduce this, could you add a minimal reproduction?
A runnable example makes fixes dramatically faster — you can fork one of the official examples, or use StackBlitz / CodeSandbox. For TypeScript-only issues, a TS Playground link works too.
Automated triage — a maintainer will follow up.