NAME
Claude::Agent::Message - Message types for Claude Agent SDK
SYNOPSIS
use Claude::Agent::Message;
my $msg = Claude::Agent::Message->from_json($decoded);
if ($msg->isa('Claude::Agent::Message::Assistant')) {
print $msg->text;
}
elsif ($msg->isa('Claude::Agent::Message::Result')) {
print $msg->result;
}
DESCRIPTION
This module loads every message class and provides the factory that turns a decoded line of the CLI's stream-json output into an object.
MESSAGE TYPES
Claude::Agent::Message::User - type
userClaude::Agent::Message::Assistant - type
assistantClaude::Agent::Message::System - type
systemClaude::Agent::Message::HookEvent - type
system, hook subtypesClaude::Agent::Message::Result - type
resultClaude::Agent::Message::StreamEvent - type
stream_eventClaude::Agent::Message::RateLimitEvent - type
rate_limit_eventClaude::Agent::Message::ToolProgress - type
tool_progressClaude::Agent::Message::Base - every other type
METHODS
from_json
my $msg = Claude::Agent::Message->from_json($data);
Builds the message object for $data->{type}. The top-level keys are converted from camelCase to snake_case before they are matched to attributes, so sessionId, durationMs, totalCostUsd, numTurns, isError, modelUsage, apiKeySource and permissionMode arrive as session_id, duration_ms and so on. Nested hashes are not touched. Keys the class does not declare are not lost: the decoded hash is kept as it was sent in the object's raw attribute. A key whose value is JSON null is treated as absent. A type with no class of its own becomes a Claude::Agent::Message::Base; a message with no type dies.
AUTHOR
LNATION, <email at lnation.org>
LICENSE
This software is Copyright (c) 2026 by LNATION.
This is free software, licensed under The Artistic License 2.0 (GPL Compatible).