Skip to content

SDK protocol (stream-json)

The lowest-level integration surface: drive hipmmcode over NDJSON on stdin/stdout. This is what the server and bridges use internally, and it's the right choice when you're embedding hipmmcode as an agent engine inside another program.

bash
hipmmcode --input-format stream-json --output-format stream-json

Each line in is a control message or user turn; each line out is an event.

Messages you send

MessagePurpose
{"type":"user", "message":{…}}A user turn (text and/or attachments)
initializeHandshake: capabilities, session info
set_modelSwitch provider/model mid-session
interruptCancel the running turn
set_permission_modeSwitch default / acceptEdits / plan / bypass
control responsesAnswers to permission / question round-trips (below)

Events you receive

EventMeaning
system (subtype init)Session started: session id, model, tools
assistant / text deltasStreaming response content
tool-use eventsEach tool call + its result
control_requestcan_use_toolPermission round-trip: reply allow/deny on stdin
control_requestask_user_questionStructured question round-trip
resultTurn finished: final text, usage, cost, subtype (success / error / budget_exceeded / …)

Add --include-partial-messages for raw per-token frames, --include-hook-events for hook lifecycle frames, --replay-user-messages to have your own turns echoed back (useful for transcript builders).

One-shot structured pipelines

You don't need the full protocol for simple automation — headless exec emits the same envelopes:

bash
hipmmcode --print --output-format stream-json "run the tests and summarize failures"
hipmmcode --print --json --json-schema '{"type":"object",…}' ""   # schema-validated answer

Permission wiring

In protocol mode, permission decisions come to you as can_use_tool control requests — your host process is the approver. Alternatives: pre-set a mode (--permission-mode acceptEdits), pass rules in settings, or use --permission-webhook to move decisions to an HTTP service. Unanswered requests fail closed.

Embedding checklist

  1. Spawn hipmmcode --input-format stream-json --output-format stream-json (optionally -p/-m, --resume <id>).
  2. Send initialize, then a user message.
  3. Stream events; answer control_requests.
  4. On result, either send the next user turn (the session stays warm) or exit.
  5. Persist the session_id if you want to --resume later.

The complete, always-current handbook — message schemas, examples, exit codes — is embedded in the binary:

bash
hipmmcode integration | less