Xerg
by @xerg
Audit and reduce AI agent spend in dollars. Use when the user asks about AI costs, agent spend, token waste, retry loops, model downgrades, per-agent spend,...
clawhub install xergπ About This Skill
name: xerg description: Audit OpenClaw and Hermes workflows in dollars. Local-first audits with init, compare mode, OpenClaw remote support, CI gates, and optional hosted follow-up. homepage: https://xerg.ai metadata: openclaw: homepage: https://xerg.ai links: repository: https://github.com/xergai/xerg documentation: https://xerg.ai/docs primaryEnv: XERG_API_KEY requires: anyBins: - xerg - npx config: - ~/.xerg/config.json - ~/.config/xerg/credentials.json - ~/.xerg/remotes.json install: - kind: node package: "@xerg/cli" bins: - xerg envVars: - name: XERG_API_KEY required: false description: Optional Xerg Cloud workspace API key for explicit push, connect, and hosted MCP setup. - name: XERG_API_URL required: false description: Optional override for the Xerg API endpoint; defaults to https://api.xerg.ai. dependencies: - name: "@xerg/cli" type: npm repository: https://github.com/xergai/xerg - name: ssh type: other url: https://www.openssh.com/ - name: rsync type: other url: https://rsync.samba.org/ - name: railway type: npm repository: https://github.com/railwayapp/cli
Xerg
Use xerg if it is already installed. If not, use npx @xerg/cli with the same arguments.
Xerg audits OpenClaw and Hermes workflows in dollars, not tokens. It reads gateway logs and session transcripts, surfaces confirmed waste plus savings opportunities, and helps you measure fixes with --compare.
Local audits need no account. Hosted sync and hosted MCP are optional paid workspace features. No data leaves your machine unless you explicitly push results to Xerg Cloud.
The initial npx @xerg/cli path fetches and executes the published npm package. To avoid that runtime fetch, install and review the CLI first with npm install -g @xerg/cli, or use a locally built xerg binary.
Quick Start
xerg init
xerg audit --compare
Use direct commands when you need explicit control, non-interactive behavior, JSON output, or CI gates:
xerg doctor
xerg audit
xerg audit --json
xerg audit --fail-above-waste-rate 0.30
Inputs
Xerg needs one of these source inputs:
/tmp/openclaw/openclaw-*.log
- ~/.openclaw/agents/*/sessions/*.jsonl
~/.hermes/logs/agent.log* with gateway.log* fallback
- ~/.hermes/sessions/
--log-file and/or --sessions-dir--remote--railway--remote-configAdditional requirements:
--compare needs at least one previously stored compatible local snapshotXERG_API_KEY, ~/.xerg/config.json, or browser credentials from xerg loginssh and rsync on your local PATH and are OpenClaw-only in this phaserailway CLI on your local PATH and are OpenClaw-only in this phaseSecurity And Data Flow
Default doctor, init, audit, --compare, --json, and --markdown commands analyze data on the local machine. They read OpenClaw, Hermes, or Cursor usage files, compute economic summaries, print reports, and may write local SQLite snapshots for future comparison.
Remote OpenClaw audits over SSH, Railway, or --remote-config pull selected gateway logs and session files to local temporary storage, then run the same local audit engine. These flows require the corresponding remote transport credentials already configured on the machine.
Hosted sync is opt-in. connect, audit --push, push, and mcp-setup use XERG_API_KEY, ~/.xerg/config.json, or browser login credentials only for Xerg Cloud actions. The push payload contains audit totals, daily rollups, findings, recommendations, comparison deltas, and source metadata; it does not include raw prompt or response content, local source file paths, local database paths, or internal finding details.
Default Flow
1. Start with the default first-run path when you want the fastest local result:
xerg init
init detects local OpenClaw or Hermes data2. Detect sources directly when paths or connectivity are uncertain:
xerg doctor
xerg doctor --verbose
xerg doctor --remote user@host
xerg doctor --railway
xerg doctor --verbose shows progress on stderr while Xerg checks local paths or remote transportsxerg doctor --remote ... or xerg doctor --railway instead of guessing paths3. Run a baseline audit explicitly when you want direct control:
xerg audit
xerg audit --runtime openclaw
xerg audit --runtime hermes
4. Choose the right output mode for the task:
xerg audit
xerg audit --json
xerg audit --markdown
xerg audit is best for a human-readable summaryxerg audit --json is best for automation and agentsxerg audit --markdown is best for a shareable report5. After a workflow or model change, measure the delta:
xerg audit --compare
xerg audit --compare --json
6. Export, push, or hosted-setup only when needed:
xerg audit --markdown > xerg-audit.md
xerg connect
xerg mcp-setup
xerg audit --push
xerg push
connect is the guided hosted path: it reuses existing auth, prompts before browser login when needed, and offers to push the latest auditmcp-setup prints or writes hosted MCP config for Cursor, Claude Code, Codex, or another clientSource Selection
Local defaults:
xerg audit
If both OpenClaw and Hermes are present locally, pass --runtime openclaw or --runtime hermes explicitly.
Explicit local paths:
xerg audit --runtime openclaw --log-file /path/to/openclaw.log
xerg audit --runtime openclaw --sessions-dir /path/to/sessions
xerg audit --runtime hermes --log-file ~/.hermes/logs/agent.log
xerg audit --runtime hermes --sessions-dir ~/.hermes/sessions
SSH remote:
xerg audit --remote user@vps.example.com
xerg audit --remote user@vps.example.com \
--remote-log-file /opt/openclaw/logs/openclaw.log \
--remote-sessions-dir /opt/openclaw/sessions
Railway:
xerg audit --railway
xerg audit --railway --project --environment --service
Multiple remote sources:
xerg audit --remote-config ~/.xerg/remotes.json
Remote config files use this shape:
{
"remotes": [
{
"name": "prod",
"transport": "ssh",
"host": "deploy@prod.example.com"
},
{
"name": "railway-prod",
"transport": "railway",
"railway": {
"projectId": "...",
"environmentId": "...",
"serviceId": "..."
}
}
]
}
CI And Automation
For CI gates, prefer a single command so the audit can still be pushed before threshold failure:
xerg audit --push --fail-above-waste-rate 0.25 --fail-above-waste-usd 100
Common variants:
xerg audit --fail-above-waste-rate 0.30
xerg audit --fail-above-waste-usd 50
xerg audit --since 24h --fail-above-waste-rate 0.30
Documented exit codes:
0 success1 runtime error2 no supported local runtime data found3 threshold exceededAutomation can branch on those codes instead of scraping terminal output.
Recommendations
When using --json, expect a recommendations array alongside the audit summary. Each recommendation item includes:
id, findingId, kind, title, summarypriorityBucket, recommendedOrder, implementationSurface, categoryseverity, confidence, effortestimatedSavingsUsd, estimatedSavingsPctscope, scopeId, scopeLabelwhereToChange, validationPlan, actionsCurrent recommendation kinds map into the Action queue buckets:
fix_now: retry-waste, loop-wastetest_next: context-outlier, idle-spend, candidate-downgrade, cache-carryover, max-mode-concentrationwatch: unknown or uncategorized findingsPrefer high-confidence or reversible fixes first. Treat model downgrades, context changes, and Cursor behavior changes as compare-friendly experiments, not guaranteed savings.
Checks
Before finalizing work that used Xerg:
--compare was used, confirm that it compared against a compatible stored snapshotxerg doctor or use explicit source flags rather than guessingretry-waste, loop-waste) from directional opportunities (context-outlier, idle-spend, candidate-downgrade)Notes
--compare and --no-db cannot be used togetherXERG_API_KEY is recommended for CI and non-interactive automationxerg login; remove stored credentials with xerg logoutquery@xerg.aiπ‘ Examples
xerg init
xerg audit --compare
Use direct commands when you need explicit control, non-interactive behavior, JSON output, or CI gates:
xerg doctor
xerg audit
xerg audit --json
xerg audit --fail-above-waste-rate 0.30
π Tips & Best Practices
--compare and --no-db cannot be used togetherXERG_API_KEY is recommended for CI and non-interactive automationxerg login; remove stored credentials with xerg logoutquery@xerg.ai