Skip to content

claude-p

A claude -p emulator that drives the interactive claude UI inside an in-process zmux PTY session.

Use at your own risk. This package and repository exist for educational purposes and demonstrate why client-side restrictions on how a product is used are fundamentally unenforceable. Built using the smithers self-improving harness and zmux.

Terminal window
# One-shot text (default)
npx claude-p "Reply with the single word OK."
# Structured JSON result
git diff HEAD~1 | npx claude-p --output-format json "Summarize this diff."
# Live per-message JSONL stream (--verbose required)
npx claude-p --output-format stream-json --verbose "Audit src/" | jq .
# Long-lived multi-turn daemon over NDJSON
printf '%s\n' '{"type":"user","message":{"role":"user","content":"List the Zig modules."}}' \
| npx claude-p daemon
STAGE 1 · BOOT PTY + FIFO Open events.fifo first, spawn claude, reply to 5 DEC probes + modals. STAGE 2 · SUBMIT SessionStart Wait for quiescence, bracketed-paste prompt, verify UserPromptSubmit. STAGE 3 · RUN Tail & Wait Stream JSONL lines via pread() as flushed until Stop arrives on FIFO. STAGE 4 · EMIT Result + Reap Parse offset slice, emit text/json/result, kill child, remove temp dir.
Every one-shot invocation walks through four deterministic stages. No screen scraping is ever used to decide whether the assistant finished.
Mode Entry point Best for Overhead
One-shot CLI claude-p [OPTIONS] [PROMPT] Shell scripts, git hooks, CI steps (text, json, stream-json). 1 PTY boot per call (~50–200 ms)
Daemon CLI claude-p daemon [OPTIONS] Multi-turn controllers, chat bridges, agent hubs over NDJSON (user, ping, interrupt). 1 PTY boot across all turns
Zig library claude_p.run() / claude_p.daemon.run() Native Zig 0.15.2 binaries with direct std.Io.Writer streaming. In-process, zero subprocess shim

Zero ~/.claude mutation

Every hook script, FIFO, and inline —settings payload lives inside a per-run $TMPDIR/claude-p-<pid>-<rand>/ directory and is deleted on exit.

Hooks, not screen scraping

SessionStart, UserPromptSubmit, Stop, and StopFailure drive the state machine. Output comes straight from Claude’s session JSONL transcript.

Real PTY, paced bracketed paste

zmux.NativeSession runs a real forkpty session. Prompts stream in ≤ 512 B UTF-8-safe chunks so macOS TTYHOG never drops bytes.

Verified prebuilt binaries

scripts/install.js downloads platform binaries from GitHub Releases and checks their SHA-256 digest against the checksums.json bundled in the npm tarball before writing to disk. A mismatch fails the install.