Skip to content

The agent that grows with you

feat(cli): `hermes usage [--json]` prints the /usage account limits without a session

teknium185b2a3df6c2d
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 069cc050663..1abdabc92fe 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -380,6 +380,7 @@ from hermes_cli.subcommands.memory import build_memory_parser
from hermes_cli.subcommands.acp import build_acp_parser
from hermes_cli.subcommands.tools import build_tools_parser
from hermes_cli.subcommands.insights import build_insights_parser
+from hermes_cli.subcommands.usage import build_usage_parser
from hermes_cli.subcommands.monitoring import build_monitoring_parser
from hermes_cli.subcommands.skills import build_skills_parser
from hermes_cli.subcommands.pairing import build_pairing_parser
@@ -2449,7 +2450,7 @@ def _coalesce_session_name_args(argv: list) -> list:
"auth", "status", "cron", "doctor", "config", "pairing", "skills", "tools", "mcp",
"sessions", "insights", "update", "uninstall", "profile", "dashboard", "serve",
"desktop", "gui", "honcho", "claw", "plugins", "security", "acp", "webhook", "peer",
- "memory", "dump", "debug", "backup", "import", "completion", "logs",
+ "memory", "dump", "debug", "backup", "import", "completion", "logs", "usage",
}
_SESSION_FLAGS = {"-c", "--continue", "-r", "--resume"}
@@ -2743,7 +2744,7 @@ _BUILTIN_SUBCOMMANDS = frozenset(
"resume",
"send", "sessions", "setup",
"skin", "skills", "slack", "status", "sync", "tools", "uninstall", "update",
- "vault",
+ "usage", "vault",
"webhook", "whatsapp", "whatsapp-cloud", "worktree", "chat", "secrets", "security",
"browser",
"verify",
@@ -3386,6 +3387,7 @@ def _build_cli_parser():
build_mcp_parser(subparsers, cmd_mcp=cmd_mcp)
build_sessions_parser(subparsers, cmd_sessions=_cmd_sessions_lazy)
build_insights_parser(subparsers, cmd_insights=cmd_insights)
+ build_usage_parser(subparsers)
build_monitoring_parser(subparsers, cmd_monitoring=cmd_monitoring)
build_claw_parser(subparsers, cmd_claw=cmd_claw)
build_vault_parser(subparsers)
diff --git a/hermes_cli/subcommands/usage.py b/hermes_cli/subcommands/usage.py
new file mode 100644
index 00000000000..4779ac89476
--- /dev/null
+++ b/hermes_cli/subcommands/usage.py
@@ -0,0 +1,73 @@
+"""``hermes usage`` — the account-limits block of the REPL ``/usage`` without starting a session.
+
+Script-friendly Codex / Anthropic / OpenRouter quota view (issue #33094): same fetch and renderer as
+``/usage`` (``agent.account_usage``), same credential resolution as a session with no live agent, plus
+``--json`` for cron jobs and shell loops. Slim redo of #81819 (@himanusia).
+"""
+
+from __future__ import annotations
+
+import argparse
+import json
+import sys
+
+
+def usage_snapshot_document(snapshot) -> dict:
+ """``hermes usage --json`` document. Schema is documented in website/docs/reference/cli-commands.md —
+ keep the keys stable; extend only by adding keys."""
+ return {
+ "provider": snapshot.provider,
+ "source": snapshot.source,
+ "title": snapshot.title,
+ "plan": snapshot.plan,
+ "fetched_at": snapshot.fetched_at.isoformat(),
+ "windows": [
+ {
+ "label": window.label,
+ "used_percent": window.used_percent,
+ "resets_at": window.reset_at.isoformat() if window.reset_at else None,
+ "detail": window.detail,
+ }
+ for window in snapshot.windows
+ ],
+ "details": list(snapshot.details),
+ "unavailable_reason": snapshot.unavailable_reason,
+ }
+
+
+def cmd_usage(args: argparse.Namespace) -> int:
+ """Print the configured (or ``--provider``) account's usage windows; exit 1 when nothing could be fetched."""
+ from agent.account_usage import fetch_account_usage, render_account_usage_lines
+ from hermes_cli.runtime_provider import resolve_requested_provider
+
+ provider = resolve_requested_provider(getattr(args, "provider", None))
+ # No explicit key: the fetcher resolves the credential exactly as a session without a live agent
+ # would (singleton store, then credential pool) — it never adopts or refreshes anything else.
+ snapshot = fetch_account_usage(provider)
+ if snapshot is None:
+ print(
+ f"No account usage available for provider '{provider}': no credential is configured for it, "
+ "the provider has no usage endpoint, or the fetch failed.",
+ file=sys.stderr,
+ )
+ return 1
+ if getattr(args, "json", False):
+ print(json.dumps(usage_snapshot_document(snapshot), indent=2))
+ else:
+ print("\n".join(render_account_usage_lines(snapshot)))
+ return 0
+
+
+def build_usage_parser(subparsers) -> None:
+ """Attach the ``usage`` subcommand to ``subparsers``."""
+ usage_parser = subparsers.add_parser(
+ "usage", help="Show account rate-limit windows (the /usage block) without starting a session",
+ description="Fetch the configured provider's account limits (Codex 5h/weekly windows, plan, banked "
+ "resets; Anthropic OAuth windows; OpenRouter credits) — the same block the /usage slash "
+ "command prints — and exit. Exit code 1 when no credential is configured or the fetch fails.",
+ )
+ usage_parser.add_argument(
+ "--provider", default=None, help="Provider to query (default: the configured model provider)")
+ usage_parser.add_argument(
+ "--json", action="store_true", help="Print one JSON document instead of the human-readable block")
+ usage_parser.set_defaults(func=cmd_usage)
diff --git a/tests/hermes_cli/test_usage_command.py b/tests/hermes_cli/test_usage_command.py
new file mode 100644
index 00000000000..f6d68c855d5
--- /dev/null
+++ b/tests/hermes_cli/test_usage_command.py
@@ -0,0 +1,64 @@
+"""``hermes usage`` — the non-interactive /usage surface (issue #33094).
+
+Drives the real ``hermes`` argparse entrypoint; only the network fetch is replaced with a snapshot
+(``agent.account_usage.fetch_account_usage`` is what ``cmd_usage`` reads at call time).
+"""
+
+import json
+import sys
+from datetime import datetime, timezone
+from unittest.mock import patch
+
+from agent.account_usage import AccountUsageSnapshot, AccountUsageWindow
+from hermes_cli import main as hermes_main
+
+_SNAPSHOT = AccountUsageSnapshot(
+ provider="openai-codex", source="usage_api", fetched_at=datetime(2026, 9, 19, 12, 0, tzinfo=timezone.utc),
+ plan="Plus",
+ windows=(
+ AccountUsageWindow(label="Session", used_percent=37.0, reset_at=datetime(2026, 9, 19, 21, 0, tzinfo=timezone.utc)),
+ AccountUsageWindow(label="Weekly", used_percent=12.5, reset_at=None),
+ ),
+ details=("You have 1 reset banked - use /usage reset to activate",),
+)
+
+
+def _run(argv, fetch):
+ with patch.object(hermes_main, "_plugin_cli_discovery_needed", return_value=False), \
+ patch("agent.account_usage.fetch_account_usage", fetch), \
+ patch.object(sys, "argv", ["hermes", *argv]):
+ try:
+ hermes_main.main()
+ except SystemExit as exc:
+ return int(exc.code or 0)
+ return 0
+
+
+def test_hermes_usage_json_is_one_stable_document(capsys):
+ calls = []
+
+ def fetch(provider, **kwargs):
+ calls.append(provider)
+ return _SNAPSHOT
+
+ assert _run(["usage", "--json", "--provider", "openai-codex"], fetch) == 0
+ out, err = capsys.readouterr()
+ doc = json.loads(out)
+ assert calls == ["openai-codex"] and err == ""
+ assert doc["provider"] == "openai-codex" and doc["plan"] == "Plus"
+ assert doc["fetched_at"] == "2026-09-19T12:00:00+00:00"
+ assert doc["windows"] == [
+ {"label": "Session", "used_percent": 37.0, "resets_at": "2026-09-19T21:00:00+00:00", "detail": None},
+ {"label": "Weekly", "used_percent": 12.5, "resets_at": None, "detail": None},
+ ]
+ assert doc["details"] == ["You have 1 reset banked - use /usage reset to activate"]
+ assert set(doc) == {"provider", "source", "title", "plan", "fetched_at", "windows", "details", "unavailable_reason"}
+
+
+def test_hermes_usage_without_credential_exits_nonzero_with_one_stderr_line(capsys):
+ # fetch_account_usage returns None when no credential resolves (or the fetch fails) — script-friendly failure.
+ assert _run(["usage", "--json", "--provider", "openai-codex"], lambda provider, **kw: None) == 1
+ out, err = capsys.readouterr()
+ assert out == ""
+ assert err.count("\n") == 1 and "openai-codex" in err
+
diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.md
index e0f51a63f99..f861c604d02 100644
--- a/website/docs/reference/cli-commands.md
+++ b/website/docs/reference/cli-commands.md
@@ -58,6 +58,7 @@ hermes [global-options] <command> [subcommand/options]
| `hermes migrate` | Diagnose and (optionally) rewrite `config.yaml` to replace references to retired models or deprecated settings (e.g. `migrate xai`). |
| `hermes codex-runtime` | Noninteractive counterpart of `/codex-runtime`: `migrate [--dry-run] [--json]` regenerates the Hermes-managed block in `~/.codex/config.toml` for the selected profile. See [Codex app-server runtime](../user-guide/features/codex-app-server-runtime.md#running-the-migration-from-a-script). |
| `hermes status` | Show agent, auth, and platform status. |
+| `hermes usage` | Show the configured account's rate-limit windows (the `/usage` block) without a session; `--json` for scripts. |
| `hermes cron` | Inspect and tick the cron scheduler. |
| `hermes pause` / `hermes resume` | Global emergency stop: no new cron fires (built-in ticker, managed-cron webhook, misfire catch-up), kanban dispatch or gateway turns start until resumed; in-flight work is never killed. |
| `hermes kanban` | Multi-profile collaboration board (tasks, links, dispatcher). |
@@ -686,6 +687,49 @@ hermes auth spotify # Authenticate Hermes w
Subcommands: `add`, `list`, `remove`, `reset`, `priority`, `refresh`, `status`, `logout`, `spotify`. When called with no subcommand, launches the interactive management wizard.
+## `hermes usage`
+
+The account-limits block of the `/usage` slash command — Codex 5-hour / weekly windows, plan and banked
+resets; Anthropic OAuth windows; OpenRouter credits — without starting a session, so shell scripts and cron
+jobs can read it.
+
+```bash
+hermes usage # configured model provider, human-readable block
+hermes usage --provider openai-codex # a specific provider
+hermes usage --json # one JSON document on stdout
+```
+
+| Option | Description |
+|--------|-------------|
+| `--provider NAME` | Provider to query (default: the configured `model.provider`). Supported: `openai-codex`, `anthropic`, `openrouter`. |
+| `--json` | Print one JSON document instead of the human-readable block. |
+
+Credentials resolve exactly as they do for `/usage` in a session with no live agent (the auth store, then
+the credential pool); the command never adds or refreshes a credential it would not use for chat. Exit code
+`0` on success; `1` with a single stderr line when no credential is configured for the provider, the provider
+has no usage endpoint, or the fetch fails (stdout stays empty).
+
+`--json` schema (keys are stable; new keys may be added):
+
+```json
+{
+ "provider": "openai-codex",
+ "source": "usage_api",
+ "title": "Account limits",
+ "plan": "Plus",
+ "fetched_at": "2026-09-19T07:58:55+00:00",
+ "windows": [
+ {"label": "Session", "used_percent": 37.0, "resets_at": "2026-09-19T21:00:00+00:00", "detail": null},
+ {"label": "Weekly", "used_percent": 12.5, "resets_at": "2026-09-25T09:00:00+00:00", "detail": null}
+ ],
+ "details": ["You have 1 reset banked - use /usage reset to activate"],
+ "unavailable_reason": null
+}
+```
+
+`used_percent` is `null` when the provider did not report the window; `resets_at` is ISO-8601 UTC or `null`
+(some windows carry a free-text `detail` instead); `plan` is `null` when unknown.
+
## `hermes status`
```bash