pub struct Session {Show 40 fields
pub session_id: String,
pub machine_id: String,
pub framework: Option<String>,
pub first_started_at: DateTime<Utc>,
pub last_started_at: DateTime<Utc>,
pub first_ended_at: Option<DateTime<Utc>>,
pub last_ended_at: Option<DateTime<Utc>>,
pub last_activity: DateTime<Utc>,
pub revival_count: u32,
pub status: Option<SessionStatus>,
pub status_updated_at: Option<DateTime<Utc>>,
pub pid: Option<i32>,
pub process_start_time: Option<i64>,
pub cwd: Option<String>,
pub local_git_dir: Option<String>,
pub git_branch: Option<String>,
pub git_worktree_path: Option<String>,
pub github_repo: Option<String>,
pub github_issue: Option<i32>,
pub github_pr: Option<i32>,
pub git_additions: Option<i32>,
pub git_deletions: Option<i32>,
pub first_user_message: Option<String>,
pub last_user_message: Option<String>,
pub model: Option<String>,
pub compaction_count: u32,
pub message_count: u32,
pub tool_call_count: u32,
pub api_request_count: u32,
pub api_error_count: u32,
pub tokens_input: i64,
pub tokens_output: i64,
pub tokens_cache_read: i64,
pub tokens_cache_write: i64,
pub cost_usd: Option<f64>,
pub context: Option<i64>,
pub n_hook_events: u32,
pub n_otel_events: u32,
pub transcript_available: bool,
pub transcript_path: Option<String>,
}Expand description
A Claude Code session with aggregated metadata.
Sessions are derived from events but stored separately for efficient querying. All aggregate fields are updated incrementally when events are inserted.
§Schema v2
This struct implements Sessions Schema v2 which uses unified columns with
explicit source tracking instead of source-specific columns (e.g., tokens_input
instead of tokens_input_otel and tokens_input_transcript).
Source priority is: transcript > otel > hook
- Transcript is preferred as the authoritative source (includes is_sidechain info)
- OTEL is used as fallback for token/API data
- Hook provides real-time status and prompts
§Session Revival
Sessions can be revived after ending. The schema tracks:
first_started_at/last_started_at: Original and most recent start timesfirst_ended_at/last_ended_at: Original and most recent end timesrevival_count: Number of times the session was revived
Fields§
§session_id: StringUnique session identifier
machine_id: StringMachine identifier for multi-machine sync
framework: Option<String>Source framework (claude_code, gemini, codex, etc.)
first_started_at: DateTime<Utc>Original session start time (immutable)
last_started_at: DateTime<Utc>Most recent start/revival time
first_ended_at: Option<DateTime<Utc>>First time session ended (immutable historical record)
last_ended_at: Option<DateTime<Utc>>Most recent end time (None = running)
last_activity: DateTime<Utc>Timestamp of most recent activity
revival_count: u32Number of times the session was revived after ending
status: Option<SessionStatus>Current session status (idle, busy, wait, done)
status_updated_at: Option<DateTime<Utc>>Timestamp when status was last updated (prevents stale updates)
pid: Option<i32>Process ID (NULL when process ended, can change on revival)
process_start_time: Option<i64>Process start time in seconds (Unix timestamp). Used for deterministic PID identity validation - (pid, start_time) is globally unique. This prevents false positives from PID reuse and handles late mi6 installation.
cwd: Option<String>Working directory
local_git_dir: Option<String>Absolute path to .git directory
git_branch: Option<String>Current git branch name
git_worktree_path: Option<String>Worktree root if in a worktree
github_repo: Option<String>Repository in owner/repo format (e.g., “paradigmxyz/mi6”)
github_issue: Option<i32>GitHub issue number from gh commands (most recent)
github_pr: Option<i32>GitHub PR number from gh commands (most recent)
git_additions: Option<i32>Lines added (from git diff vs main/master or gh pr view)
git_deletions: Option<i32>Lines deleted (from git diff vs main/master or gh pr view)
first_user_message: Option<String>First user prompt (transcript can correct hook’s initial value)
last_user_message: Option<String>Most recent user message text
model: Option<String>Model used in most recent API request
compaction_count: u32Number of context compactions
message_count: u32Total user message count
tool_call_count: u32Total tool call count
api_request_count: u32Total API request count
api_error_count: u32Total failed API request count
tokens_input: i64Total input tokens
tokens_output: i64Total output tokens
tokens_cache_read: i64Total cache read tokens
tokens_cache_write: i64Total cache write tokens
cost_usd: Option<f64>Total cost in USD
context: Option<i64>Current context window usage (raw token count)
n_hook_events: u32Cumulative count of hook events (enables priority logic)
n_otel_events: u32Cumulative count of OTEL events (enables priority logic)
transcript_available: boolWhether transcript has been successfully parsed
transcript_path: Option<String>Full absolute path to transcript file
Implementations§
Source§impl Session
impl Session
Sourcepub fn is_process_running(&self) -> bool
pub fn is_process_running(&self) -> bool
Check if the session’s process is still running.
Returns true if the session has a PID and that process is still alive.
Returns false if there’s no PID or the process is not running.
Sourcepub fn total_tokens(&self) -> i64
pub fn total_tokens(&self) -> i64
Total tokens across all categories
Sourcepub fn duration(&self) -> Duration
pub fn duration(&self) -> Duration
Duration of the session (from first start to last end or last activity)
Sourcepub fn metrics_source(&self) -> &'static str
pub fn metrics_source(&self) -> &'static str
Determine which source currently owns the metrics.
Priority: transcript > otel > hook
Sourcepub fn should_otel_update_tokens(&self) -> bool
pub fn should_otel_update_tokens(&self) -> bool
Whether OTEL events should update token metrics.
OTEL can update tokens only when transcript is not available.
Sourcepub fn should_hook_update_counts(&self) -> bool
pub fn should_hook_update_counts(&self) -> bool
Whether hook events should update message/tool counts.
Hooks can update counts only when transcript is not available.
Check if this session uses a shared process (one process for many sessions).
For frameworks like Cursor IDE, a single long-running process hosts multiple sessions. PID-based liveness detection doesn’t work reliably for these because the process stays alive even after individual sessions end.
Use this to skip PID timestamp validation for shared-process frameworks.