Feature Request: Support passing environment variables via settings.json
What feature would you like to see?
Feature Request: Support passing environment variables via settings.json
Description
Currently, hapi CLI does not support configuring environment variables (like ANTHROPIC_AUTH_TOKEN,
ANTHROPIC_BASE_URL) through settings.json. Users must set these environment variables in their shell before
running hapi, which is not convenient for configuration management.
Additional information
No response
Thanks for request. Current CLI settings only cover cliApiToken, serverUrl (plus machineId/daemon flags). No settings.json support for ANTHROPIC_AUTH_TOKEN or ANTHROPIC_BASE_URL found; only env vars read are HAPI_SERVER_URL + CLI_API_TOKEN.
Relevant code:
cli/src/persistence.ts:13- settings schema fieldscli/src/ui/tokenInit.ts:4- settings/env forCLI_API_TOKENcli/src/ui/serverUrlInit.ts:4- settings/env forHAPI_SERVER_URLcli/src/configuration.ts:31- env defaults for server url + token
Need more info:
- Which env keys should be supported in
settings.json(only ANTHROPIC_* or more)? - Precedence preference: env over settings or settings over env?
- Scope: apply to CLI process only, or also daemon/terminal sessions?
HAPI Bot
https://code.claude.com/docs/en/settings#available-settings
Actually, the Claude Code SDK does support passing ANTHROPIC_AUTH_TOKEN and ANTHROPIC_BASE_URL. This is the approach used by other platforms as well.
Reference: wecode-ai/Wegent executor/agents/claude_code/claude_code_agent.py
env_config = {
"ANTHROPIC_MODEL": model_id,
"ANTHROPIC_SMALL_FAST_MODEL": env.get("small_model", model_id),
"ANTHROPIC_DEFAULT_HAIKU_MODEL": env.get("small_model", model_id),
"ANTHROPIC_AUTH_TOKEN": env.get("api_key", ""),
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": int(
os.getenv("CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC", "0")
),
}
base_url = env.get("base_url", "")
if base_url:
env_config["ANTHROPIC_BASE_URL"] = base_url.removesuffix("/v1")
As the code shows:
- The SDK supports passing the API key via ANTHROPIC_AUTH_TOKEN in env
- The SDK supports custom API endpoints via ANTHROPIC_BASE_URL in env
- This is a common pattern implemented by other platforms
@tiann
You can put it into ~/.claude/settings.json
My apologies for the confusion. Let me clarify.
From my understanding, the Claude Code SDK does not directly read ~/.claude/settings. In this project, sessions created directly on the web interface are launched based on the Claude Code SDK.
In this scenario, could it cause the session to directly access Anthropic's endpoint instead of the user-configured custom endpoint?
The concern is: when a session is initiated through the SDK (rather than a local CLI session), does it bypass any custom endpoint configuration and default to Anthropic's official API?
Thank you for your reply.
@tiann
No, the remote mode will also respect this configuration file.