← Back to PRs

#7806: feat: export quota info to ~/.openclaw/quota.json after each agent run

by leviyehonatan open 2026-02-03 06:51 View on GitHub →
agents stale
## Summary This PR enables external monitoring tools (dashboards, file watchers) to track provider quota usage in real-time without making API calls or using model tokens. ## Motivation Currently, to check quota info you need to either: 1. Call `session_status` tool (uses tokens) 2. Run `openclaw status` CLI 3. Scrape provider dashboards With this change, external tools can simply watch `~/.openclaw/quota.json` for updates. ## Changes - Add `provider-usage.export.ts` with `exportQuotaToFile()` and `appendQuotaToHistory()` - Add `quota-export-runner.ts` for fire-and-forget quota export - Call `runQuotaExport()` after each agent run in `attempt.ts` - Export new functions from `provider-usage.ts` ## Output Format ```json { "updatedAt": 1706945123456, "models": { "Claude": { "percent": 80, "resetIn": "2h 30m" } } } ``` History is also appended to `quota-history.jsonl` for time-series tracking. ## Performance The quota export runs asynchronously (fire-and-forget) so it doesn't impact response latency. Errors are silently ignored since quota export is non-critical. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Adds an asynchronous “fire-and-forget” quota export after each embedded agent attempt completes. The new infra utilities convert `UsageSummary` into a simplified JSON payload and write it to `~/.openclaw/quota.json`, while also optionally appending JSONL snapshots to `~/.openclaw/quota-history.jsonl` for time-series monitoring. The runner is invoked from the Pi embedded attempt flow and uses existing provider usage loading logic (`loadProviderUsageSummary`). <h3>Confidence Score: 3/5</h3> - Mostly safe to merge, but there are a couple of correctness/path-resolution issues worth fixing first. - Changes are isolated and non-critical (errors are swallowed), but the exported JSON field semantics (`percent`) look inverted vs existing “usedPercent” conventions, and the HOME fallback to an empty string can write to an unintended relative directory in some environments. - src/infra/provider-usage.export.ts <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs