LemonCliRunners.ClaudeSchema (lemon_cli_runners v0.1.0)

View Source

Claude CLI JSONL event schema definitions.

This module defines all the event types emitted by claude -p --output-format stream-json. Events are decoded from newline-delimited JSON (JSONL) format.

Event Categories

System Messages

  • StreamSystemMessage - Session initialization with metadata

Conversation Messages

  • StreamAssistantMessage - Claude's response with content blocks
  • StreamUserMessage - Tool results returned to Claude

Result Messages

  • StreamResultMessage - Final session result with usage stats

Content Block Types

  • TextBlock - Plain text response
  • ThinkingBlock - Extended thinking/reasoning
  • ToolUseBlock - Tool invocation request
  • ToolResultBlock - Tool execution result

Decoding

case ClaudeSchema.decode_event(json_line) do
  {:ok, %StreamSystemMessage{session_id: id}} -> ...
  {:ok, %StreamAssistantMessage{message: msg}} -> ...
  {:error, reason} -> ...
end

Summary

Types

Union of all content block types

Union of all stream event types

Functions

Decode a JSON line into a stream event struct.

Decode a map (already parsed JSON) into a stream event struct.

Types

Functions

decode_event(json)

@spec decode_event(String.t() | binary()) :: {:ok, stream_event()} | {:error, term()}

Decode a JSON line into a stream event struct.

Returns {:ok, event} on success or {:error, reason} on failure.

decode_event_map(data)

@spec decode_event_map(map()) :: {:ok, stream_event()} | {:error, term()}

Decode a map (already parsed JSON) into a stream event struct.