openusage
AGENTS.md250 starsChanged 9 months agoMITView on GitHub
Guidelines for coding agents working in this repository. OpenUsage is a Go terminal dashboard (Bubble Tea) for monitoring AI coding tool usage and spend. It supports two runtime paths: CGO is required (CGO_ENABLED=1) due to mattn/go-sqlite3 usage (Cursor + telemetry store). All providers implement core.UsageProvider from internal/core/provider.go: Providers are registered in internal/providers/registry.go via AllProviders(). Current provider set: openai, anthropic, alibaba_cloud, openrouter, groq, mistral, deepseek, xai, opencode, gemini_api, gemini_cli, ollama, copilot, cursor, claude_code, codex.
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,337 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 1 is common, 1 is distinctive, and 8 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 75
All providers implement core.UsageProvider from internal/core/provider.go:
- Very specific: line 91
Use pointer numerics for optional values (Limit *float64, Remaining *float64).
- Very specific: line 94
Prefer provider-specific error prefixes, for example fmt.Errorf("openai: ...: %w", err).
- Very specific: line 115
Use standard testing package only (no assertion/mocking libraries).
- Very specific: line 116
Prefer table-driven tests with t.Run.
- Distinctive: line 119
Keep env var setup isolated and cleaned up in each test.
- Common: line 124
Never print raw API keys in logs.
- Very specific: line 140
Add widget/detail config (Spec, optional widget.go).
- Very specific: line 142
Verify with go build, go test, make vet.
- Very specific: line 159
Use short imperative subjects (for example: Refresh telemetry provider mapping docs).
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — OpenUsage
Guidelines for coding agents working in this repository.
Project Overview
OpenUsage is a Go terminal dashboard (Bubble Tea) for monitoring AI coding tool usage and spend. It supports two runtime paths:
- Dashboard mode (
openusage) reads usage snapshots through the local telemetry daemon runtime. - Daemon mode (
openusage telemetry ...) collects provider data + hook events into SQLite.
CGO is required (CGO_ENABLED=1) due to mattn/go-sqlite3 usage (Cursor + telemetry store).
Build, Run, Test, Lint
# Build
make build # binary -> ./bin/openusage (with version ldflags)
go build ./cmd/openusage # quick build without ldflags
# Run
make run # go run cmd/openusage/main.go
OPENUSAGE_DEBUG=1 make run # enable debug logging to stderr
make demo # run demo binary with simulated data
# Telemetry daemon
go run ./cmd/openusage telemetry daemon
go run ./cmd/openusage telemetry daemon status
go run ./cmd/openusage telemetry hook codex < /tmp/codex-hook.json
# Test
make test # go test -race -coverprofile=coverage.out -covermode=atomic ./...
make test-verbose # go test -v -race ./...
go test ./internal/providers/... -v
go test ./internal/telemetry/... -v
go test ./internal/tui/... -v
# Lint/format
make lint # golangci-lint run ./... (skips if binary missing)
make vet # go vet ./...
make fmt # go fmt ./...
# Dependencies
make deps # go mod download && go mod verify
make tidy # go mod tidyCurrent Structure
cmd/openusage/ cobra CLI entrypoint
main.go root command
dashboard.go Bubble Tea runtime wiring
telemetry.go telemetry daemon / hook subcommands
cmd/demo/ demo dashboard runner with synthetic snapshots
internal/
config/ settings + credentials JSON persistence
core/ shared types (UsageSnapshot, Metric, ProviderSpec, widgets, time windows)
daemon/ daemon server/client, socket runtime, service install/status
detect/ local tool + env key auto-detection
integrations/ Codex/OpenCode/Claude hook/plugin install + version checks
parsers/ shared HTTP header parsing helpers
providers/ provider implementations + registry (16 providers)
telemetry/ SQLite store, ingest pipeline, dedup, read model
tui/ Bubble Tea views/components/settings UX
version/ build metadata injected by ldflags
plugins/ integration install scripts/templates
configs/ example settings
docs/skills/ feature and provider implementation workflowsProvider Model
All providers implement core.UsageProvider from internal/core/provider.go:
ID(),Describe(),Spec()DashboardWidget(),DetailWidget()Fetch(ctx, acct) (core.UsageSnapshot, error)
Providers are registered in internal/providers/registry.go via AllProviders().
Current provider set: openai, anthropic, alibaba_cloud, openrouter, groq,
mistral, deepseek, xai, opencode, gemini_api, gemini_cli,
ollama, copilot, cursor, claude_code, codex.
Code Style
- Format with
gofmtand keep imports grouped: stdlib, third-party, internal. - Bubble Tea import alias:
tea "github.com/charmbracelet/bubbletea". - Provider package naming: snake_case IDs (for example
claude_code,gemini_api). - Use pointer numerics for optional values (
Limit *float64,Remaining *float64). - Initialize maps explicitly (
make(map[string]core.Metric)). - JSON fields use
snake_case; runtime-only fields usejson:"-". - Prefer provider-specific error prefixes, for example
fmt.Errorf("openai: ...: %w", err).
Error and Status Conventions
- Non-fatal provider states should return populated snapshots with status:
core.StatusAuthcore.StatusLimitedcore.StatusError(when provider returns a handled API error state)
- Fatal execution failures should return
(core.UsageSnapshot{}, error). - Missing auth should degrade gracefully to auth-required snapshots where possible.
UsageSnapshotis the canonical payload (notQuotaSnapshot).
Concurrency Expectations
- Daemon service uses mutex-protected shared state (
pipelineMu,ingestMu, read-model cache locks). - Provider polling, collectors, retention, and spool maintenance run in background goroutines.
ViewRuntimethrottles reconnect attempts and read-model error logs.- Config and credential read-modify-write operations are guarded by package-level mutexes (
saveMu,credMu).
Testing Patterns
- Use standard
testingpackage only (no assertion/mocking libraries). - Prefer table-driven tests with
t.Run. - Provider HTTP tests should use
httptest.NewServer. - File/dir tests should use
t.TempDir. - Keep env var setup isolated and cleaned up in each test.
internal/tui/,internal/telemetry/,internal/daemon/, and providers all have active test suites.
Security and Data Handling
- Never print raw API keys in logs.
- Settings are stored at
~/.config/openusage/settings.json(or%APPDATA%\openusage\settings.jsonon Windows). - User-entered API keys are stored in
credentials.jsonwith0600permissions. AccountConfig.TokenandAccountConfig.ExtraDataare runtime-only (json:"-").- Redact or avoid storing sensitive headers/body data in snapshot diagnostics/raw metadata.
Adding a Provider
For complete workflow and checklists, follow:
docs/skills/add-new-provider.md
Minimum sequence:
- Quiz requirements and auth/data model.
- Research API/docs/error semantics.
- Implement
internal/providers/<name>/with tests. - Add widget/detail config (
Spec, optionalwidget.go). - Register in
registry.go, detection ininternal/detect/, and example config. - Verify with
go build,go test,make vet.
Repo Skills
For larger changes, use these workflow docs in docs/skills/:
develop-featuredesign-featurereview-designimplement-featurevalidate-featureiterate-featurefinalize-featureopenusage-provider(provider-specific guidance)
Commit Style
- Use short imperative subjects (for example:
Refresh telemetry provider mapping docs). - Include the validation commands you ran in PR descriptions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

