live

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 13 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 live decides what is running: Claude Code's live-session registry, the state word a hook left, and how long a session's transcript has been quiet. The rules are the bash ones (live_ids, deadp, tquiet and stext in bin/sitrep).

Index

Constants

View Source
const (
	BlockPermission = "permission"
)

Block kinds a hook records.

View Source
const BlockedSlack = 3

BlockedSlack is how long after a block the transcript may still be written, in seconds: Claude Code writes it once, 0.3 s after a dialog opens.

View Source
const Grace = 120

Grace is how long a session that is not in the registry may stay quiet before it counts as over: the registry lags a start and a /clear.

View Source
const IdleAfter = 600

IdleAfter is how long a working session's transcript may stay quiet before the session is shown as idle?.

Variables

This section is empty.

Functions

func Age

func Age(secs int64) string

Age writes seconds as <1m, 5m, 3h or 2d.

func AttachClients added in v1.3.3

func AttachClients(procs []Proc, sessionID string) []int

AttachClients finds the `claude attach <prefix>` processes that show the session. The argument is a prefix of the session id; a client counts only if it names this session.

func Blocked added in v1.0.0

func Blocked(s state.Store, configDir, id, word string, now int64) (kind string, at int64, ok bool)

Blocked says whether a session is stopped at a dialog, and since when (seconds since the epoch). The permission hook wrote the file `blocked`; the block counts only while the session is working and its transcript has not been written since, so that an answered dialog and a crash leave nothing behind once the next transcript line is written, which for a long tool is when it finishes. A session without a readable transcript keeps the block until the file is removed.

func Changed

func Changed(s state.Store, id string) (int64, bool)

Changed is when a session's state last changed, in seconds since the epoch: the state file's time, else the notes file's.

func Clients added in v1.3.3

func Clients(procs []Proc, set Set, next func(id string) (string, bool)) map[string][]int

Clients maps each live background session to the pids of the terminal clients that show it. next gives the session that a resume moved a conversation into.

func ContinuedIn added in v1.3.3

func ContinuedIn(configDir, id string) (string, bool)

ContinuedIn is the session that a resume moved a conversation into, from the end of the old transcript.

func Continues added in v1.3.3

func Continues(configDir, from, to string) bool

Continues says whether the conversation of from was resumed, through one or more continued-in links, as to.

func Dead

func Dead(set Set, id, word string, changed, now int64) bool

Dead says whether a session is over. With a readable registry a live process settles it; otherwise the session is over once it said so, or after two quiet minutes. Without a registry only its own word counts.

func IsIdle added in v1.1.0

func IsIdle(word string, quiet int64, hasQuiet bool) bool

IsIdle says whether a working session's transcript has been quiet long enough for it to be shown as idle?.

func Label

func Label(word string, changed, now int64, quiet int64, hasQuiet bool) string

Label is the state column: "waiting 3m". A working session whose transcript has been quiet for ten minutes is "idle? 12m".

func LocalDomain

func LocalDomain() string

LocalDomain is how Claude Code names this machine's pid space.

func Quiet

func Quiet(configDir, id string, now int64) (int64, bool)

Quiet is how many seconds the session's transcript has been unchanged (the shortest, if there are several). An interrupt fires no Stop hook, but the transcript still shows life.

func Word

func Word(s state.Store, id string) string

Word is a session's state word from the file a hook wrote, from an allow-list (the file is untrusted input), else "-".

Types

type Entry

type Entry struct {
	ID  state.ID
	PID int
	// Bg is true for a background session (kind "bg"), which has no terminal of its own. BgIdle is true when the registry also calls it
	// idle.
	Bg, BgIdle bool
}

Entry is one live session. PID is 0 when the process is in another pid space and cannot be judged here.

type Proc added in v1.3.3

type Proc struct {
	PID, PPID int
	Args      []string
}

Proc is one line of `ps -A -o pid=,ppid=,command=`.

func ParseProcs added in v1.3.3

func ParseProcs(out string) []Proc

ParseProcs reads the output of `ps -A -o pid=,ppid=,command=`.

type Registry

type Registry struct {
	Dir    string        // the sessions folder
	Run    runner.Runner // for ps
	Alive  func(pid int) bool
	Domain string // how Claude Code names this machine's pid space; empty when it cannot be worked out
}

Registry reads ~/.claude/sessions/<pid>.json. Its files are untrusted input, so everything used is checked.

func NewRegistry

func NewRegistry(configDir string, run runner.Runner) Registry

NewRegistry is the registry of a Claude config folder, with the real process checks.

func (Registry) Read

func (r Registry) Read(ctx context.Context) Set

Read lists the live sessions. OK is false when the registry holds no file, or no live session.

type Set

type Set struct {
	Entries []Entry
	OK      bool
}

Set is what the registry says is live. OK is false when nothing live could be read, which means the registry cannot be trusted either way.

func (Set) AnyBg added in v1.3.3

func (s Set) AnyBg() bool

AnyBg says whether a background session is live.

func (Set) Bg added in v1.3.3

func (s Set) Bg(id string) bool

Bg says whether the registry shows this session as a background session.

func (Set) BgIdle added in v1.3.3

func (s Set) BgIdle(id string) bool

BgIdle says whether the registry shows this session as an idle background session.

func (Set) Has

func (s Set) Has(id string) bool

Has says whether a live process has this session id.

func (Set) PID

func (s Set) PID(id string) (int, bool)

PID is the first live process of a session, when it runs on this machine.

Jump to

Keyboard shortcuts

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