fix: ensure --input-format stream-json is added when sending images#314
fix: ensure --input-format stream-json is added when sending images#314
Conversation
…o Claude Code The Windows cmd.exe fix (2d227ed) made promptViaStdin match on any arg containing "stream-json", which false-positived on --output-format stream-json (always present in Claude Code default args). This prevented --input-format stream-json from being added when sending images, so Claude Code interpreted the raw JSON+base64 stdin blob as plain text, blowing the token limit. - Fix promptViaStdin to only match --input-format stream-json, not --output-format - Always add --input-format stream-json when images are present (idempotent) - Add 10 regression tests covering image flag injection, promptViaStdin detection, and non-stream-json agent fallback
Pull Request ReviewThis is an excellent bug fix with thorough testing and clear documentation. The fix addresses a critical regression where image input to Claude Code was breaking due to incorrect flag detection logic. ✅ Strengths1. Root Cause Analysis
2. Precise FixThe logic change in // Old (broken): matched any arg containing 'stream-json'
const argsHaveStreamJson = args.some((arg) => arg.includes('stream-json'));
// New (correct): only matches --input-format stream-json
const argsHaveInputStreamJson = args.some(
(arg, i) => arg === 'stream-json' && i > 0 && args[i - 1] === '--input-format'
);This correctly distinguishes between:
3. Idempotent Flag AdditionLines 100-103 ensure const needsInputFormat = !args.includes('--input-format')
? ['--input-format', 'stream-json']
: [];4. Excellent Test CoverageThe 10 new tests (219 lines) comprehensively cover:
All tests follow the existing codebase patterns and include clear explanatory comments. 5. Documentation Quality
🔍 Minor Observations1. Potential Edge Case: Invalid Args ArrayThe flag detection logic assumes const argsHaveInputStreamJson = args.some(
(arg, i) => arg === 'stream-json' && i > 0 && args[i - 1] === '--input-format'
);This is safe for well-formed arg arrays, but could theoretically fail if someone passes
Verdict: Not a blocker, but worth noting. 2. Test Mock SetupThe test suite imports and mocks Recommendation: Verify the mock setup is correct by running the tests locally. If they pass, this is fine. 🚀 Performance ConsiderationsNo performance concerns. The changes are minimal:
🔒 Security ConsiderationsNo security concerns identified. The changes:
📊 Code Quality
🎯 RecommendationAPPROVE with confidence. This is a well-researched, precisely implemented bug fix with excellent test coverage. The regression is critical (breaks image input entirely), and the fix is minimal and low-risk. Suggested follow-up (non-blocking):
📝 Final Score
Overall: ⭐⭐⭐⭐⭐ Excellent work! This fixes a critical bug and sets a great example for regression testing. |
Summary
--input-format stream-jsonCLI flagpromptViaStdinmatch on--output-format stream-json(always present in Claude Code's default args), which prevented--input-format stream-jsonfrom being added when images were presentpromptViaStdindetection to only match--input-format stream-json, not--output-format stream-json--input-format stream-jsonwhen images are present (idempotent, skips if already in args)promptViaStdindetection, and non-stream-json agent fallbackRoot Cause
ChildProcessSpawner.tsline 80 used a broad check:This matched Claude Code's --output-format stream-json default arg, making promptViaStdin always true, which caused the image code path to skip adding --input-format stream-json.
Test plan
--input-format stream-jsonis added when sending images with default Claude Code argssendPromptViaStdinis explicitly true--input-formatwhen already present in args--output-format stream-jsondoes NOT triggerpromptViaStdin--input-format stream-jsonDOES triggerpromptViaStdinsendPromptViaStdinandsendPromptViaStdinRawstill work correctly