Local agent
The agent is a set of small Node.js scripts that Claude Code calls as hooks. They read your rules and caps, decide, and append one line per decision to a local journal.
What runs where
| Part | Role | Proof |
|---|---|---|
evaluate.js (hook PreToolUse) | Applies .leashr/rules.json before each tool call. | skills/lsh-rules/test (155) |
cap.js guard, cap.js prompt | Refuses tool calls and prompts when a cap is reached or the kill switch is on. | skills/lsh-cap/test (73) |
cap.js statusline | Stores the session cost every 2 s, and the quota samples. | skills/lsh-cap/test/cap.test.js |
mission.js session-start | Binds each session to the current mission. | skills/lsh-mission/test (24) |
learn.js record | Records failed tool calls so loops can be spotted. | skills/lsh-learn/test (12) |
audit.js | Reads the journal. Read-only. | skills/lsh-audit/test (18) |
collector.js | Local OpenTelemetry receiver for cost. Started by hand, not by init. | skills/lsh-cost/test (14) |
Leashr does not parse transcripts: Anthropic documents their format as internal and changing between versions. Cost comes from the statusline and OpenTelemetry.
Other tools in the repository
| Tool | What it does | Status and proof |
|---|---|---|
lsh-learn | Proposes a rule from commands that fail in a loop. Never writes the rules file. | Tested, skills/lsh-learn/test |
lsh-quota | Shows the subscription quota used and a straight-line projection. Prints n/a without a sample. | Tested, interactive Claude Code only, skills/lsh-quota/test |
lsh-agents | Declares tier agents (lsh:fast, lsh:standard, lsh:expert, lsh:review) as a Claude Code plugin. | Tested on Claude Code 2.1.310, skills/lsh-agents/test (34) |
Audit journal
Each decision is one JSON line in .mission/events/YYYY-MM-DD.jsonl, one file per local day. The line holds the rule that decided, the session, the agent and the mission. The target field holds the command or path, with secrets masked and cut at 300 characters. The prompt text is never written. Read it with audit.js: see Event format.
Limits
Fail open by default, fail closed as installedClaude Code hooks fail open by default: if a hook errors or times out, the call continues. lsh-init sets onFailure: "block" on the guard hooks, and the scripts refuse on their own errors (fail closed). Observed on 2.1.310: a hook that hangs past its timeout blocks the call. Even so, rules are a guard rail, not a sandbox.
- A request already in flight cannot be cancelled: only the next tool call or prompt is refused.
disableAllHooksor another statusline switches off the data the agent relies on; calls then fail closed.- A script called by name, a variable or a command built at run time is not seen by the rules.
- Tested on Claude Code 2.1.310 only. Other agents: see Limits by agent.