Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .serena/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/cache
/project.local.yml
133 changes: 133 additions & 0 deletions .serena/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# the name by which the project can be referenced within Serena
project_name: "Claude-Code-Usage-Monitor"


# list of languages for which language servers are started; choose from:
# al angular ansible bash clojure
# cpp cpp_ccls crystal csharp csharp_omnisharp
# dart elixir elm erlang fortran
# fsharp go groovy haskell haxe
# hlsl html java json julia
# kotlin lean4 lua luau markdown
# matlab msl nix ocaml pascal
# perl php php_phpactor powershell python
# python_jedi python_ty r rego ruby
# ruby_solargraph rust scala scss solidity
# svelte swift systemverilog terraform toml
# typescript typescript_vts vue yaml zig
# (This list may be outdated. For the current list, see values of Language enum here:
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py
# For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
# Note:
# - For C, use cpp
# - For JavaScript, use typescript
# - For Angular projects, use angular (subsumes typescript+html; requires `npm install` in the project root)
# - For Svelte projects, use svelte (subsumes typescript/javascript for .svelte projects; requires npm)
# - For SCSS / Sass / plain CSS, use scss (some-sass-language-server handles all three)
# - For Free Pascal/Lazarus, use pascal
# Special requirements:
# Some languages require additional setup/installations.
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
# When using multiple languages, the first language server that supports a given file will be used for that file.
# The first language is the default language and the respective language server will be used as a fallback.
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
languages:
- rust

# the encoding used by text files in the project
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
encoding: "utf-8"

# line ending convention to use when writing source files.
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
line_ending:

# The language backend to use for this project.
# If not set, the global setting from serena_config.yml is used.
# Valid values: LSP, JetBrains
# Note: the backend is fixed at startup. If a project with a different backend
# is activated post-init, an error will be returned.
language_backend:

# whether to use project's .gitignore files to ignore files
ignore_all_files_in_gitignore: true

# advanced configuration option allowing to configure language server-specific options.
# Maps the language key to the options.
# The settings are considered only if the project is trusted (see global configuration to define trusted projects).
# See https://oraios.github.io/serena/02-usage/050_configuration.html#language-server-specific-settings
ls_specific_settings: {}

# list of additional workspace folder paths for cross-package reference support (e.g. in monorepos).
# Paths can be absolute or relative to the project root.
# Each folder is registered as an LSP workspace folder, enabling language servers to discover
# symbols and references across package boundaries.
# Currently supported for: TypeScript.
# Example:
# additional_workspace_folders:
# - ../sibling-package
# - ../shared-lib
additional_workspace_folders: []

# list of additional paths to ignore in this project.
# Same syntax as gitignore, so you can use * and **.
# Note: global ignored_paths from serena_config.yml are also applied additively.
ignored_paths: []

# whether the project is in read-only mode
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
# Added on 2025-04-18
read_only: false

# list of tool names to exclude.
# This extends the existing exclusions (e.g. from the global configuration)
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
excluded_tools: []

# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).
# This extends the existing inclusions (e.g. from the global configuration).
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
included_optional_tools: []

# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
# This cannot be combined with non-empty excluded_tools or included_optional_tools.
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
fixed_tools: []

# list of mode names that are to be activated by default, overriding the setting in the global configuration.
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
# If the setting is undefined/empty, the default_modes from the global configuration (serena_config.yml) apply.
# Otherwise, this overrides the setting from the global configuration (serena_config.yml).
# Therefore, you can set this to [] if you do not want the default modes defined in the global config to apply
# for this project.
# This setting can, in turn, be overridden by CLI parameters (--mode).
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
default_modes:

# list of mode names to be activated additionally for this project, e.g. ["query-projects"]
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
added_modes:

# initial prompt for the project. It will always be given to the LLM upon activating the project
# (contrary to the memories, which are loaded on demand).
initial_prompt: ""

# time budget (seconds) per tool call for the retrieval of additional symbol information
# such as docstrings or parameter information.
# This overrides the corresponding setting in the global configuration; see the documentation there.
# If null or missing, use the setting from the global configuration.
symbol_info_budget:

# list of regex patterns which, when matched, mark a memory entry as read‑only.
# Extends the list from the global configuration, merging the two lists.
read_only_memory_patterns: []

# list of regex patterns for memories to completely ignore.
# Matching memories will not appear in list_memories or activate_project output
# and cannot be accessed via read_memory or write_memory.
# To access ignored memory files, use the read_file tool on the raw file path.
# Extends the list from the global configuration, merging the two lists.
# Example: ["_archive/.*", "_episodes/.*"]
ignored_memory_patterns: []
50 changes: 50 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## What this is

