-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Problem
Currently, gitclaw requires explicit model configuration to start. If a user has API keys set in their shell (e.g. ANTHROPIC_API_KEY, OPENAI_API_KEY) or in a .env file,
gitclaw does not detect them or pick a default model automatically. Instead it fails with:
No model configured. Either:
- Set model.preferred in agent.yaml (e.g., "anthropic:claude-sonnet-4-5-20250929")
- Pass --model provider:model on the command line
Users must always either edit agent.yaml or pass --model provider:model manually, even when valid API keys are already available in the environment.
Additionally, there is no .env file support — API keys must be exported in the shell.
Expected Behavior
gitclaw should work out of the box when an API key is present:
- Auto-detect available API keys — On startup, check for known environment variables (
ANTHROPIC_API_KEY,OPENAI_API_KEY,GOOGLE_API_KEY,XAI_API_KEY,
GROQ_API_KEY,MISTRAL_API_KEY) - Pick a sensible default model — If no model is configured in
agent.yamlor via--model, automatically select the latest/best model for the first available API key.
Suggested defaults:ANTHROPIC_API_KEY→anthropic:claude-sonnet-4-5-20250929OPENAI_API_KEY→openai:gpt-4oGOOGLE_API_KEY→google:gemini-2.0-flash- (etc.)
- Support
.envfiles — Load.envfrom the agent directory (and/or home directory) so users can persist their API keys without exporting in every shell session
The resolution priority should remain:
--model flag > agent.yaml model.preferred > env config override > auto-detected from API key
Current Code
API key validation (src/index.ts:468-484) already has the provider-to-env-var mapping:
const apiKeyEnvVars: Record<string, string> = {
anthropic: "ANTHROPIC_API_KEY",
openai: "OPENAI_API_KEY",
google: "GOOGLE_API_KEY",
xai: "XAI_API_KEY",
groq: "GROQ_API_KEY",
mistral: "MISTRAL_API_KEY",
}; But this is only used to validate after a model is already chosen — not to auto-detect which provider to use.
Model resolution (src/loader.ts:354-360) throws an error when no model is configured instead of falling back to auto-detection.
Suggested Fix
- Add .env loading — Use dotenv (or Node's --env-file) to load .env from the agent directory early in startup
- Add auto-detection in loadAgent() — When no model is configured via any existing method, iterate through apiKeyEnvVars and pick the first available provider with a sensible
default model - Log the choice — Print which model was auto-selected so the user knows (e.g. Using anthropic:claude-sonnet-4-5-20250929 (detected ANTHROPIC_API_KEY))