Skip to content

Getting Started

claude-p emulates claude -p. It spawns your installed claude binary inside an in-process zmux PTY, drives the interactive UI, and prints claude -p-shaped text and json results. stream-json emits Claude Code session-transcript lines plus a claude -p-shaped result envelope; see Stream Live JSON Output for how that differs from native claude -p.

  • OS & CPU: macOS or Linux on arm64 or x64. Windows is unsupported (forkpty is POSIX-only).
  • claude on $PATH: claude-p drives the real Claude Code binary. Verify with claude --version.
  • Runtime: Node >= 18 for npx / npm, or Zig 0.15.2 to build from source.
Terminal window
npx claude-p --version

On npm install, scripts/install.js fetches claude-p-<platform>-<arch>.gz from GitHub Releases and verifies its SHA-256 digest against the checksums.json bundled in the npm tarball before extracting the binary. A digest mismatch aborts installation with exit code 1. A connectivity failure (DNS, offline, HTTP error, timeout) prints a warning and exits 0 unless CLAUDE_P_STRICT_INSTALL=1; local filesystem errors such as ENOSPC exit 1. See Installation, Checksums, and Builds.

Terminal window
npx claude-p --dangerously-skip-permissions "Reply with the single word OK."
OK

If you omit the positional prompt, claude-p reads stdin (up to 16 MiB) or --input-file <path>.

Terminal window
npx claude-p --output-format json --dangerously-skip-permissions \
"Reply with the single word OK."
{"type":"result","subtype":"success","session_id":"550e8400-e29b-41d4-a716-446655440000","result":"OK","is_error":false,"duration_ms":2410,"duration_api_ms":0,"num_turns":1,"total_cost_usd":0,"usage":{"input_tokens":6,"output_tokens":4,"cache_read_input_tokens":0,"cache_creation_input_tokens":0},"permission_denials":[]}

stream-json requires --verbose, matching native claude -p:

Terminal window
npx claude-p --output-format stream-json --verbose \
--dangerously-skip-permissions "Reply with OK." | jq -c '{type, subtype}'

Each transcript line flushes to stdout as soon as claude writes it, followed by the final result envelope.

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.

claude-p never edits ~/.claude/settings.json. It builds an inline --settings JSON string pointing SessionStart, UserPromptSubmit, and Stop hooks to a temporary FIFO in $TMPDIR, runs claude on a real PTY, and reads the final answer from the session transcript JSONL.