A lightweight **Windows-only** native taskbar widget (Rust) that displays Claude Code, Codex, and Google Antigravity usage/quota directly in the Windows taskbar, plus system tray icon badges. No backend service; it reads local OAuth credentials and polls provider endpoints directly.

The project targets Windows exclusively via the `windows` crate (Win32 APIs). It will not build or run on Linux/macOS. The development environment here is WSL, so builds and tests must target Windows (e.g. `cargo build --target x86_64-pc-windows-msvc` or build on a Windows host).

## Commands

```bash
cargo build # debug build (Windows target)
cargo build --release # optimized release (opt-level=z, LTO, stripped, panic=abort)
cargo test # run tests
cargo test <name> # run a single test by name
cargo clippy # lint
```

Runtime entry points (the produced exe):
- `claude-code-usage-monitor` — normal run, shows widget + tray icons
- `claude-code-usage-monitor --diagnose` — writes a startup/visibility log to `%TEMP%\claude-code-usage-monitor.log`
- `updater::handle_cli_mode` intercepts update-related CLI args before the window launches (see `main.rs`)

## Architecture

`main.rs` wires modules and dispatches: diagnose mode → updater CLI mode → `window::run()` (the main message loop). Modules:

- **`window.rs`** (largest, ~3300 lines) — the heart. Owns the Win32 window (a layered/child window embedded into the taskbar), the `wnd_proc` message handler, all painting, drag-to-move (restricted to the divider handle), DPI/display-change handling, the right-click context menu, settings persistence (`SettingsFile`), and the timers (`TIMER_POLL`, `TIMER_COUNTDOWN`, `TIMER_RESET_POLL`, `TIMER_UPDATE_CHECK`). Background work posts custom messages (`WM_APP_USAGE_UPDATED`, `WM_APP_UPDATE_CHECK_COMPLETE`, `WM_APP_TRAY`) back to the window thread.
- **`native_interop.rs`** — Win32 helpers and shared constants: enumerating taskbars (`find_taskbars`, multi-monitor), locating taskbar child windows, taskbar/window rects, window-style and timer/message constants. Multi-monitor placement is anchored by `taskbar_index` (settings) plus `tray_offset`.
- **`poller.rs`** (~1700 lines) — all network + credential logic. Reads credentials (Windows `~/.claude/.credentials.json`, WSL distro fallback, Codex `auth.json`, Antigravity token in Windows Credential Manager `gemini:antigravity`), polls Anthropic / ChatGPT Codex / Google Antigravity endpoints, refreshes expired tokens by shelling out to the provider CLI (`refresh_or_fallback`, `cli_refresh_*`), and falls back to rate-limit headers. `poll()` is the entry; `credential_watch_*` detects credential changes.
- **`models.rs`** — shared data types: `UsageSection`, `UsageData`, `AppUsageData` (per-provider results consumed by window/tray rendering).
- **`tray_icon.rs`** — system tray (notification area) icons, one per enabled provider, with percentage badges and hover tooltips; left-click toggles widget.
- **`theme.rs`** — colors and the per-provider usage color schemes (Claude warm, Codex black/white, Antigravity Google-blue).
- **`updater.rs`** — update check + self-update (WinGet path and portable self-download from GitHub releases).
- **`localization/`** — 10 languages. `mod.rs` defines `LanguageId`, the `Strings` struct, system-language detection, and language resolution; each `*.rs` returns that language's `Strings`. Add a language by adding a module, extending `LanguageId::ALL`, and the match arms in `mod.rs`.
- **`diagnose.rs`** — opt-in file logging used across modules when `--diagnose` is passed.
- **`build.rs`** — embeds the icon and PE version metadata (from `CARGO_PKG_VERSION`) via `winres`.

## Persistence

- Settings: `%APPDATA%\ClaudeCodeUsageMonitor\settings.json` — `SettingsFile` in `window.rs` (tray_offset, taskbar_index, poll_interval_ms, language, last_update_check_unix, widget_visible, show_claude_code, show_codex, show_antigravity). Fields use serde defaults so old files stay forward-compatible — preserve that when adding fields.
- Startup-with-Windows: registry Run key `ClaudeCodeUsageMonitor`.
- Single-instance: global mutex `Global\ClaudeCodeUsageMonitor`.

## Conventions

