Pure functions for the Claude Code stream-json wire format.
Messages are newline-delimited JSON objects on stdin/stdout.
Summary
Functions
Decodes a single JSON line into a tagged tuple.
Encodes a user prompt as a stream-json stdin message.
Splits a binary buffer into complete lines and a remainder.
Types
Functions
Decodes a single JSON line into a tagged tuple.
Returns one of:
{:system_init, map}{:assistant, map}{:user, map}{:result, subtype, map}{:stream_event, map}{:unknown, map}{:invalid_json, raw_line}when the input is not valid JSON
Does not raise; callers can safely pass arbitrary subprocess output.
Encodes a user prompt as a stream-json stdin message.
Returns a newline-terminated JSON string.
Splits a binary buffer into complete lines and a remainder.
Returns {complete_lines, remainder} where complete_lines is a list
of binaries (without the trailing newline) and remainder is the
incomplete trailing fragment (possibly empty).