helpers
Class info¶
🛈 DocStrings¶
Claude Code storage provider.
See ARCHITECTURE.md for detailed documentation of the storage format.
count_session_messages
¶
Count user/assistant messages in a session without full validation.
Only parses JSON to check the 'type' field, skipping Pydantic validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_path
|
Path
|
Path to the JSONL session file |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of user/assistant message entries |
Source code in src/clawd_code_sdk/storage/helpers.py
decode_project_path
¶
Decode a Claude project path back to filesystem path (best effort).
The encoding is lossy ('-', '.', '_' and '/' all become '-'), so this is only
a guess; prefer the cwd recorded in the session's entries.
Example: -home-user-project -> /home/user/project
Source code in src/clawd_code_sdk/storage/helpers.py
encode_project_path
¶
Encode a project path to Claude's format (see :func:path_to_claude_dir_name).
Example: /home/user/.config/project -> -home-user--config-project
Source code in src/clawd_code_sdk/storage/helpers.py
extract_title
¶
Extract a display title from a session file without parsing all of it.
Reads only the head and tail of the file. Preference order: the last
user-set title (custom-title), the last AI-generated title
(ai-title), a legacy summary entry, then the first meaningful
user prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_path
|
Path
|
Path to the JSONL session file |
required |
max_chars
|
int
|
Maximum characters for title (truncates with '...') |
60
|
Returns:
| Type | Description |
|---|---|
str | None
|
Extracted title or None if no suitable content found |
Source code in src/clawd_code_sdk/storage/helpers.py
get_claude_data_dir
¶
Get the Claude Code data directory ($CLAUDE_CONFIG_DIR, default ~/.claude).
Source code in src/clawd_code_sdk/storage/helpers.py
get_claude_projects_dir
¶
get_latest_session
¶
Get the path for the most recent session file for given project if existing.
Source code in src/clawd_code_sdk/storage/helpers.py
list_project_session_files
¶
List all session files for given project path, sorted by modification time (newest first).
Source code in src/clawd_code_sdk/storage/helpers.py
path_to_claude_dir_name
¶
Convert a filesystem path to Claude Code's project directory name.
Claude Code replaces every non-alphanumeric character with '-', so '/home/user/my.project' becomes '-home-user-my-project'. Names longer than 200 characters are truncated and get a hash suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str
|
The filesystem path |
required |
Returns:
| Type | Description |
|---|---|
str
|
The Claude Code directory name format |
Source code in src/clawd_code_sdk/storage/helpers.py
read_session
¶
read_session(session_path: Path) -> list[ClaudeJSONLEntry]
Read all entries from a session file.
Source code in src/clawd_code_sdk/storage/helpers.py
write_entry
¶
write_entry(session_path: Path, entry: ClaudeJSONLEntry) -> None
Append an entry to a session file.