- Version lives only in `Cargo.toml`; `build.rs` packs it into the exe and `updater.rs` compares against it. Release commits are tagged like `v1.4.8`.
- The widget embeds into the real Windows taskbar window; there's a non-embedded fallback paint path (`WM_PAINT`) for when embedding fails. Multi-monitor moves happen by dragging the widget onto another taskbar, which updates `taskbar_index`.
2 changes: 2 additions & 0 deletions src/localization/dutch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Open Antigravity en meld je opnieuw aan. Ververs of herstart de app daarna.",
codex_window_title: "Codex-gebruiksmonitor",
antigravity_window_title: "Antigravity-gebruiksmonitor",
monitor: "Monitor",
primary_monitor: "Primair",
second_suffix: "s",
};
2 changes: 2 additions & 0 deletions src/localization/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Open Antigravity and sign in again. After that, refresh or restart this app.",
codex_window_title: "Codex Usage Monitor",
antigravity_window_title: "Antigravity Usage Monitor",
monitor: "Monitor",
primary_monitor: "Primary",
second_suffix: "s",
};
2 changes: 2 additions & 0 deletions src/localization/french.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Ouvrez Antigravity et reconnectez-vous. Ensuite, actualisez ou redemarrez cette application.",
codex_window_title: "Moniteur d'utilisation Codex",
antigravity_window_title: "Moniteur d'utilisation Antigravity",
monitor: "Moniteur",
primary_monitor: "Principal",
second_suffix: "s",
};
2 changes: 2 additions & 0 deletions src/localization/german.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Offnen Sie Antigravity und melden Sie sich erneut an. Aktualisieren oder starten Sie diese App anschliessend neu.",
codex_window_title: "Codex-Nutzungsmonitor",
antigravity_window_title: "Antigravity-Nutzungsmonitor",
monitor: "Monitor",
primary_monitor: "Primär",
second_suffix: "s",
};
2 changes: 2 additions & 0 deletions src/localization/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Antigravity を開いて再度サインインしてください。その後、このアプリを更新するか再起動してください。",
codex_window_title: "Codex 使用量モニター",
antigravity_window_title: "Antigravity 使用量モニター",
monitor: "モニター",
primary_monitor: "プライマリ",
second_suffix: "秒",
};
2 changes: 2 additions & 0 deletions src/localization/korean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Antigravity를 열고 다시 로그인하세요. 그런 다음 이 앱을 새로 고치거나 다시 시작하세요.",
codex_window_title: "Codex 사용량 모니터",
antigravity_window_title: "Antigravity 사용량 모니터",
monitor: "모니터",
primary_monitor: "기본",
second_suffix: "초",
};
2 changes: 2 additions & 0 deletions src/localization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ pub struct Strings {
pub antigravity_token_expired_body: &'static str,
pub codex_window_title: &'static str,
pub antigravity_window_title: &'static str,
pub monitor: &'static str,
pub primary_monitor: &'static str,
}

pub fn resolve_language(language_override: Option<LanguageId>) -> LanguageId {
Expand Down
2 changes: 2 additions & 0 deletions src/localization/portuguese_brazil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Abra o Antigravity e entre novamente. Depois disso, atualize ou reinicie este aplicativo.",
codex_window_title: "Monitor de uso do Codex",
antigravity_window_title: "Monitor de uso do Antigravity",
monitor: "Monitor",
primary_monitor: "Principal",
};
2 changes: 2 additions & 0 deletions src/localization/russian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Откройте Antigravity и войдите снова. После этого обновите или перезапустите приложение.",
codex_window_title: "Монитор использования Codex",
antigravity_window_title: "Монитор использования Antigravity",
monitor: "Монитор",
primary_monitor: "Основной",
};
2 changes: 2 additions & 0 deletions src/localization/spanish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "Abre Antigravity e inicia sesion otra vez. Despues, actualiza o reinicia esta aplicacion.",
codex_window_title: "Monitor de uso de Codex",
antigravity_window_title: "Monitor de uso de Antigravity",
monitor: "Monitor",
primary_monitor: "Principal",
second_suffix: "s",
};
2 changes: 2 additions & 0 deletions src/localization/traditional_chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ pub(super) const STRINGS: Strings = Strings {
antigravity_token_expired_body: "請開啟 Antigravity 並重新登入。完成後,請重新整理或重新啟動此應用程式。",
codex_window_title: "Codex 使用量監控",
antigravity_window_title: "Antigravity 使用量監控",
monitor: "螢幕",
primary_monitor: "主要",
second_suffix: "秒",
};
Loading