Skip to main content

ClaudeSession

Struct ClaudeSession 

Source
pub struct ClaudeSession {
Show 67 fields pub pid: u32, pub session_id: String, pub cwd: String, pub project_name: String, pub started_at: u64, pub elapsed: Duration, pub tty: String, pub status: SessionStatus, pub cpu_percent: f32, pub cpu_history: Vec<f32>, pub mem_mb: f64, pub own_input_tokens: u64, pub own_output_tokens: u64, pub own_cache_read_tokens: u64, pub own_cache_write_tokens: u64, pub subagent_input_tokens: u64, pub subagent_output_tokens: u64, pub subagent_cache_read_tokens: u64, pub subagent_cache_write_tokens: u64, pub total_input_tokens: u64, pub total_output_tokens: u64, pub model: String, pub command_args: String, pub session_name: String, pub jsonl_path: Option<PathBuf>, pub jsonl_offset: u64, pub last_message_ts: u64, pub cache_read_tokens: u64, pub cache_write_tokens: u64, pub cost_usd: f64, pub context_tokens: u64, pub context_max: u64, pub prev_cost_usd: f64, pub burn_rate_per_hr: f64, pub subagent_count: usize, pub active_subagent_count: usize, pub active_subagent_jsonl_paths: Vec<PathBuf>, pub subagent_rollups: HashMap<PathBuf, SubagentRollup>, pub activity_history: Vec<u8>, pub files_modified: HashMap<String, u32>, pub tool_usage: HashMap<String, ToolStats>, pub worktree_id: Option<String>, pub telemetry_status: TelemetryStatus, pub usage_metrics_available: bool, pub cost_estimate_unverified: bool, pub model_profile_source: String, pub last_msg_type: String, pub last_stop_reason: String, pub is_waiting_for_task: bool, pub pending_tool_name: Option<String>, pub pending_tool_input: Option<String>, pub pending_file_path: Option<String>, pub has_file_conflict: bool, pub last_tool_error: bool, pub last_error_message: Option<String>, pub recent_errors: Vec<ErrorEntry>, pub total_tokens_at_edit_count: u64, pub edit_event_count: u32, pub baseline_tokens_per_edit: Option<f64>, pub error_counts_per_window: Vec<u32>, pub current_window_errors: u32, pub window_tick_counter: u32, pub baseline_error_rate: Option<f64>, pub file_reads_since_edit: HashMap<String, u32>, pub total_error_count: u32, pub decay_score: u32, pub worker_origin: Option<String>,
}

Fields§

§pid: u32§session_id: String§cwd: String§project_name: String§started_at: u64§elapsed: Duration§tty: String§status: SessionStatus§cpu_percent: f32§cpu_history: Vec<f32>§mem_mb: f64§own_input_tokens: u64§own_output_tokens: u64§own_cache_read_tokens: u64§own_cache_write_tokens: u64§subagent_input_tokens: u64§subagent_output_tokens: u64§subagent_cache_read_tokens: u64§subagent_cache_write_tokens: u64§total_input_tokens: u64§total_output_tokens: u64§model: String§command_args: String§session_name: String§jsonl_path: Option<PathBuf>§jsonl_offset: u64§last_message_ts: u64§cache_read_tokens: u64§cache_write_tokens: u64§cost_usd: f64§context_tokens: u64§context_max: u64§prev_cost_usd: f64§burn_rate_per_hr: f64§subagent_count: usize§active_subagent_count: usize§active_subagent_jsonl_paths: Vec<PathBuf>§subagent_rollups: HashMap<PathBuf, SubagentRollup>§activity_history: Vec<u8>§files_modified: HashMap<String, u32>§tool_usage: HashMap<String, ToolStats>§worktree_id: Option<String>§telemetry_status: TelemetryStatus§usage_metrics_available: bool§cost_estimate_unverified: bool§model_profile_source: String§last_msg_type: String

Persisted across ticks so status inference works when no new JSONL arrives.

§last_stop_reason: String§is_waiting_for_task: bool§pending_tool_name: Option<String>

Pending tool call details for rule-based auto-actions.

§pending_tool_input: Option<String>§pending_file_path: Option<String>§has_file_conflict: bool§last_tool_error: bool§last_error_message: Option<String>§recent_errors: Vec<ErrorEntry>§total_tokens_at_edit_count: u64

Cumulative tokens at each Edit/Write event (for efficiency trending).

§edit_event_count: u32

Number of Edit/Write events (for averaging tokens-per-edit).

§baseline_tokens_per_edit: Option<f64>

Baseline tokens-per-edit, frozen after first 5 edits.

§error_counts_per_window: Vec<u32>

Error count ring buffer: one entry per window (~10s each).

§current_window_errors: u32

Accumulator for current error window.

§window_tick_counter: u32

Ticks since last window flush.

§baseline_error_rate: Option<f64>

Baseline error rate (errors per window), frozen after 3 windows.

§file_reads_since_edit: HashMap<String, u32>

File reads since last edit: path -> read count. Reset when file is edited.

§total_error_count: u32

All-time error count.

§decay_score: u32

Cached composite decay score (0-100), recomputed each tick.

§worker_origin: Option<String>

If set, this session is from a remote worker (not local). Terminal actions (approve, kill, etc.) are disabled for remote sessions.

Implementations§

Source§

impl ClaudeSession

Source

pub fn from_raw(raw: RawSession) -> Self

Source

pub fn record_activity(&mut self)

Record current status into the activity sparkline ring buffer. Max 15 entries (one per tick, at 2s default = 30s of history).

Source

pub fn format_sparkline(&self) -> String

Render the sparkline as unicode block characters.

Source

pub fn display_name(&self) -> &str

Source

pub fn is_remote(&self) -> bool

Whether this session is from a remote worker (not local).

Source

pub fn from_remote_json(worker_id: &str, json: &Value) -> Option<Self>

Build a ClaudeSession from remote JSON (as received via heartbeat/HTTP).

Source

pub fn format_subagent_summary(&self) -> String

Source

pub fn subagent_breakdown(&self) -> Vec<SubagentBreakdown>

Source

pub fn format_elapsed(&self) -> String

Source

pub fn format_tokens(&self) -> String

Source

pub fn format_mem(&self) -> String

Source

pub fn format_cost(&self) -> String

Source

pub fn context_percent(&self) -> f64

Source

pub fn format_context(&self) -> String

Format context as “450k/1M 45%” or a visual bar

Source

pub fn format_context_bar(&self, width: usize) -> String

Visual bar for context usage: ████░░ 62%

Source

pub fn to_json_value(&self) -> Value

Produce a JSON-serializable value for –json export.

Source

pub fn format_burn_rate(&self) -> String

Source

pub fn telemetry_label(&self) -> &'static str

Source

pub fn has_usage_metrics(&self) -> bool

Trait Implementations§

Source§

impl Clone for ClaudeSession

Source§

fn clone(&self) -> ClaudeSession

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ClaudeSession

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.