Merge pull request #57 from kvenanzi/windows-daemon
This commit is contained in:
@@ -37,10 +37,11 @@ Boards supported out of the box:
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Linux (tested on Ubuntu) or macOS
|
||||
- Linux (tested on Ubuntu), macOS, or Windows 10/11
|
||||
- [PlatformIO CLI](https://docs.platformio.org/en/latest/core/installation/index.html)
|
||||
- Linux: `curl`, `bluetoothctl`, `busctl` (BlueZ Bluetooth stack)
|
||||
- macOS: `python3` (the installer sets up a venv with `bleak` and `httpx`)
|
||||
- Windows: `python3` 3.11+ (the installer sets up a venv with `bleak`, `httpx`, and `pystray`)
|
||||
- Claude Code with an active subscription
|
||||
|
||||
## macOS installation
|
||||
@@ -118,9 +119,73 @@ Check status: `systemctl --user status claude-usage-daemon`
|
||||
|
||||
View logs: `journalctl --user -u claude-usage-daemon -f`
|
||||
|
||||
## Windows installation
|
||||
|
||||
Runs natively on Windows — no WSL required. A system-tray app polls your usage and pushes it over BLE, and starts automatically at login.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- **Native Windows** (not WSL).
|
||||
- **Python 3.11+** from [python.org](https://www.python.org/downloads/) — check *"Add python.exe to PATH"* during install.
|
||||
- **Claude Code** installed, with `claude login` completed. The token is read from `%USERPROFILE%\.claude\.credentials.json` (falling back to `%LOCALAPPDATA%\Claude\` then `%APPDATA%\Claude\`).
|
||||
- The repo on a **native Windows path** (e.g. `%USERPROFILE%\Clawdmeter`), **not** a `\\wsl$` share — the installer refuses a WSL path.
|
||||
|
||||
### Flash the firmware
|
||||
|
||||
```powershell
|
||||
pio run -d firmware -e waveshare_amoled_216 -t upload --upload-port COM5 # use your device's COM port
|
||||
```
|
||||
|
||||
Run `pio run -d firmware` with no env to see the available board envs.
|
||||
|
||||
### Pair the device
|
||||
|
||||
The device is a bonded BLE HID keyboard, so pair it once: **Settings → Bluetooth & devices → Add device → Bluetooth**, then select "Claude Controller". Pairing is **required** — it enables the physical buttons and keeps a persistent connection (the device keeps showing your last-synced usage even after the daemon quits). To undo, use **Remove device** (this disables the buttons).
|
||||
|
||||
### Install the daemon (recommended)
|
||||
|
||||
From the repo root in PowerShell:
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy Bypass -File install-windows.ps1
|
||||
```
|
||||
|
||||
This creates a venv, installs `bleak`/`httpx`/`pystray`/`Pillow` from the in-repo requirements (no internet downloads), registers a per-user login-autostart entry (`HKCU\…\Run`, no admin needed), and launches the tray app headlessly (no console window).
|
||||
|
||||
### Run manually instead (optional)
|
||||
|
||||
```powershell
|
||||
python -m venv .venv
|
||||
.venv\Scripts\Activate.ps1 # if blocked: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned, then retry
|
||||
pip install -r daemon\requirements-windows.txt
|
||||
python daemon\claude_usage_daemon_windows.py # runs in the foreground; Ctrl+C to stop
|
||||
```
|
||||
|
||||
### Tray icon and menu
|
||||
|
||||
The icon's corner bubble shows state — **green** Connected, **amber** Scanning, **red** Error — and hovering shows the status (`Connected · last update HH:MM`). A notification fires once when it enters Error (e.g. an expired token). Right-click for the menu:
|
||||
|
||||
- **Status header** — live state + last sync time.
|
||||
- **Start at login** — toggle autostart on/off.
|
||||
- **Quit** — stops the daemon cleanly; leaves the Windows pairing intact (device keeps its last reading).
|
||||
|
||||
### Logs and troubleshooting
|
||||
|
||||
```powershell
|
||||
Get-Content $env:LOCALAPPDATA\Clawdmeter\daemon.log -Tail 30 # view logs
|
||||
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v Clawdmeter /f # remove autostart
|
||||
```
|
||||
|
||||
| Symptom | Fix |
|
||||
|---------|-----|
|
||||
| `Device not found` | Power on the device; make sure it's in range and paired. |
|
||||
| `token expired` toast / `API HTTP 401` | Re-run `claude login`, then restart the daemon. |
|
||||
| `Connection failed` | Toggle Windows Bluetooth off/on in Settings. |
|
||||
| `Warning: running under Linux/WSL` | Run from a native PowerShell window, not a WSL shell. |
|
||||
|
||||
## How it works
|
||||
|
||||
1. The daemon reads your Claude Code OAuth token — from the macOS Keychain (service `Claude Code-credentials`) on macOS, or from `~/.claude/.credentials.json` on Linux.
|
||||
1. The daemon reads your Claude Code OAuth token — from the macOS Keychain (service `Claude Code-credentials`) on macOS, or from `~/.claude/.credentials.json` on Linux (`%USERPROFILE%\.claude\.credentials.json` on Windows).
|
||||
2. It makes a minimal API call to `api.anthropic.com/v1/messages` — one token of Haiku, basically free.
|
||||
3. The usage numbers come straight out of the response headers (`anthropic-ratelimit-unified-5h-utilization` and friends).
|
||||
4. The daemon connects to the ESP32 over BLE and writes a JSON payload to the GATT RX characteristic.
|
||||
|
||||
Reference in New Issue
Block a user