pub struct Event {Show 28 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 process_start_time: Option<i64>,
pub cwd: Option<String>,
pub git_branch: 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_write: Option<i64>,
pub cost_usd: Option<f64>,
pub duration_ms: Option<i64>,
pub payload: Option<String>,
pub metadata: Option<String>,
pub source: Option<String>,
pub is_sidechain: Option<bool>,
pub context_size: Option<i64>,
}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
process_start_time: Option<i64>Process start time in seconds (Unix timestamp). Captured at event ingestion time for session identity validation.
Note: This field is a transport mechanism - it’s captured during event
ingestion but only persisted to the sessions table, not the events table.
Used to populate Session::process_start_time for PID identity validation.
cwd: Option<String>Working directory
git_branch: Option<String>Git branch name
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_write: 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
source: Option<String>Data source: ‘hook’, ‘otel’, or ‘transcript’
is_sidechain: Option<bool>Whether this is a sidechain request (subagent/auxiliary) Only available from transcript parsing - critical for context size tracking
context_size: Option<i64>Context window size (total tokens in conversation). Used by Amp thread reader where context is pre-calculated from thread data.
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
Sourcepub fn is_main_chain(&self) -> bool
pub fn is_main_chain(&self) -> bool
Returns true if this is a transcript event from the main conversation chain.
Main chain events are the primary conversation between user and agent. Sidechain events are subagent/auxiliary requests that run in parallel.
This is used for filtering when updating session context - we only want to update context (issue/PR numbers, branch info) from main chain events.
Returns true if:
- The event source is “transcript” AND
- The event is NOT marked as sidechain (
is_sidechain != Some(true))
Note: Only transcript events have reliable sidechain info. Hook and OTEL
events don’t have this field, so this method returns false for them.
Sourcepub fn is_sidechain_event(&self) -> bool
pub fn is_sidechain_event(&self) -> bool
Returns true if this is a transcript event from a sidechain (subagent).
Sidechain events are subagent requests that run in parallel to the main conversation. They should not update session context.
Note: Only transcript events have reliable sidechain info.