# The local-first safety and cost layer for your autonomous agents

> Source: <https://github.com/aisona-lab/tucana-code>
> Published: 2026-12-02 10:07:30+00:00

**Key takeaway:** Tucana Code v0.1.0 registers a <1 ms, $0, fully offline PreToolUse hook that deterministically allows safe commands like git status, blocks destructive ones like rm -rf /, and escalates gray-zone commands such as npm run deploy:staging, with spend caps set in ~/.tucana-code/budget.json.

**The local-first safety & cost layer for Claude Code, Codex, and OpenCode.**

  Same agents. Hard spend caps. Sub-millisecond guardrails. Zero telemetry.

[Quickstart](#30-second-quickstart) •
  [Why Tucana](#why-tucana-code) •
  [Safety Cockpit](#local-safety-cockpit-web-ui) •
  [Architecture](#system-0--system-1-architecture) •
  [Kill-Switch](#local-currency-kill-switch) •
  [Closed-Loop Calibration](#closed-loop-calibration-with-tucana-lab)

**Coding agents run real shell commands on your machine and burn real API dollars while you look away.**

One hallucinated `rm -rf`, one leaked `.env` piped to `curl`, or one runaway reasoning loop on pay-as-you-go tokens can wipe your morning in seconds.

**Tucana Code** puts a **<1 ms, $0, 100% offline safety & budget gate** directly inside Claude Code's `PreToolUse` hook (and any CLI agent wrapper) — **without** shipping your prompts, code, or traces to anyone's cloud.

| Capability | Unprotected Agent | Cloud AI Gateways | **Tucana Code (`v0.1.0`)** | 
|---|---|---|---|
| **Safe read-only checks (`git status`, tests)** | Manual click or YOLO | +150–600 ms network roundtrip | **`<1 ms` System 0, `$0`, 100% offline** | 
| **Destructive / exfil protection** | Hope the LLM behaves | Cloud policy / SaaS lock-in | **Instant deterministic block + fail-safe** | 
| **API spend ceiling & Kill-Switch** | Surprise invoice tomorrow | USD-only / proxy account | **Real-time USD + 6 LATAM currencies** | 
| **Telemetry & cloud accounts** | Vendor telemetry | Cloud dashboard + auth | **Zero accounts · Zero network · MIT** | 
| **Learn from your overrides** | Re-prompt forever | Vendor fine-tuning | **Human review in [`tucana-lab`](https://github.com/aisona-lab/tucana-lab) → `<1 ms` rules** | 

Requires **Node.js `>=22.16.0`**. Zero runtime dependencies in the published CLI (` 27.5 kB` packed, ~56 ms cold start).

```
npm install -g tucana-code
tucana-code --help
```

*(Want to try a one-off command first? Run `npx tucana-code --help`.)*

`init --dry-run` backs up `~/.claude/settings.json` with a timestamp, registers `PreToolUse` idempotently using your resolved binary path (**never** slow `npx` in the hot path), and runs in observation mode while writing real traces:

```
tucana-code init --dry-run --currency MXN
tucana-code doctor
```

Test all three decision paths immediately:

``` php
tucana-code guard check -- git status                  # System 0 -> ALLOW (<1 ms, $0)
tucana-code guard check -- "rm -rf /"                  # System 0 -> BLOCK (<1 ms, $0)
tucana-code guard check -- "npm run deploy:staging"    # Gray zone -> ESCALATE (ask)
```

Ready to enforce live blocking? Re-run without `--dry-run`:

```
tucana-code init --currency MXN
```

Using **Codex**, **OpenCode**, **Gemini CLI**, or local scripts? Wrap any command in one line:

```
tucana-code guard check -- <command>
```

Run `tucana-code` locally for an **Editorial Instrument** workspace built specifically for agent governance and cost control:

- **Tucana Light (Paper) & Tucana Space (Dark):** Warm paper canvas (`#F4EEE3` ) as the strict default, paired with dark space mode (`#0B101B` ) via a`Light | Space` segmented toggle.
- **44px Top Telemetry Ribbon:** Live`System 0` mode selector (`Active` ,`Strict` ,`Dry-run` ) and an interactive**Budget Guard** popover to switch currencies (`USD` ,`MXN` ,`COP` ,`ARS` ,`BRL` ,`CLP` ,`PEN` ) and update thread/daily caps in`~/.tucana-code/budget.json` .
- **Collapsible Editorial Rail & Session Briefing:** Numbered session index (`01` ,`02` , ...) with`Workspace & Git` ,`System 0 Gate` , and`Budget Guard` cards under the composer.
- **Clean Offline Resilience:** Local WebSocket/network loss renders a clean Tucana reconnecting state with zero cloud dependencies.

Tucana splits decisions between deterministic speed and calibrated escalation so your fast path stays instant and offline:

``` php
flowchart LR
  Agent["Agent Bash Call<br/>(PreToolUse / CLI)"] --> Budget{"Local Budget<br/>Kill-Switch?"}
  Budget -- "Limit Exceeded" --> Deny["DENY<br/>(0 ms, kill_switch)"]
  Budget -- "Within Budget" --> Sys0{"System 0<br/>Deterministic + Policy"}
  Sys0 -- "Known Safe / Approved" --> Allow["ALLOW<br/>(&lt;1 ms, $0)"]
  Sys0 -- "Known Destructive / Exfil" --> Block["BLOCK<br/>(&lt;1 ms, $0)"]
  Sys0 -- "Gray Zone" --> Sys1["System 1 (Optional)<br/>Ollama / KEV / Jev / Offline Ask"]
  Deny --> Trace["Append-Only<br/>decision-trace.jsonl"]
  Allow --> Trace
  Block --> Trace
  Sys1 --> Trace
  Trace --> Lab["Tucana Lab<br/>ECE / Brier + Active Learning"]
  Lab -- "policy-calibration.json" --> Sys0
```

- **System 0 (`<1 ms`, `$0`, offline):** Fast deterministic rules + exact-match human-approved rules loaded from`~/.tucana-code/policy-calibration.json` .
- **System 1 (optional, never blocking):** Point`TUCANA_KEV_URL` or`OLLAMA_HOST` to your local model (`$0` ), or optionally set`JEV_API_KEY` . When offline or unconfigured, gray-zone commands gracefully`escalate` (`ask` ) — never crashing your session.

Every raw agent trace starts as scattered telemetry points in the dark (**01 Origin**). Run it through continuous evaluation and uncertainty sorting (** 02 Vortex**), assemble human-verified judgment on a structured grid (** 03 Assemblage**), and lock it into sharp, deterministic `<1 ms` instincts (** 04 The Tucana**).

Built for real pay-as-you-go developers across the Americas and beyond. Configure limits in USD and track spend in **USD (`$`), MXN (` MX$`), COP (` COL$`), ARS (` ARS$`), BRL (` R$`), CLP (` CLP$`), or PEN (` S/`)**:

```
# Set per-thread and daily spending caps
tucana-code budget set --currency MXN --thread-limit 0.15 --daily-limit 2.00

# Check current thread & daily spend
tucana-code budget status --currency MXN --thread-id session-1

# Record token usage; triggers kill-switch once the cap is reached
tucana-code budget record --model claude-sonnet-5-5 --input 100000 --output 20000 --thread-id session-1 --currency MXN

# Once tripped, even benign commands are halted cleanly
tucana-code guard check --thread-id session-1 --currency MXN -- git status
# -> BLOCK (kill_switch, conf=1, 0ms): Kill-switch: thread spend MX$... reached limit MX$...

# Summarize local traces or clear limits when ready
tucana-code trace summary --currency MXN
tucana-code budget set --thread-limit none --daily-limit none
```

Every guardrail verdict is appended locally to `~/.tucana-code/traces/decision-trace.jsonl` (conforming to `schemas/decision-trace.schema.json`` v0.1.0`).

Open those traces in [**Tucana Lab (`aisona-lab/tucana-lab`)**](https://github.com/aisona-lab/tucana-lab) to:

1. **Measure real calibration** (10-bin Reliability Diagram, Expected Calibration Error, Brier score).
2. **Label only high-uncertainty edge cases** via keyboard-first Active Learning (`feedback.jsonl` , keeping`decision-trace.jsonl` strictly immutable).
3. **Export `policy-calibration.json`** straight back to`~/.tucana-code/policy-calibration.json` so`tucana-code` improves`<1 ms` decisions instantly —**with zero model training required** .
4. **Export clean SFT JSONL datasets** whenever you are ready to fine-tune your own local Qwen / Llama / Mistral classifier.

- **Zero telemetry:** 100% free of PostHog, Axiom, Clerk, analytics beacons, or cloud relay dependencies. Everything lives under`~/.tucana-code/` .
- **Fast hot path:**`tucana-code init` writes`tucana-code hook claude-pretool` (or`node <resolved-bin.mjs> hook claude-pretool` ) — never`npx` inside`PreToolUse` .
- **MIT Open Source:** Licensed under the[MIT License](https://github.com/aisona-lab/tucana-code/blob/main/LICENSE) .

```
git clone https://github.com/aisona-lab/tucana-code.git
cd tucana-code
corepack pnpm install
corepack pnpm run typecheck
corepack pnpm --filter @tucana/guardian test
corepack pnpm --filter tucana-code build
```

Verify shared schema parity with `tucana-lab`:

```
node scripts/verify-contract-parity.mjs
```

  If **Tucana Code** saved a production directory or an unexpected API bill, consider giving the repo a ⭐

  and exploring [**aisona-lab/tucana-lab**](https://github.com/aisona-lab/tucana-lab) for visual calibration & Active Learning.
