cctasks

package
v0.234.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cctasks counts what a Claude Code CLI has running beside its turn: its background shells, from the CLI's own process tree, and — with a subagent count its caller reads from the transcript — the work rule that turns both, and the CLI's own session status, into what an agent card may claim (docs/design/agent-cards.md (a), "The work rule").

🔴 IT NEVER CLAIMS MORE THAN IT KNOWS. A count is exact only while no foreground command can be running; whenever one could be (any running turn) the shell count is a lower bound, "1+ shell" (operator decision 3), because a foreground Bash call — or a running subagent's — looks exactly like a background one in the process tree. And with no status at all (no live sessions file) there is no Work: the card shows nothing rather than a stale or guessed number.

The layout relied on, measured on Claude Code 2.1.289 (one host, one sample each — the design's Phase 0 spike is what widens it):

  • every Bash tool call, background or foreground, runs as a descendant of the CLI with fd 1 and fd 2 on its task output file, <tmp>/claude-<uid>/<slug>/<session>/tasks/b<8 base-36>.output;
  • a Monitor task is a DIRECT child of the CLI whose argv names the CLI's shell snapshot (<config>/shell-snapshots/…), with fd 0 /dev/null and fds 1 and 2 sockets — no task output file;
  • a subagent's own symlink in that directory (a<16 hex>.output) is not a process and is never counted;
  • a daemon a task left behind (`nohup … &`) is reparented away from the CLI, so it is not a descendant and not counted — the task is done.

Index

Constants

View Source
const (
	StatusIdle    = "idle"
	StatusShell   = "shell"
	StatusBusy    = "busy"
	StatusWaiting = "waiting"
)

Claude Code's session statuses, as its sessions file writes them RAW — before muster's own mapping folds "shell" into idle (mirror.NormalizeStatus).

Variables

This section is empty.

Functions

This section is empty.

Types

type Shells

type Shells struct {
	N       int
	Monitor bool
}

Shells is what the process tree says: N distinct background-shell task ids, and whether a Monitor was seen (which has no task id to count).

func CountShells

func CountShells(procRoot string, cli int, children map[int][]int, argv func(int) []string, configDir string) Shells

CountShells is the shells CLI process cli has running, from the proc filesystem at procRoot ("" = /proc): the distinct Bash task ids among its LIVE descendants' fd 1 and fd 2, and whether one of its direct children is a Monitor. children is the caller's process table's child lists (sorted); argv is a process's argv from that table. configDir is Claude Code's config dir, whose shell-snapshots/ a Monitor's argv names.

type Work

type Work struct {
	Subagents     int
	Shells        int
	ShellsAtLeast bool
}

Work is what a CLI has running now. ShellsAtLeast: Shells is a lower bound ("1+ shell"), never an exact count.

func Decide

func Decide(status string, sh Shells, subagents func() int) (Work, bool)

Decide is THE WORK RULE: what a card may claim from the CLI's RAW session status, its process-tree shells, and its running subagents (asked only when the status needs them — a transcript read). ok is false when there is nothing it may claim at all: no status (no live sessions file) or one it does not know.

  • idle: nothing runs — the CLI says so (no agent task, no Bash task).
  • shell: no subagent runs, and at least one Bash task does. The count is exact unless a Monitor was seen (its signature rests on one sample) or the tree shows none (unreadable, or a changed layout): then "1+".
  • busy, waiting: a turn may be running, so any shell seen is "1+", never a number; the subagents are the transcript's running count.

Jump to

Keyboard shortcuts

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