ClaudeCode.Input (ClaudeCode v0.16.0)
View SourceBuilds input messages for stream-json input format.
When using --input-format stream-json, the CLI accepts NDJSON messages via stdin.
This module provides builders for the various message types.
Message Format
Messages are JSON objects with the following structure:
%{
type: "user",
message: %{role: "user", content: "Your message"},
session_id: "default",
parent_tool_use_id: nil
}Usage
# Build a user message
json = ClaudeCode.Input.user_message("Hello, Claude!")
# With explicit session ID
json = ClaudeCode.Input.user_message("Hello!", "my-session-123")
Summary
Functions
Builds a tool response message for stream-json input.
Builds a user message for stream-json input.
Functions
Builds a tool response message for stream-json input.
Use this when responding to a tool use request from Claude.
Parameters
tool_use_id- The ID of the tool use being responded toresult- The result of the tool execution (string or map)session_id- Session ID for conversation continuityopts- Additional options::is_error- Whether the tool execution resulted in an error (default: false)
Examples
iex> ClaudeCode.Input.tool_response("tool-123", "File created", "session-456")
# Returns JSON with tool result
Builds a user message for stream-json input.
Parameters
content- The message content (string)session_id- Session ID for conversation continuity (default: "default")opts- Additional options::parent_tool_use_id- Tool use ID if responding to a tool (default: nil)
Examples
iex> ClaudeCode.Input.user_message("What is 2 + 2?")
~s({"type":"user","message":{"role":"user","content":"What is 2 + 2?"},"session_id":"default","parent_tool_use_id":null})
iex> ClaudeCode.Input.user_message("Hello", "session-123")
~s({"type":"user","message":{"role":"user","content":"Hello"},"session_id":"session-123","parent_tool_use_id":null})