session

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package session defines the provider-agnostic model of a coding session.

Index

Constants

View Source
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

View Source
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.

View Source
var ErrCoworkRename = errors.New("cowork session: rename it in Claude Desktop")

ErrCoworkRename is returned when asked to rename a Cowork session.

Functions

func Age

func Age(t time.Time) string

Age renders a compact relative time: now, 5m, 3h, 2d, 4mo.

func Clip

func Clip(s string, n int) string

Clip collapses newlines and truncates to n runes with an ellipsis.

func RetiredWorktreeRoot added in v0.5.0

func RetiredWorktreeRoot(cwd string) string

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.

func Tilde added in v0.5.0

func Tilde(path, home string) string

Tilde abbreviates a path under home to ~/...

func Tokens added in v0.2.0

func Tokens(n int) string

Tokens renders a token count compactly: 850, 12k, 140k, 1.2M.

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

func Find(sessions []*Session, q string) *Session

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) Empty

func (s *Session) Empty() bool

Empty is true when nobody ever typed a prompt.

func (*Session) Named

func (s *Session) Named() bool

Named reports whether the user gave this session a name with /rename.

func (*Session) OpenDir added in v0.5.0

func (s *Session) OpenDir(home string) string

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) Repo

func (s *Session) Repo() string

Repo is the folder name of the working directory.

func (*Session) ShortID

func (s *Session) ShortID() string

ShortID is the 8-char prefix Claude Code itself prints.

func (*Session) Title

func (s *Session) Title() string

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

func (s *Session) WillOfferSummary(now time.Time) bool

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".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL