Documentation
¶
Index ¶
- func FormatAge(t time.Time) string
- func FormatTokenCount(n int64) string
- func IsProcessRunning(sessionID string) bool
- func IsProcessRunningInWorktree(binName, sessionID, worktreePath string) bool
- func ProjectDir(worktreePath string) string
- func ProjectDirPath(worktreePath string) string
- func ShortenModel(model string) string
- type Session
- type SessionDetail
- type TokenUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatTokenCount ¶
FormatTokenCount formats a token count in human-readable form (e.g. 1.2K, 3.5M).
func IsProcessRunning ¶
IsProcessRunning checks if a Claude process is running for the given session ID by looking for a process whose command line contains the session ID.
func IsProcessRunningInWorktree ¶ added in v0.11.0
IsProcessRunningInWorktree reports whether an agent process is alive for a worktree. It checks the process's cwd against worktreePath first, falling back to matching sessionID in the process's command line.
The cwd check is the primary signal: a freshly launched session (started without --resume) never carries its own session ID in argv — Claude/Codex generate that ID internally after the process starts — so IsProcessRunning alone reports a false "not running" for every fresh session until it has been resumed at least once. Matching on cwd instead works from the first scan, since zen always launches the agent with the worktree as its working directory.
func ProjectDir ¶ added in v0.7.0
ProjectDir returns the Claude projects directory for a worktree path. Returns empty string if the directory doesn't exist.
func ProjectDirPath ¶ added in v0.10.0
ProjectDirPath returns the Claude projects directory for a worktree path whether or not it exists on disk, so callers can create it (e.g. when migrating a session from another agent).
func ShortenModel ¶
ShortenModel shortens a Claude model identifier. "claude-opus-4-6" -> "opus-4-6", "claude-sonnet-4-5-20250929" -> "sonnet-4-5"
Types ¶
type Session ¶
type Session struct {
ID string `json:"id"`
Path string `json:"path"` // absolute path to the session file on disk
Modified int64 `json:"modified_epoch"`
ModHuman string `json:"modified"`
Size int64 `json:"size"`
SizeStr string `json:"size_str"`
}
Session represents an agent session file (Claude .jsonl or Codex rollout).
func FindSessions ¶
FindSessions finds Claude sessions for a worktree path by scanning ~/.claude/projects/<encoded-path>/*.jsonl files.
type SessionDetail ¶
type SessionDetail struct {
Session
Model string `json:"model"`
Tokens TokenUsage `json:"tokens"`
Running bool `json:"running"`
LastActive time.Time `json:"last_active"`
AgeStr string `json:"age_str"`
}
SessionDetail extends Session with parsed token usage and process status.
type TokenUsage ¶
type TokenUsage struct {
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
CacheCreationInputTokens int64 `json:"cache_creation_input_tokens"`
CacheReadInputTokens int64 `json:"cache_read_input_tokens"`
}
TokenUsage holds aggregated token counts from a session.
func ParseSessionDetailFull ¶
func ParseSessionDetailFull(path string) (model string, tokens TokenUsage, err error)
ParseSessionDetailFull reads the entire session file and sums up all token usage. Slower but accurate for total counts.
func ParseSessionDetailTail ¶
func ParseSessionDetailTail(path string) (model string, tokens TokenUsage, err error)
ParseSessionDetailTail reads the last tailSize bytes of a session file and extracts the model and most recent token usage. This is fast but may not capture all token usage from long sessions.