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.

More tools from this site

  • claudestream Drive Claude Code from Python: run it as a subprocess and read its output as typed events, with async and sync sessions, sandbox policies, and tools you define in Python
  • dirstat Fast, single-binary directory statistics CLI: every file under a tree grouped by format, with counts, sizes, and lines of code, as a colored terminal table or as JSON
  • fastware A batteries-included ASGI framework: msgspec JSON, a managed Granian server, dependency injection, SSE, WebSockets, auth, and a test client
  • go-toml-edit Zero-dep TOML editing library for Go with comment preservation
  • howmuchleft The fastest Claude Code statusline: context window, 5-hour, and weekly limit usage as three customizable gradient bars, rendering in about 6 ms
  • orxtra
  • pgdesign
  • predraw Declarative rendering pipeline: describe a scene in JSON and get SVG, PNG and WebP out, with light and dark style tokens, reusable components and text converted to path outlines
  • reposummary Turn a git repository's history into a Markdown journal: pick a time window or revision range and get a readable digest of what changed, optionally narrated by an LLM
  • rlsbl Release orchestration and project scaffolding CLI that bumps versions, validates a structured JSONL changelog, tags only the commit CI verified, and publishes to npm, PyPI, Go and more
  • safegit git wrapper CLI that gives each commit its own temporary index and retries ref updates on conflict, so concurrent agents share one repository
  • saferm Command-line replacement for rm that archives every deletion with a mandatory reason and the context it ran in, so deleted files can be listed, inspected and restored
  • selfdoc Static Site Generator that builds a project's documentation site directly from its source code, so the docs can never drift from the code they describe, with SEO/AEO, first-class blog, search, and cross-project linking built in
  • strictcli
  • stricttest An always-on test-isolation floor: a pytest plugin and a Go env-hygiene module that make a test suite structurally unable to reach real credentials, the real HOME, the network, or the development repository.
  • wesktop A Python framework that turns an ASGI web app into a desktop application, serving it from a local Granian server and displaying it in a native OS window via pywebview
Search