kristianvast/hermes-claude-auth
Claude Code OAuth bypass for hermes-agent
hermes‑claude‑auth – OAuth bypass for the Hermes AI agent
What it is
- A tiny Python‑only patch that lets the hermes‑agent (an open‑source Claude‑based chatbot/assistant) keep using a Claude Code subscription (Max/Pro) after Anthropic added server‑side OAuth validation on 2026‑04‑04.
- It does not modify any hermes‑agent source files. Instead it installs a runtime hook (via a
.pthshim) that monkey‑patches the functionbuild_anthropic_kwargsthe moment the hermes virtual‑environment starts.
Why you might need it
- Without this patch, hermes‑agent’s OAuth flow is rejected and the request falls back to Anthropic’s “extra‑usage” (pay‑per‑token) billing, or simply fails with HTTP 400/401.
- The hook adds the exact billing header, system‑prompt layout, beta flags, and user‑agent fingerprint that Claude Code expects, so the request is treated as a normal subscription call.
- It also adds a subscription‑window aware auto‑wait: when a Claude Pro/Max quota window (5 h, 1 d, 7 d) is exhausted, the agent will sleep until the window resets instead of aborting.
How it works (high‑level)
- Bootstrap – a
.pthfile placed in the hermes venv’ssite‑packagesimports a tiny bootstrap module at interpreter start. - MetaPathFinder hook – the bootstrap registers a finder that intercepts imports of
agent.anthropic_adapterand patchesbuild_anthropic_kwargs. - Billing header – computes a SHA‑256‑signed
x-anthropic-billing-headerand injects it as the first system message. - System‑prompt relocation – moves non‑identity system entries into a
<system‑reminder>block inside the first user message (the format Claude Code expects). - Rate‑limit auto‑wait – on HTTP 429 the hook reads Anthropic’s
anthropic‑ratelimit‑unified‑*‑resetheaders, picks the longest window, sleeps (capped per‑window) and retries transparently. - Fingerprint parity – forces the
user‑agentand billing header to report the same Claude Code version (2.1.112or the locally detected version) and setsx‑app: cliso Anthropic does not treat the request as “extra usage”.
Installation
- Linux/macOS – one‑liner:
curl … | bashor clone the repo and run./install.sh. - Windows – PowerShell one‑liner:
irm … | iexor clone and run. install.ps1. - The installer automatically:
- Detects the hermes data directory (
$HERMES_HOMEor defaults). - Copies
anthropic_billing_bypass.pyto<hermes‑dir>/patches/. - Places the
.pthshim and bootstrap module inside the hermes virtual‑env. - Mirrors Claude Code credentials from the OS credential store to
~/.claude/.credentials.json. - Restarts the
hermes‑gateway.serviceon Linux if it is running.
- Detects the hermes data directory (
Uninstall
- Run
./uninstall.sh(Linux/macOS) or. uninstall.ps1(Windows). Use--purge/-Purgeto also delete the patch file.
Recovery after hermes update
hermes updatecan wipe thesitecustomize.pythat previously held the hook. This repo installs two defenses:- Git hooks placed outside the repo (
core.hooksPath) that re‑run the installer after a merge. - A cron‑style watchdog (
restore_loader.sh) that restores the loader every 15 min while the Hermes gateway is up.
- Git hooks placed outside the repo (
- The installer also provides
--post-updateand--checkflags to verify that the patch file matches the repo and to restore a missing loader.
Verification After installation, you should see lines like:
[anthropic_billing_bypass] Bypass installed
[anthropic_billing_bypass] Rate‑limit auto‑wait installed
in the Hermes gateway logs. A successful chat command such as:
hermes chat --provider anthropic -m claude‑sonnet‑4‑6 -q "OK" -Q
should complete without extra usage or HTTP 400 errors.
Compatibility
- hermes‑agent ≥ Python 3.11, Linux/macOS/Windows.
- Works with multiple hermes profiles; the patch lives at the data‑root and is shared.
- Relies on the internal function
build_anthropic_kwargs(is_oauth=…); if hermes‑agent changes that signature the patch will need an update.
Key take‑aways
- No source code changes – everything is applied at runtime via import hooks.
- Handles both OAuth validation and subscription‑window throttling, turning a hard failure into a graceful wait‑and‑retry.
- Self‑healing – git‑hook + cron recovery keep the bypass alive across hermes updates.
All details above are taken directly from the repository’s README; no additional features have been inferred.
Related
- Project
- Project
- Dispatch
- Project
- Project