Documentation
¶
Overview ¶
Package processscan is the ports.ProcessSource adapter that detects running `claude` CLI processes by parsing their argv for the `--session-id <UUID>` flag.
Why scan processes at all ------------------------- The TUI wants to mark a session as "live" so it earns a tab in the title-bar strip. A session whose JSONL was just appended to is trivially live (mtime within the activity window). But a session the user resumed via `claude --resume` and then left idle has a stale mtime — the `claude` process is alive, waiting for input, yet the file looks dead. Without a process probe, that session drops out of the tab strip after ~90s and the user has no way to switch back to it short of re-running `/resume`.
Cwd filtering — by construction, not by code here ------------------------------------------------- This adapter does NOT know or care what cwd a `claude` process was started in. The caller (livesession.applySessionStats) intersects the returned set of session IDs with the per-cwd session list it already has from SessionSource.Sessions(cwd). A process whose session JSONL lives under a different project's encoded dir simply won't be in that per-cwd list, so even if its ID appears in our scan it has no effect on the current view. Keeping cwd resolution out of this package keeps it portable + trivial to test.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source is the ports.ProcessSource implementation. Holds a small time-windowed cache so the snapshot loop's 1Hz polling doesn't fork a fresh `ps` every tick — see processCacheTTL.
func New ¶
func New() *Source
New constructs a Source. The returned value is safe to share across goroutines.
func (*Source) RunningClaudeSessionIDs ¶
RunningClaudeSessionIDs scans the OS process list and returns every session.ID that appears in a live `claude` command line. Empty slice + nil error means "no claude processes running".
Calls within processCacheTTL of the last successful scan return the cached result without forking a new process. The cached slice is shared across callers — treat the returned slice as read-only.
Implementation: `ps -axo command=` is POSIX-portable on macOS and Linux and prints one row per process containing the full argv with no header. We grep for "claude" + "--session-id" first as a cheap pre-filter, then run the regex only on candidates. Duplicate IDs (same session reported twice — shouldn't happen but just in case) are de-duplicated.