pub struct HistoryRoot { /* private fields */ }Expand description
Root directory of Claude Code’s on-disk history. Defaults to
~/.claude/projects; override with HistoryRoot::at for
tests or non-default installs.
Implementations§
Source§impl HistoryRoot
impl HistoryRoot
Sourcepub fn home() -> Result<Self>
pub fn home() -> Result<Self>
Resolve the default ~/.claude/projects. Errors if $HOME
(or the platform-specific user home) cannot be determined.
Sourcepub fn at(path: impl Into<PathBuf>) -> Self
pub fn at(path: impl Into<PathBuf>) -> Self
Use a specific path as the projects root. Useful for tests (point at a tempdir) and for non-default installs.
Sourcepub fn list_projects(&self) -> Result<Vec<ProjectSummary>>
pub fn list_projects(&self) -> Result<Vec<ProjectSummary>>
List every project directory at the root, sorted by slug.
Convenience wrapper around Self::list_projects_with with
ListOptions::default (no limit, no offset, name-ascending
sort, includes empty projects). Existing callers keep their
behavior; new callers wanting pagination or recency sort
should use Self::list_projects_with.
Returns an empty vec if the root directory doesn’t exist.
Sourcepub fn list_projects_with(
&self,
opts: &ListOptions,
) -> Result<Vec<ProjectSummary>>
pub fn list_projects_with( &self, opts: &ListOptions, ) -> Result<Vec<ProjectSummary>>
List project directories with filter / sort / pagination.
Reads every direct child directory of the root, summarizes each, then applies (in order):
- Filter out empty projects (
session_count == 0) whenopts.include_emptyisfalse. - Sort by
opts.sort(ListSort::NameAscby default,ListSort::RecencyDescfor “most recent first”). - Skip the first
opts.offsetitems. - Truncate to
opts.limititems.
Returns an empty vec if the root directory doesn’t exist.
Sourcepub fn list_sessions(&self, slug: Option<&str>) -> Result<Vec<SessionSummary>>
pub fn list_sessions(&self, slug: Option<&str>) -> Result<Vec<SessionSummary>>
List sessions, optionally filtered to one project’s slug,
sorted by session id.
Convenience wrapper around Self::list_sessions_with with
ListOptions::default.
Sourcepub fn list_sessions_with(
&self,
slug: Option<&str>,
opts: &ListOptions,
) -> Result<Vec<SessionSummary>>
pub fn list_sessions_with( &self, slug: Option<&str>, opts: &ListOptions, ) -> Result<Vec<SessionSummary>>
List sessions with filter / sort / pagination.
When slug is Some, only that project is walked. When
None, every project directory is unioned. The options
pipeline is the same as Self::list_projects_with:
filter empty (message_count == 0) sessions unless
opts.include_empty, sort, then offset + limit.
Sourcepub fn read_session(&self, session_id: &str) -> Result<SessionLog>
pub fn read_session(&self, session_id: &str) -> Result<SessionLog>
Read one session’s full entry log.
Walks every project directory looking for <session_id>.jsonl.
Errors with Error::History if no session file matches.
Malformed lines are skipped with a tracing warning.
Sourcepub fn find_session(
&self,
session_id: &str,
) -> Result<Option<(PathBuf, String)>>
pub fn find_session( &self, session_id: &str, ) -> Result<Option<(PathBuf, String)>>
Locate the on-disk path for a session id, plus its project
slug. Returns Ok(None) if no such session exists. Useful
when a caller wants to read with non-default semantics
(streaming, tailing, etc.) without going through
Self::read_session.
Trait Implementations§
Source§impl Clone for HistoryRoot
impl Clone for HistoryRoot
Source§fn clone(&self) -> HistoryRoot
fn clone(&self) -> HistoryRoot
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more