teknium1
5e12442b4b
feat: native Anthropic provider with Claude Code credential auto-discovery
Add Anthropic as a first-class inference provider, bypassing OpenRouter
for direct API access. Uses the native Anthropic SDK with a full format
adapter (same pattern as the codex_responses api_mode).
## Auth (three methods, priority order)
1. ANTHROPIC_API_KEY env var (regular API key, sk-ant-api-*)
2. ANTHROPIC_TOKEN / CLAUDE_CODE_OAUTH_TOKEN env var (setup-token, sk-ant-oat-*)
3. Auto-discovery from ~/.claude/.credentials.json (Claude Code subscription)
- Reads Claude Code's OAuth credentials
- Checks token expiry with 60s buffer
- Setup tokens use Bearer auth + anthropic-beta: oauth-2025-04-20 header
- Regular API keys use standard x-api-key header
## Changes by file
### New files
- agent/anthropic_adapter.py — Client builder, message/tool/response
format conversion, Claude Code credential reader, token resolver.
Handles system prompt extraction, tool_use/tool_result blocks,
thinking/reasoning, orphaned tool_use cleanup, cache_control.
- tests/test_anthropic_adapter.py — 36 tests covering all adapter logic
### Modified files
- pyproject.toml — Add anthropic>=0.39.0 dependency
- hermes_cli/auth.py — Add 'anthropic' to PROVIDER_REGISTRY with
three env vars, plus 'claude'/'claude-code' aliases
- hermes_cli/models.py — Add model catalog, labels, aliases, provider order
- hermes_cli/main.py — Add 'anthropic' to --provider CLI choices
- hermes_cli/runtime_provider.py — Add Anthropic branch returning
api_mode='anthropic_messages' (before generic api_key fallthrough)
- hermes_cli/setup.py — Add Anthropic setup wizard with Claude Code
credential auto-discovery, model selection, OpenRouter tools prompt
- agent/auxiliary_client.py — Add claude-haiku-4-5 as aux model
- agent/model_metadata.py — Add bare Claude model context lengths
- run_agent.py — Add anthropic_messages api_mode:
* Client init (Anthropic SDK instead of OpenAI)
* API call dispatch (_anthropic_client.messages.create)
* Response validation (content blocks)
* finish_reason mapping (stop_reason -> finish_reason)
* Token usage (input_tokens/output_tokens)
* Response normalization (normalize_anthropic_response)
* Client interrupt/rebuild
* Prompt caching auto-enabled for native Anthropic
- tests/test_run_agent.py — Update test_anthropic_base_url_accepted to
expect native routing, add test_prompt_caching_native_anthropic
2026-03-12 15:47:45 -07:00
..
2026-03-12 00:29:04 -07:00
2026-03-11 09:22:32 +01:00
2026-02-28 14:28:04 +03:00
2026-03-11 09:15:31 -07:00
2026-03-12 08:08:22 -07:00
2026-03-04 19:35:01 -08:00
2026-03-11 20:14:44 -07:00
2026-03-10 00:35:14 -07:00
2026-03-12 06:27:21 -07:00
2025-10-01 23:29:25 +00:00
2026-03-12 01:23:28 -07:00
2026-03-12 01:23:28 -07:00
2026-03-10 15:22:44 -07:00
2026-03-12 01:23:28 -07:00
2026-03-11 06:52:55 -07:00
2026-03-11 06:52:55 -07:00
2026-03-12 15:47:45 -07:00
2026-03-07 21:00:12 -05:00
2026-03-06 05:50:12 -08:00
2026-03-01 19:59:24 -08:00
2026-03-02 17:18:15 +11:00
2026-03-11 21:06:54 -07:00
2026-03-06 05:50:12 -08:00
2026-03-10 06:05:02 -07:00
2026-03-10 17:31:00 -07:00
2026-03-11 23:06:06 -07:00
2026-03-11 22:04:42 -07:00
2026-03-08 20:22:33 -07:00
2026-03-08 18:30:27 -07:00
2026-03-09 21:01:40 -07:00
2026-03-01 19:59:24 -08:00
2026-03-11 21:38:29 -07:00
2026-03-09 02:19:32 -07:00
2026-03-11 21:06:54 -07:00
2026-03-09 23:59:26 -07:00
2026-03-01 03:12:37 -05:00
2026-03-06 14:50:57 -08:00
2026-03-11 06:52:55 -07:00
2026-03-10 17:12:34 -07:00
2026-03-05 18:46:30 -08:00
2026-03-09 17:31:54 +03:00
2026-03-07 10:14:19 -08:00
2026-03-09 07:38:06 +03:00
2026-03-12 05:38:19 -07:00
2026-03-08 17:45:45 -07:00
2026-03-11 04:28:31 -07:00
2026-03-12 15:47:45 -07:00
2026-03-11 20:14:44 -07:00
2026-03-11 08:42:04 -07:00
2026-03-11 06:52:55 -07:00
2026-02-26 13:54:20 +03:00
2026-03-09 23:27:19 -07:00
2026-02-28 21:28:28 +03:00
2026-03-07 21:05:40 -08:00