Skip to content
claudewheel.session_rows
Edit
On this page

Turns a session registry record into a fixed-height block of lines for the deletion checklist, and marks the row belonging to the session the reader is sitting in.

#claudewheel.session_rows

#claudewheel.session_rows

Render one session registry record as a block of lines, collapsed or expanded.

The block form the deletion checklist lists the processes holding a profile in (through :mod:claudewheel.session_list): a :class:~claudewheel.session_registry.SessionRecord in, a tuple of plain text lines out, with no colour, no terminal and no clock of its own. :func:format_uptime and the identity helpers below are shared more widely -- the machine-wide sessions table reads them too, though it draws its own rows.

Block heights are fixed per state, because they are what :func:claudewheel.vertical_viewport.compute_viewport scrolls over:

================= ====================================================== Collapsed two lines -- a header and one summary line Collapsed + state three lines -- the state line is the checklist's indicator Highlighted five lines -- header, directory, identity, resources, and the state line (blank when the row carries no state) =============== ========================================================

Nothing a record may be missing changes those counts: an absent directory, version or start time changes what a line says, never how many there are.

The current session -------------------

Claude Code exports its own identity into every process it starts, and the registry file records the same two values. CLAUDE_CODE_SESSION_ID is the session's UUID (the record's sessionId) and CLAUDE_PID is the process that owns it (the record's pid). A row is marked as this session only when both match: a session id alone would also mark a sibling process of the same session, and a pid alone would mark whatever the kernel handed that recycled number to. If either variable is missing or unusable, no identity is resolved and no row is marked -- claiming the wrong row is worse than claiming none.

The environment is a parameter here, never read from the process: a caller passes os.environ (or a fixture) to :func:current_identity, and the resulting identity is passed down to :func:format_row.

#SessionIdentity

Who the reader is: the session UUID and the pid that owns it.

#current_identity

python
def current_identity(env: Mapping[str, str]) -> SessionIdentity | None

The identity env describes, or None when it does not describe one.

Both values must be present and usable. A missing variable, an empty string, a non-numeric pid and a pid that no process can have all mean "no identity", so nothing is marked rather than the wrong thing being marked.

#is_current

python
def is_current(record: SessionRecord, identity: SessionIdentity | None) -> bool

True when record is the session identity describes.

Both values are compared exactly. A record carrying no session id can never match, and neither can a match on one value alone.

#format_uptime

python
def format_uptime(started_at: int | None, now_ms: int) -> str

How long a session started at started_at has been up, at now_ms.

Both are wall-clock milliseconds, as the registry records them. A record with no start time reads unknown; a start time in the future (a clock stepped between the two readings) reads as no uptime rather than negative.

#format_memory

python
def format_memory(rss_kib: int) -> str

Resident memory, given in KiB as ps -o rss= reports it on both platforms.

#_header

python
def _header(record: SessionRecord, *, prefix: str, current: bool) -> str

The first line: the toggle, the current mark, and what the session is.

#format_row

python
def format_row(record: SessionRecord, *, highlighted: bool, now_ms: int, identity: SessionIdentity | None=None, rss_kib: int | None=None, state: str | None=None, selector: str | None=None) -> tuple[str, ...]

The lines of one row block, two, three or five of them.

highlighted expands the block; state adds (collapsed) or fills (highlighted) the per-row state line the deletion checklist writes its running/stopped indicator into; selector is that checklist's [x] / [ ] toggle, drawn at the left edge with the rest of the block indented under it. rss_kib is the resident memory a caller measured for the pid; omitted, no memory clause is written at all. identity decides the current-session mark and is compared per :func:is_current.

Search