Event

Struct Event 

Source
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: String

Machine identifier for multi-machine sync

§timestamp: DateTime<Utc>

Event timestamp

§event_type: EventType

Event type (SessionStart, PreToolUse, etc.)

§session_id: String

Session 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

Source

pub fn new( machine_id: String, event_type: EventType, session_id: String, ) -> Self

Create a new event with current timestamp

Source

pub fn is_api_request(&self) -> bool

Check if this event is an API request (has token data)

Source

pub fn total_tokens(&self) -> i64

Total tokens (input + output) for API requests

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Event

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Event

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,