Build your own chat UI for Claude Code: the stdin control protocol, with a runnable host A developer documented how to drive Claude Code as a long-lived bidirectional child process using `claude -p` with stream-JSON input and output plus `--permission-prompt-tool stdio`, publishing a runnable Node host script that answers `can_use_tool` control requests itself. The writeup shows the CLI can pause mid-run to ask the host a question and wait for a reply, and warns that wrappers hang if they don't handle these control requests. The host was tested on Claude Code 2.1.332 on Windows. claude -p looks like a one-shot command, but it can also be a long-lived child process that talks to your program in both directions. That is how you build your own chat UI, bot, or review tool around Claude Code without scraping a terminal. The part that surprised me is that the CLI can ask your program a question in the middle of a run and then wait for the answer . If you don't know that, your wrapper hangs. If you do, you get proper question cards, plan approvals, and permission prompts. This post shows the handshake with a runnable host, one real run I captured, and the mistakes that are easy to make. I tested it on Claude Code 2.1.332 on Windows. You start the CLI with stream-JSON on both sides: claude -p --input-format stream-json --output-format stream-json \ --verbose --permission-prompt-tool stdio system/init , assistant , user tool results , result , and the interesting one, control request . --permission-prompt-tool stdio is what routes "this tool needs a human" decisions to you instead of handling them inside the CLI. Without a reply from you, those decisions can't be made. This is the whole thing. It sends one prompt that forces the AskUserQuestion tool, answers the question itself, and prints every event with a timestamp. // A tiny "host" for Claude Code: drives the CLI over stdin/stdout, answers can use tool itself. // Usage: node host-experiment.mjs