Documentation
¶
Index ¶
- func CwdToProjectDir(cwd string) string
- func FormatMemory(mem *MemoryInfo) string
- func FormatModelRows(w io.Writer, summary *UsageSummary, grandTotal int) error
- func FormatMultiUsage(w io.Writer, instances []InstanceUsage, now time.Time) error
- func FormatTmuxPanes(w io.Writer, panes []TmuxPane) error
- func FormatUsage(w io.Writer, summary *UsageSummary, now time.Time) error
- func Install(w io.Writer, fw FileWriter, personal bool) error
- func InstallHooks(w io.Writer, fw FileWriter) error
- func MergeUsage(dst, src *UsageSummary)
- func ShortProjectName(cwd string) string
- func WindowEnd(start time.Time) time.Time
- func WindowStart(now time.Time) time.Time
- type ByteWalker
- type CombinedFinder
- type CommChecker
- type CommandRunner
- type ContainerChecker
- type ContainerInfo
- type CwdResolver
- type DirWalker
- type DockerClient
- type DockerFinder
- type FileSessionResolver
- type FileWriter
- type HostFinder
- type Instance
- type InstanceFinder
- type InstanceState
- type InstanceUsage
- type MemoryInfo
- type ModelUsage
- type OSCommandRunner
- type OSDirWalker
- type OSFileWriter
- type OSProcessLister
- type OSTmuxClient
- type ProcContainerChecker
- type ProcCwdResolver
- type ProcessInfo
- type ProcessLister
- type SessionResolver
- type TmuxClient
- type TmuxPane
- type UsageSummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CwdToProjectDir ¶ added in v0.13.0
CwdToProjectDir converts an absolute cwd to the Claude project subdir name. e.g. "/home/user/project" -> "-home-user-project"
func FormatMemory ¶ added in v0.13.0
func FormatMemory(mem *MemoryInfo) string
func FormatModelRows ¶ added in v0.13.0
func FormatModelRows(w io.Writer, summary *UsageSummary, grandTotal int) error
func FormatMultiUsage ¶ added in v0.12.0
FormatMultiUsage writes per-instance and aggregated total usage.
func FormatTmuxPanes ¶ added in v0.12.0
FormatTmuxPanes writes the tmux pane listing to w.
func FormatUsage ¶ added in v0.11.0
FormatUsage writes the usage summary to w.
func Install ¶
func Install(w io.Writer, fw FileWriter, personal bool) error
Install writes the Claude Code skill and agent files to disk. When personal is true, files are written under ~/.claude/ instead of .claude/.
func InstallHooks ¶ added in v0.13.0
func InstallHooks(w io.Writer, fw FileWriter) error
InstallHooks writes the hook script and registers hooks in ~/.claude/settings.json.
func MergeUsage ¶ added in v0.12.0
func MergeUsage(dst, src *UsageSummary)
MergeUsage adds all model usage from src into dst.
func ShortProjectName ¶ added in v0.13.0
ShortProjectName returns the last two path components for a readable label. e.g. "/home/user/dev/myproject" -> "dev/myproject"
Types ¶
type ByteWalker ¶ added in v0.12.0
type ByteWalker struct {
Data []byte
}
ByteWalker implements DirWalker over in-memory bytes (one JSONL line per text line).
type CombinedFinder ¶ added in v0.12.0
type CombinedFinder struct {
Finders []InstanceFinder
}
CombinedFinder aggregates multiple InstanceFinders, logging and skipping failures.
func (*CombinedFinder) FindInstances ¶ added in v0.12.0
func (c *CombinedFinder) FindInstances(ctx context.Context) ([]Instance, error)
type CommChecker ¶ added in v0.13.0
CommChecker verifies a process command name.
type CommandRunner ¶ added in v0.12.0
type CommandRunner interface {
Run(ctx context.Context, name string, args ...string) ([]byte, error)
}
CommandRunner abstracts running external commands for testability.
type ContainerChecker ¶ added in v0.13.0
ContainerChecker determines whether a process is running inside a container.
type ContainerInfo ¶ added in v0.12.0
ContainerInfo holds minimal container metadata.
type CwdResolver ¶ added in v0.13.0
CwdResolver resolves the current working directory for a process.
type DockerClient ¶ added in v0.12.0
type DockerClient interface {
ListContainers(ctx context.Context) ([]ContainerInfo, error)
Exec(ctx context.Context, containerID string, cmd []string) (int, io.Reader, error)
ContainerStats(ctx context.Context, containerID string) (*MemoryInfo, error)
Close() error
}
DockerClient abstracts Docker operations for testability.
func NewEngineDockerClient ¶ added in v0.12.0
func NewEngineDockerClient() (DockerClient, error)
NewEngineDockerClient creates a DockerClient backed by the Docker Engine API.
type DockerFinder ¶ added in v0.12.0
type DockerFinder struct {
Client DockerClient
CacheTTL time.Duration // TTL for container data cache; defaults to 2s
// contains filtered or unexported fields
}
DockerFinder discovers Claude Code instances inside Docker containers.
func (*DockerFinder) FindInstances ¶ added in v0.12.0
func (d *DockerFinder) FindInstances(ctx context.Context) ([]Instance, error)
type FileSessionResolver ¶ added in v0.13.0
type FileSessionResolver struct {
HomeDir string
}
FileSessionResolver reads session info from ~/.claude/sessions/<PID>.json.
func (FileSessionResolver) ResolveSessionID ¶ added in v0.13.0
func (r FileSessionResolver) ResolveSessionID(pid int) (string, error)
type FileWriter ¶
type FileWriter interface {
MkdirAll(path string, perm os.FileMode) error
WriteFile(name string, data []byte, perm os.FileMode) error
ReadFile(name string) ([]byte, error)
}
FileWriter abstracts filesystem operations for testability.
type HostFinder ¶ added in v0.12.0
type HostFinder struct {
Runner CommandRunner
HomeDir string // override for testing; empty uses os.UserHomeDir result passed externally
CwdResolver CwdResolver // nil defaults to ProcCwdResolver
ContainerChecker ContainerChecker // nil defaults to ProcContainerChecker
SessionResolver SessionResolver // nil defaults to FileSessionResolver{HomeDir: h.HomeDir}
CommChecker CommChecker // nil defaults to verifyProcComm
}
HostFinder discovers Claude Code instances on the local host via pgrep.
func (*HostFinder) FindInstances ¶ added in v0.12.0
func (h *HostFinder) FindInstances(ctx context.Context) ([]Instance, error)
type Instance ¶ added in v0.12.0
type Instance struct {
Label string // e.g. "Host (PID 7046)" or `Container "dev-myapp" (abc123)`
Source string // "host" or "container"
Walker DirWalker // how to read its JSONL data
Root string // JSONL root path (or virtual path for containers)
Memory *MemoryInfo // memory usage (containers only)
ContainerID string // full Docker container ID (containers only)
PID int // host PID of the claude process (0 for containers)
FilePath string // resolved JSONL path for fsnotify (host instances only)
}
Instance represents a discovered Claude Code instance.
type InstanceFinder ¶ added in v0.12.0
InstanceFinder discovers running Claude Code instances.
type InstanceState ¶ added in v0.12.0
type InstanceState int
InstanceState represents whether a Claude Code instance is busy or ready.
const ( StateUnknown InstanceState = iota StateBusy StateReady )
func (InstanceState) String ¶ added in v0.12.0
func (s InstanceState) String() string
type InstanceUsage ¶ added in v0.12.0
type InstanceUsage struct {
Instance Instance
Summary *UsageSummary
State InstanceState
}
InstanceUsage pairs an Instance with its calculated usage.
func CollectInstanceUsage ¶ added in v0.13.0
func CollectInstanceUsage(instances []Instance, now time.Time) []InstanceUsage
CollectInstanceUsage calculates usage for each instance and returns results.
type MemoryInfo ¶ added in v0.12.0
type MemoryInfo struct {
Usage uint64 // current memory usage in bytes
Limit uint64 // memory limit in bytes (0 = unlimited)
}
MemoryInfo holds memory usage and limit for a container.
type ModelUsage ¶ added in v0.11.0
ModelUsage holds aggregated token counts for one model class.
func (*ModelUsage) Total ¶ added in v0.13.0
func (mu *ModelUsage) Total() int
Total returns the sum of all token fields.
type OSCommandRunner ¶ added in v0.12.0
type OSCommandRunner struct{}
OSCommandRunner implements CommandRunner using os/exec.
type OSDirWalker ¶ added in v0.11.0
type OSDirWalker struct{}
OSDirWalker implements DirWalker using the real filesystem.
type OSFileWriter ¶
type OSFileWriter struct{}
OSFileWriter implements FileWriter using the os package.
type OSProcessLister ¶ added in v0.12.0
type OSProcessLister struct {
Runner CommandRunner
}
OSProcessLister implements ProcessLister using ps.
func (*OSProcessLister) ListProcesses ¶ added in v0.12.0
func (l *OSProcessLister) ListProcesses(ctx context.Context) ([]ProcessInfo, error)
ListProcesses returns all processes with their PID, PPID, command name, and args.
type OSTmuxClient ¶ added in v0.12.0
type OSTmuxClient struct {
Runner CommandRunner
}
OSTmuxClient implements TmuxClient using the real tmux command.
type ProcContainerChecker ¶ added in v0.13.0
type ProcContainerChecker struct{}
ProcContainerChecker reads /proc/<pid>/cgroup to detect containerized processes.
func (ProcContainerChecker) IsContainerized ¶ added in v0.13.0
func (ProcContainerChecker) IsContainerized(pid int) bool
type ProcCwdResolver ¶ added in v0.13.0
type ProcCwdResolver struct{}
ProcCwdResolver reads /proc/<pid>/cwd (Linux).
func (ProcCwdResolver) ResolveCwd ¶ added in v0.13.0
func (ProcCwdResolver) ResolveCwd(pid int) (string, error)
type ProcessInfo ¶ added in v0.12.0
type ProcessInfo struct {
PID int
PPID int
Comm string
Args string // full command line (may be empty)
}
ProcessInfo holds PID, parent PID, command name, and full argument line.
type ProcessLister ¶ added in v0.12.0
type ProcessLister interface {
ListProcesses(ctx context.Context) ([]ProcessInfo, error)
}
ProcessLister abstracts listing all processes with PID, PPID, and command info.
type SessionResolver ¶ added in v0.13.0
SessionResolver resolves the session ID for a Claude process.
type TmuxClient ¶ added in v0.12.0
TmuxClient abstracts listing tmux panes for testability.
type TmuxPane ¶ added in v0.12.0
type TmuxPane struct {
PID int
SessionName string
WindowIndex int
PaneIndex int
Cwd string // pane working directory
Devcontainer bool // true when claude runs inside a devcontainer in this pane
ContainerID string // matched container ID (only set when Devcontainer is true)
ClaudePID int // PID of the actual claude process (0 if unknown)
State InstanceState // busy/ready/unknown
}
TmuxPane represents a tmux pane with an active Claude process.
func FindClaudePanes ¶ added in v0.12.0
func FindClaudePanes(ctx context.Context, client TmuxClient, lister ProcessLister, claudeContainerIDs []string) ([]TmuxPane, error)
FindClaudePanes discovers tmux panes that have a Claude process running in them. It lists all tmux panes, builds a process tree from ps output, and checks each pane's descendant processes for a "claude" command or a "docker exec" into a container known to run Claude (identified by claudeContainerIDs).
type UsageSummary ¶ added in v0.11.0
type UsageSummary struct {
Models map[string]*ModelUsage
}
UsageSummary holds the full usage breakdown for the current window.
func CalculateUsage ¶ added in v0.11.0
CalculateUsage scans JSONL files under root and returns usage broken down by model.