Each request currently spawns a fresh claude -p process (~5-7s startup overhead).
claude -p supports --input-format stream-json which accepts stdin messages in NDJSON format:
{"type":"user","message":{"role":"user","content":"say pong"},"session_id":"<uuid>"}
This enables keeping a persistent claude process warm and feeding messages via stdin — eliminating the cold start entirely. Responses would start in <1s instead of 5-7s.
Approach:
- On proxy startup, spawn a persistent
claude -p --input-format stream-json --output-format stream-json --verbose --permission-mode bypassPermissions
- Multiplex: track which request each
result event belongs to via session_id/uuid correlation
- Feed incoming API requests as stdin messages
- Route output events back to the correct HTTP response
- Auto-restart the process if it dies
Research done:
- Input format:
{"type":"user","message":{"role":"user","content":"text"},"session_id":"UUID"}
- Output includes session_id for correlation
- Process stays alive between messages
- Supports multi-turn conversation natively
Complexity: Medium-high (requires careful multiplexing and error handling)
Priority: High — this is the biggest UX improvement possible
Refs: https://code.claude.com/docs/en/headless
Each request currently spawns a fresh
claude -pprocess (~5-7s startup overhead).claude -psupports--input-format stream-jsonwhich accepts stdin messages in NDJSON format:{"type":"user","message":{"role":"user","content":"say pong"},"session_id":"<uuid>"}This enables keeping a persistent
claudeprocess warm and feeding messages via stdin — eliminating the cold start entirely. Responses would start in <1s instead of 5-7s.Approach:
claude -p --input-format stream-json --output-format stream-json --verbose --permission-mode bypassPermissionsresultevent belongs to via session_id/uuid correlationResearch done:
{"type":"user","message":{"role":"user","content":"text"},"session_id":"UUID"}Complexity: Medium-high (requires careful multiplexing and error handling)
Priority: High — this is the biggest UX improvement possible
Refs: https://code.claude.com/docs/en/headless