Documentation
¶
Overview ¶
Package session defines the provider-agnostic model of a coding session.
Index ¶
Constants ¶
const ( SummaryIdle = time.Hour SummaryTokens = 100_000 )
SummaryIdle and SummaryTokens are Claude Code's documented thresholds for the "resume from summary" dialog: idle for about an hour and over 100k tokens.
Variables ¶
var ErrCowork = errors.New("cowork session: open it in Claude Desktop")
ErrCowork is returned when asked to open a Cowork session, which only Claude Desktop may resume.
var ErrCoworkRename = errors.New("cowork session: rename it in Claude Desktop")
ErrCoworkRename is returned when asked to rename a Cowork session.
Functions ¶
func RetiredWorktreeRoot ¶ added in v0.5.0
RetiredWorktreeRoot returns the repo a missing cwd belonged to when that cwd was a Claude Code worktree (<repo>/.claude/worktrees/<name>, or a folder inside one) whose repo still exists. It returns "" for every other path. Callers check that cwd itself is missing; this only looks at the path and the repo.
Types ¶
type Live ¶
type Live struct {
PID int `json:"pid"`
Status string `json:"status"` // "busy", "idle", ...
Name string `json:"name"`
}
Live describes a session that is running right now.
type Message ¶
type Message struct {
Role string `json:"role"` // "user" or "assistant"
Text string `json:"text"`
At time.Time `json:"at"`
}
Message is one line of conversation kept for the preview pane.
type Session ¶
type Session struct {
Provider string `json:"provider"` // "claude"
ID string `json:"id"`
Account string `json:"account"` // label of the config root, e.g. "personal"
Root string `json:"root"` // config dir the session belongs to
Path string `json:"path"` // transcript on disk
CWD string `json:"cwd"` // the last working directory
// Dirs is every distinct working directory the Session had, first seen first.
// For a Cowork Session it also holds the folders the user gave it in Claude Desktop
// and its metadata cwd, added at query time.
Dirs []string `json:"dirs,omitempty"`
Branch string `json:"branch,omitempty"`
CustomTitle string `json:"custom_title,omitempty"`
// DesktopTitle is the title Claude Desktop shows for a Cowork session.
DesktopTitle string `json:"desktop_title,omitempty"`
AITitle string `json:"ai_title,omitempty"`
FirstPrompt string `json:"first_prompt,omitempty"`
Created time.Time `json:"created"`
LastActive time.Time `json:"last_active"`
Messages int `json:"messages"` // user prompts + assistant replies
Sidechain bool `json:"sidechain"`
// Cowork is set for sessions from a Claude Desktop Cowork root. They are read-only to unpause.
Cowork bool `json:"cowork,omitempty"`
// ContextTokens is the context size reported by the last assistant reply
// (input + cache creation + cache read). Zero when unknown.
ContextTokens int `json:"context_tokens,omitempty"`
Preview []Message `json:"preview,omitempty"`
// Filled at query time, never cached.
Live *Live `json:"live,omitempty"`
CWDMissing bool `json:"cwd_missing,omitempty"`
// WorktreeRoot is the repo of a Retired worktree: CWD was a Claude Code worktree
// that has been removed while its repo still exists. Empty otherwise.
WorktreeRoot string `json:"worktree_root,omitempty"`
}
Session is one resumable conversation, regardless of which tool produced it.
func Find ¶ added in v0.6.0
Find resolves what a user typed to one Session: an id prefix first, then an exact Name, then a substring of the Title. Matching ignores case. It returns nil when nothing matches.
func (*Session) OpenDir ¶ added in v0.5.0
OpenDir is the folder a resumed Session should start in: its cwd when that exists, the repo (or the same subfolder of it) for a Retired worktree, else home for an Orphan. Claude Code resumes the transcript regardless of cwd.
func (*Session) Title ¶
Title is the best human name we have: /rename name, else Claude Desktop's title, else Claude's auto title, else the first prompt.
func (*Session) WillOfferSummary ¶ added in v0.2.0
WillOfferSummary predicts whether Claude Code will show the resume-from-summary dialog when this session is resumed at time now. It is a prediction: the thresholds are approximate, it applies to Pro/Max plans only, and it can't see whether the user already chose "Don't ask again".