#7806: feat: export quota info to ~/.openclaw/quota.json after each agent run
agents
stale
Cluster:
TUI and Tool Execution Fixes
## 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
#14054: #13923 ----[Feature] -- Provider-rate-limit-/-quota-query-tool
by harshmohite04 · 2026-02-11
81.7%
#21076: feat(quota): unify provider quota tracking and usage UI across prov...
by romeroej2 · 2026-02-19
80.9%
#6014: Agents: improve quota exhaustion fallback detection
by erain · 2026-02-01
71.6%
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
71.1%
#22627: control-ui: agent runner queue view
by vctorabrdge · 2026-02-21
69.4%
#10006: feat: add append-only spend ledger for token usage tracking
by oldeucryptoboi · 2026-02-06
69.2%
#19251: CLI: emit diagnostics for embedded Slack-context runs
by gg2uah · 2026-02-17
68.9%
#13792: Claude/openclaw token efficiency q ni2s
by imecostalima · 2026-02-11
68.8%
#22140: feat(config): add usageDefault to agent defaults for persistent /us...
by Mellowambience · 2026-02-20
68.7%
#20428: feat: capture Anthropic rate-limit response headers to disk
by AndrewArto · 2026-02-18
68.7%