Help us shape the future of Go! Take the 2026 Go Developer Survey

proc

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package proc finds Claude's process from a hook or the statusline: its pid, its start time with the boot it belongs to, and whether another session started it (design-spec.md, Liveness; implementation-spec.md, Process lookup). The rules are one implementation over a process table (procTable); only the table differs by system: /proc through fsys on Linux (procfs), sysctl through golang.org/x/sys/unix on macOS (sysctlTable). Both tables' parsing builds everywhere, so it is tested on any system. It never starts a process. On other systems it finds nothing.

sesshin-hook links it, so it imports the standard library, sesshin's own hook-path packages, and golang.org/x/sys/unix only, starts no goroutine, and has no init function or package-level initializer that does work (implementation-spec.md, The hook binary).

Index

Constants

View Source
const (
	// ErrNoProcess is StartedAt's error when there is no such process.
	ErrNoProcess constError = "no such process"

	// ErrNoTTY is ControllingTTY's error when the process has no controlling
	// terminal.
	ErrNoTTY constError = "no controlling terminal"
)

Variables

This section is empty.

Functions

func ControllingTTY added in v1.1.0

func ControllingTTY(pid int64) (uint64, error)

ControllingTTY finds nothing on Linux, where no backend asks.

func StartedAt

func StartedAt(fsy fsys.FS, pid int64) (string, error)

StartedAt returns process pid's pid_started_at, for comparing with a stored one. It fails with ErrNoProcess when there is no such process, and with another error when the check itself fails (design-spec.md, Liveness, Unknown).

Types

type Claude

type Claude struct {
	PID int64
	// StartedAt is pid_started_at: linux:<boot_id>:<starttime> or
	// darwin:<boot session>:<sec>.<usec>, compared only for equality.
	StartedAt string
	// Nested is whether another session started this Claude, nil when that
	// couldn't be told.
	Nested *bool
}

Claude is what a lookup found. PID is 0 when it found no Claude, and then StartedAt is "" and Nested nil: pid_started_at is null exactly when pid is (design-spec.md, lifecycle.json).

func Find

func Find(fsy fsys.FS, claudePID string) Claude

Find looks up Claude from this process, a hook or the statusline that Claude started, given CLAUDE_PID from its environment ("" when unset). It reads only the process table, and takes no lock.

func FindCaller

func FindCaller(fsy fsys.FS, claudePID string) Claude

FindCaller looks up the Claude this process, a command, runs under, given CLAUDE_PID from its environment ("" when unset), for the selector self: the nearest ancestor that is CLAUDE_PID or a claude by name.

func FindWith

func FindWith(lookup func(fsys.FS, string) Claude, files fsys.FS, pid string) Claude

FindWith looks up Claude's process with lookup, or with Find when lookup is nil, the seam tests use (hooks-spec.md, Late adoption; statusline step 2).

Jump to

Keyboard shortcuts

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