# ytl001g/claude-usage-tray architecture

> Architecture diagram of the GitHub repository ytl001g/claude-usage-tray, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ytl001g/claude-usage-tray
- Repository: https://github.com/ytl001g/claude-usage-tray

## Overview

Claude Usage Tray is a Windows desktop widget that periodically retrieves Claude plan usage, keeps local history, estimates whether weekly usage will last until reset, and presents alerts and a pixel-art display. The principal flow is the polling loop in main.py through Controller, which coordinates credential and usage retrieval, history/projection, and alert decisions before posting a view to the UI. The README also documents login, five-hour usage, usage breakdowns, configuration, and Windows startup behavior. Some subsystem details are documented but not fully sampled; those relationships are only included where the excerpts, source index, or README support them.

Main entry points: [`main.py`](https://github.com/ytl001g/claude-usage-tray/blob/main/main.py) (App entry), [`tray/controller.py`](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/controller.py) (Poll controller), [`tray/ui.py`](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/ui.py) (Widget UI), [`tray/usage_api.py`](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/usage_api.py) (Usage API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application flow"]
  node_main["App entry<br/>[main.py]"]
  node_controller["Poll controller<br/>[controller.py]"]
end

subgraph group_usage["Usage and analysis"]
  node_usageapi["Usage API<br/>[usage_api.py]"]
  node_history[("Usage history<br/>[history.py]")]
  node_projection["Usage projection<br/>[history.py]"]
  node_alerts["Alert rules<br/>[alerts.py]"]
end

subgraph group_display["Widget presentation"]
  node_ui["Widget UI<br/>[ui.py]"]
  node_render["Pixel renderer<br/>[render.py]"]
  node_text["Date phrasing<br/>[text.py]"]
end

subgraph group_system["Local and Windows integration"]
  node_config[("Configuration<br/>[config.py]")]
  node_winsys["Windows helpers<br/>[winsys.py]"]
end

node_user(("User"))
node_anthropic{{"Anthropic API"}}
node_claudecode["Claude Code"]
node_windows{{"Windows OS"}}

node_main -->|"starts polling"| node_controller
node_main -->|"creates history"| node_history
node_main -->|"creates alerts"| node_alerts
node_main -->|"starts UI"| node_ui
node_main -->|"loads and saves"| node_config
node_main -->|"configures startup"| node_winsys
node_controller -->|"fetches usage"| node_usageapi
node_controller -->|"reads and records"| node_history
node_controller -->|"calculates outlook"| node_projection
node_controller -->|"checks alerts"| node_alerts
node_controller -.->|"uses settings"| node_config
node_usageapi -->|"requests usage"| node_anthropic
node_usageapi -->|"reads credentials"| node_claudecode
node_usageapi -->|"delegates refresh"| node_claudecode
node_main -->|"starts login"| node_claudecode
node_history -->|"supplies readings"| node_projection
node_ui -->|"renders views"| node_render
node_ui -->|"uses window helpers"| node_winsys
node_render -->|"formats dates"| node_text
node_ui -->|"shows widget"| node_user
node_user -->|"interacts"| node_ui
node_winsys -->|"manages windows"| node_windows
node_config -->|"locates credentials"| node_claudecode

click node_main "https://github.com/ytl001g/claude-usage-tray/blob/main/main.py"
click node_controller "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/controller.py"
click node_usageapi "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/usage_api.py"
click node_history "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/history.py"
click node_projection "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/history.py"
click node_alerts "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/alerts.py"
click node_ui "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/ui.py"
click node_render "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/render.py"
click node_text "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/text.py"
click node_config "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/config.py"
click node_winsys "https://github.com/ytl001g/claude-usage-tray/blob/main/tray/winsys.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_controller,node_user toneBlue
class node_usageapi,node_history,node_projection,node_alerts toneAmber
class node_ui,node_render,node_text,node_anthropic toneMint
class node_config,node_winsys toneRose
class node_claudecode,node_windows toneIndigo
```

## Components

### Application flow

- [App entry](https://github.com/ytl001g/claude-usage-tray/blob/main/main.py): `main.py`
- [Poll controller](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/controller.py): `tray/controller.py`

### Usage and analysis

- [Usage API](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/usage_api.py): `tray/usage_api.py`
- [Usage history](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/history.py): `tray/history.py`
- [Usage projection](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/history.py): `tray/history.py`
- [Alert rules](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/alerts.py): `tray/alerts.py`

### Widget presentation

- [Widget UI](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/ui.py): `tray/ui.py`
- [Pixel renderer](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/render.py): `tray/render.py`
- [Date phrasing](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/text.py): `tray/text.py`

### Local and Windows integration

- [Configuration](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/config.py): `tray/config.py`
- [Windows helpers](https://github.com/ytl001g/claude-usage-tray/blob/main/tray/winsys.py): `tray/winsys.py`

### Other components

- **User**
- **Anthropic API**
- **Claude Code**
- **Windows OS**

## Connections

- App entry → Poll controller: starts polling (evidence: `main.py`)
- App entry → Usage history: creates history (evidence: `main.py`)
- App entry → Alert rules: creates alerts (evidence: `main.py`)
- App entry → Widget UI: starts UI (evidence: `main.py`)
- App entry → Configuration: loads and saves (evidence: `main.py`)
- App entry → Windows helpers: configures startup (evidence: `main.py`)
- Poll controller → Usage API: fetches usage (evidence: `tray/controller.py`)
- Poll controller → Usage history: reads and records (evidence: `tray/controller.py`)
- Poll controller → Usage projection: calculates outlook (evidence: `tray/controller.py`)
- Poll controller → Alert rules: checks alerts (evidence: `tray/controller.py`)
- Poll controller → Configuration: uses settings
- Usage API → Anthropic API: requests usage (evidence: `README.md`)
- Usage API → Claude Code: reads credentials (evidence: `tray/usage_api.py`)
- Usage API → Claude Code: delegates refresh (evidence: `tray/usage_api.py`)
- App entry → Claude Code: starts login (evidence: `main.py`)
- Usage history → Usage projection: supplies readings (evidence: `tray/history.py`)
- Widget UI → Pixel renderer: renders views (evidence: `tray/ui.py`)
- Widget UI → Windows helpers: uses window helpers (evidence: `tray/ui.py`)
- Pixel renderer → Date phrasing: formats dates (evidence: `tray/render.py`)
- Widget UI → User: shows widget (evidence: `README.md`)
- User → Widget UI: interacts (evidence: `README.md`)
- Windows helpers → Windows OS: manages windows (evidence: `tray/winsys.py`)
- Configuration → Claude Code: locates credentials (evidence: `tray/config.py`)
