API Configuration
These environment variables are required for authenticating with AI providers.API key for Anthropic Claude models.You can also use the OAuth configuration flow:
OAuth refresh token for Anthropic. Alternative to To get your refresh token:
ANTHROPIC_API_KEY.Useful for Docker/container deployments where you want to use OAuth instead of API keys.- Run
agentuse auth login anthropiclocally - Extract from
~/.local/share/agentuse/auth.json
API key for OpenAI GPT models.
API key for OpenRouter service.
Custom API Key Suffixes
You can use multiple API keys by adding suffixes:Serve Mode
API key for authenticating requests to the serve mode HTTP server.
Required when binding to exposed hosts (not Clients authenticate via Bearer token:
127.0.0.1 or localhost).Behavior Control
Override the maximum number of conversation steps (LLM generation cycles) an agent can take.
Default: 100Precedence: This environment variable overrides the
maxSteps value in agent YAML files.This prevents infinite loops and controls cost by limiting the number of LLM calls. Each step typically involves an LLM generation with potential tool calls.The default was reduced from 1000 to 100 for better cost protection. Most agents complete successfully within 100 steps.
Context Management
Enable or disable automatic context compaction when approaching model limits.
Default: true (enabled)When enabled, AgentUse automatically compacts older messages when context approaches the model’s token limit.
Percentage of context limit to trigger compaction.
Default: 0.7 (70%)Must be a decimal between 0 and 1.
Number of recent messages to preserve during compaction.
Default: 3These messages are never compacted to maintain conversation flow.
Logging and Debug
Set the logging level for AgentUse output.
Default: INFOControls which messages are displayed during execution.
Enable debug logging and verbose output.
Default: falseShows detailed execution information, tool calls, and internal state.
Telemetry
Disable anonymous telemetry collection. No prompts, code, or file paths are ever collected.
Default: false (telemetry enabled)
Storage
Override the default data directory for session logs and project data.
Default: Session logs are stored at
~/.local/share$XDG_DATA_HOME/agentuse/project/{git-hash}/session/.See Session Logs for more details.Development Variables
For local development with self-signed certificates (HTTPS testing).
MCP Server Environment Variables
Security by Design: AgentUse intentionally prevents hardcoding secrets in
.agentuse files. All sensitive values must come from environment variables, keeping your secrets secure and out of version control.The Security Model
MCP servers can access environment variables through two fields:requiredEnvVars: Variables that MUST exist or the agent fails immediatelyallowedEnvVars: Variables that are passed through if they exist (optional)
Why This Design?
- No Secrets in Code:
.agentusefiles are often committed to version control - Clear Requirements: Developers know exactly what env vars are needed
- Early Failure: Missing required vars fail fast with clear error messages
- Security Allowlist: Only explicitly allowed vars are passed to MCP servers
Setting Environment Variables
- Option 1: .env File (Recommended)
- Option 2: Shell Export
- Option 3: Inline Command
- Option 4: Secret Managers
Create a AgentUse automatically loads
.env file in your project root:.env files from the project root (detected via .git/, .agentuse/, or package.json).Override Options:Error Messages
AgentUse provides clear, actionable error messages:Complete Example
.env file:
Using .env Files
AgentUse automatically loads.env files if present in your project directory:
Never commit
.env files to version control. Add them to .gitignore.Priority Order
Environment variables are loaded in this order (later overrides earlier):- System environment variables
.envfile in current directory- Command-line environment variables
Security Best Practices
Store Secrets Securely
Never hardcode API keys in agent files:Use .gitignore
Always exclude sensitive files:Validate Required Variables
For MCP servers that require specific environment variables, they will fail with clear error messages if the variables are not set.Troubleshooting
API key not found
API key not found
Verify the environment variable is set:If empty, set it:Or use the auth command:
Wrong API key being used
Wrong API key being used
Check which key is being used:The tool prioritizes OAuth tokens over API keys for Anthropic.
MAX_STEPS not working
MAX_STEPS not working
Ensure you’re setting it before running the agent:
