session

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsResumeStale added in v0.2.1

func IsResumeStale(cwd, sessionID string, maxAge time.Duration) (bool, time.Duration, error)

IsResumeStale reports whether the session jsonl at JSONLPath(cwd, sessionID) has not been written in at least maxAge. Returns (false, 0, nil) if the file does not exist — claude will create it, so we should not drop --resume just because the file is missing.

func JSONLPath added in v0.2.1

func JSONLPath(cwd, sessionID string) (string, error)

JSONLPath returns the absolute path to claude's session jsonl for the given cwd + sessionID. Resolves "~" via os.UserHomeDir.

func LatestSession added in v0.4.2

func LatestSession(cwd string, maxAge time.Duration) (string, time.Time, error)

LatestSession returns the session ID of the most recently modified <session>.jsonl in claude's project directory for cwd. It mirrors what `/resume` inside claude would show at the top of the list: the session the user was most recently in for this working directory.

Returns ("", zero time, nil) when:

  • the project directory does not yet exist (brand-new workspace)
  • no .jsonl files are present
  • maxAge > 0 and the newest file is older than maxAge

Other filesystem errors are surfaced.

func NewID

func NewID() string

NewID generates a random UUID v4 string. Panics if the system's cryptographic random source is unavailable.

func ProjectSlug added in v0.2.1

func ProjectSlug(cwd string) string

ProjectSlug returns claude's project slug for a working directory. The slug is the folder name under ~/.claude/projects/ that holds <session-id>.jsonl files for sessions launched with that cwd.

Types

type Entry

type Entry struct {
	SessionID string    `json:"session_id"`
	UpdatedAt time.Time `json:"updated_at"`
}

Entry represents a stored session mapping.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages session ID persistence in a JSON file.

func NewStore

func NewStore(workspace string) *Store

NewStore creates a Store backed by <workspace>/state/sessions.json.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes a session mapping by key.

func (*Store) DeleteAll

func (s *Store) DeleteAll() error

DeleteAll removes all stored sessions.

func (*Store) Get

func (s *Store) Get(key string) (string, bool, error)

Get returns the session ID for the given key, or empty string if not found.

func (*Store) List

func (s *Store) List() (map[string]Entry, error)

List returns all stored session entries.

func (*Store) Set

func (s *Store) Set(key string, sessionID string) error

Set stores a session ID for the given key.

Jump to

Keyboard shortcuts

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