pub struct Event {Show 23 fields
pub id: Option<i64>,
pub machine_id: String,
pub timestamp: DateTime<Utc>,
pub event_type: EventType,
pub session_id: String,
pub framework: Option<String>,
pub tool_use_id: Option<String>,
pub spawned_agent_id: Option<String>,
pub tool_name: Option<String>,
pub subagent_type: Option<String>,
pub permission_mode: Option<String>,
pub transcript_path: Option<String>,
pub pid: Option<i32>,
pub cwd: Option<String>,
pub model: Option<String>,
pub tokens_input: Option<i64>,
pub tokens_output: Option<i64>,
pub tokens_cache_read: Option<i64>,
pub tokens_cache_creation: Option<i64>,
pub cost_usd: Option<f64>,
pub duration_ms: Option<i64>,
pub payload: Option<String>,
pub metadata: Option<String>,
}Expand description
A hook event captured from Claude Code
Fields§
§id: Option<i64>Database ID (None for new events)
machine_id: StringMachine identifier for multi-machine sync
timestamp: DateTime<Utc>Event timestamp
event_type: EventTypeEvent type (SessionStart, PreToolUse, etc.)
session_id: StringSession ID from Claude Code
framework: Option<String>Source framework (claude, cursor, gemini, etc.)
tool_use_id: Option<String>Tool use ID for correlating PreToolUse/PostToolUse
spawned_agent_id: Option<String>Child agent ID from PostToolUse for Task tool (links parent → child sessions)
tool_name: Option<String>Tool name (Bash, Read, Write, Edit, Task, etc.)
subagent_type: Option<String>Subagent type for Task tool (Explore, Plan, claude-code-guide, etc.)
permission_mode: Option<String>Permission mode (default, plan, acceptEdits, bypassPermissions)
transcript_path: Option<String>Path to the session transcript JSONL file
pid: Option<i32>Parent process ID
cwd: Option<String>Working directory
model: Option<String>Model used for API request (e.g., “claude-3-opus”)
tokens_input: Option<i64>Input tokens used
tokens_output: Option<i64>Output tokens generated
tokens_cache_read: Option<i64>Tokens read from cache
tokens_cache_creation: Option<i64>Tokens written to cache
cost_usd: Option<f64>Cost in USD
duration_ms: Option<i64>API call duration in milliseconds
payload: Option<String>JSON payload with all hook data
metadata: Option<String>Extensible JSON metadata for future fields
Implementations§
Source§impl Event
impl Event
Sourcepub fn new(
machine_id: String,
event_type: EventType,
session_id: String,
) -> Self
pub fn new( machine_id: String, event_type: EventType, session_id: String, ) -> Self
Create a new event with current timestamp
Sourcepub fn is_api_request(&self) -> bool
pub fn is_api_request(&self) -> bool
Check if this event is an API request (has token data)
Sourcepub fn total_tokens(&self) -> i64
pub fn total_tokens(&self) -> i64
Total tokens (input + output) for API requests
pub fn with_framework(self, framework: Option<String>) -> Self
pub fn with_tool_use_id(self, tool_use_id: Option<String>) -> Self
pub fn with_spawned_agent_id(self, spawned_agent_id: Option<String>) -> Self
pub fn with_tool_name(self, tool_name: Option<String>) -> Self
pub fn with_subagent_type(self, subagent_type: Option<String>) -> Self
pub fn with_permission_mode(self, permission_mode: Option<String>) -> Self
pub fn with_transcript_path(self, transcript_path: Option<String>) -> Self
pub fn with_pid(self, pid: Option<i32>) -> Self
pub fn with_cwd(self, cwd: Option<String>) -> Self
pub fn with_model(self, model: Option<String>) -> Self
pub fn with_tokens_input(self, tokens_input: Option<i64>) -> Self
pub fn with_tokens_output(self, tokens_output: Option<i64>) -> Self
pub fn with_tokens_cache_read(self, tokens_cache_read: Option<i64>) -> Self
pub fn with_tokens_cache_creation( self, tokens_cache_creation: Option<i64>, ) -> Self
pub fn with_cost_usd(self, cost_usd: Option<f64>) -> Self
pub fn with_duration_ms(self, duration_ms: Option<i64>) -> Self
pub fn with_payload(self, payload: Option<String>) -> Self
pub fn with_metadata(self, metadata: Option<String>) -> Self
Sourcepub fn with_timestamp(self, timestamp: DateTime<Utc>) -> Self
pub fn with_timestamp(self, timestamp: DateTime<Utc>) -> Self
Set the timestamp (useful for testing)