Skip to content

About

A Tamagotchi for Claude Code — your usage and agent activity on a desktop ESP32 screen

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Claudegotchi

A tiny desktop pet that shows your Claude usage limits and reacts to your Claude agent's current activity.

page_main cycling through working / musing / excited states

The GIF above is rendered by tools/render-gif/, a headless port of the device's LVGL view — not a capture of the physical screen.

The device displays:

  • Current — usage within the active 5-hour billing block (the same number Claude Code's /usage command shows).
  • Weekly — usage across the rolling 7-day window.
  • Pet — an animated pixel creature whose color, bob speed, and eyes reflect what your Claude agent is doing right now.

Repo layout

Path What it is
claudegotchi.yaml ESPHome firmware for the device
server/ Node.js HTTP feed; calls Anthropic's /api/oauth/usage using your Claude Code OAuth tokens and serves the result to the device
secrets.yaml WiFi creds + CLAUDE_API_URL (not committed)

Hardware

Wiring

   ┌─────────────────┐                      ┌──────────────────┐
   │                 │                      │                  │
   │                 │ CS  ─────────────────┤ GPIO 10          │
   │                 │ DC  ─────────────────┤ GPIO 13          │
   │   ST7789V LCD   │ RST ─────────────────┤ GPIO 4           │
   │     240×320     │ SDA ─────────────────┤ GPIO 11 (MOSI)   │
   │                 │ SCL ─────────────────┤ GPIO 12 (SCK)    │
   │                 │ VCC ─────────────────┤ VBUS (5V)        │
   │                 │ GND ─────────────────┤ GND              │
   │                 │                      │                  │
   └─────────────────┘                      └──────────────────┘
        Display                              ESP32-S3 (LOLIN S3 Mini)

Pages

  1. Usage — two animated bars + reset countdowns + status footer (matches the look on the reference image). Header has small WIFI and API indicators top-right (green = OK, red = problem).
  2. Pet — full-screen pet with status label.
  3. Info — IP address, WiFi status, API status, uptime.

Pet states

State derivation runs every 5s, in this priority order:

State Trigger
no_wifi Device is not associated with WiFi
api_down WiFi is up but no successful API poll in 45s
excited current_pct ≥ 85 or weekly_pct ≥ 85
error API reports agent_status: "error"
working API reports agent_status: "working"
musing API reports agent_status: "musing"
sleeping Both meters below 3%
idle Default

Each state has its own body color, bob frequency, blink pattern, and LED color. The two failure states are visually distinct: no_wifi is a frozen dark-red pet (no bob, eyes closed, red LED), api_down is a slate pet with slow bob and a dim-red LED — so you can tell at a glance whether the network or the server is broken.

Setup

1. Log in to Claude Code

The server reads your Claude Code OAuth tokens from ~/.claude/.credentials.json, so you must be logged in. If you can run /usage inside claude and see your real numbers, you're set. Switching accounts later (/login) is picked up automatically — no server restart.

2. Wrapper server

cd server
cp .env.example .env   # optional — defaults are sensible
npm install
npm start

Requires Node ≥ 18. No external CLIs. The server prints the LAN IP(s) to drop into secrets.yaml.

Endpoint:

  • GET / or GET /claude — the JSON contract below.

3. Secrets

Create secrets.yaml (or extend your existing one):

WIFI_SSID: "your-ssid"
WIFI_PASSWORD: "your-password"
CLAUDE_API_URL: "http://your-host:8787/"

4. Firmware

esphome run claudegotchi.yaml

First flash must be over USB because the device's hostname is being changed from any previous identity.

API contract

The device polls CLAUDE_API_URL every 10s and expects:

{
  "current_pct": 50,
  "current_reset_s": 4920,
  "weekly_pct": 11,
  "weekly_reset_s": 547200,
  "agent_status": "musing"
}
  • *_pct — integer 0–100.
  • *_reset_s — seconds until that meter resets.
  • agent_status — one of idle, musing, working, error.

On any failure to fetch usage (no credentials, OAuth refresh fails, Anthropic unreachable), the server omits the numeric fields entirely and responds with just:

{ "agent_status": "error" }

The firmware's JSON parser leaves any field that's missing alone, so the device keeps showing the last-known-good current_* / weekly_* bars (with a still-ticking reset countdown) while the pet flips to the red error state — making the problem visually obvious without losing the last numbers you saw.

How the server fills the feed

current_* and weekly_* come from a single call to GET https://api.anthropic.com/api/oauth/usage, authenticated with the OAuth tokens from ~/.claude/.credentials.json — the same endpoint and the same credentials Claude Code's /usage slash command uses. Responses are cached in memory for USAGE_CACHE_TTL_SECONDS (default 60 s, minimum 60 s) to avoid hammering Anthropic on every 10-second device poll. If a fetch fails (429, 5xx, network error), the server enters a cooldown that respects the upstream Retry-After header (default 60 s, max 1 h) and serves the last cached value during that window — no further upstream calls happen until the cooldown ends. Reset countdowns are recomputed from the cached resets_at timestamp on every response, so they tick smoothly regardless of cache age.

Access tokens are refreshed proactively (within 30s of expiry) and reactively (on any 401), and the new tokens are atomically written back to ~/.claude/.credentials.json.

agent_status is inferred by tailing the most recently modified ~/.claude/projects/**/*.jsonl file and parsing the last ~12 events:

  • working — a tool_use block has no matching tool_result yet (Claude is mid-execution; this also holds for long-running tools like Bash, capped at 10 min so a crashed session doesn't get stuck).
  • musing — the most recent event has a thinking block, is a user message (Claude is composing a reply), or is general recent activity within 30s.
  • idle — stop_reason: end_turn on the last assistant message, no activity in 2 minutes, or no JSONL files at all.

Configuration

server/.env (optional — copy from server/.env.example):

Variable Default Notes
PORT 8787 TCP port the server listens on.
USAGE_CACHE_TTL_SECONDS 60 How long /api/oauth/usage responses are cached, in seconds. Range 60..86400. Anthropic rate-limits this endpoint aggressively, so the floor is 60 s — going lower will earn you 429s. Reset countdowns are not affected; they're recomputed at response time.

Status footer & spinner

The footer text under the pet matches Claude Code's CLI style: a 12-frame breathing asterisk (· ✢ * ✶ ✻ ✽) cycling next to a verb randomly drawn from Claude Code's SPINNER_VERBS list ("Pondering", "Tinkering", "Crafting", …) — the glyph slot has a fixed width so the verb never jitters as the spinner cycles. The glyph and verb list are copied verbatim from claude-code/src/components/Spinner/ so the device feels like an extension of the CLI.

The spinner is shown only for active states (musing, working). Idle / sleeping / error / near-limit / connectivity states show plain text — no glyph.

Offline behaviour

Three failure modes, three visuals:

  • WiFi disconnected → footer reads No WiFi, header WIFI turns red, pet freezes dark-red with eyes closed, LED solid red. Usage cards hidden.
  • WiFi up but server unreachable → footer reads API down, header API turns red while WIFI stays green, pet slows to a slate-gray slow-bob, LED dim red. Usage cards hidden.
  • Server responding but can't fetch usage (e.g. expired credentials Anthropic rejected) → red Error! pet with fast bob and rapidly blinking eyes, LED pulses bright red. Usage cards stay visible with the last good percentages and a still-ticking reset countdown — the device made it clear something's wrong without throwing away the numbers you last saw.

When the next successful poll lands, everything snaps back to fresh.

About

A Tamagotchi for Claude Code — your usage and agent activity on a desktop ESP32 screen

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages