Overview
Environment variables control your agent's behavior, API keys, and configuration. You can update them at any time through the instance configuration page.
How to Update Environment Variables
- Navigate to your instance details page
- Click the "Configuration" tab
- In the "Environment Variables" section, find the variable to update
- Click the "Edit" button next to the variable
- Enter the new value
- Click "Save Changes"
- Important: Restart your instance for changes to take effect
Adding New Variables
- Go to the Configuration tab
- Scroll to the "Environment Variables" section
- Click "Add Variable"
- Enter the variable name (e.g.,
NEW_VARIABLE) - Enter the value
- Click "Save"
- Restart the instance
Deleting Variables
- Find the variable in the Configuration tab
- Click the "Delete" button
- Confirm the deletion
- Restart the instance
Note: Deleted variables are permanently removed from encrypted storage.
Common Variables to Update
API Keys
OPENAI_API_KEY- When rotating OpenAI keysANTHROPIC_API_KEY- When rotating Anthropic keysOPENROUTER_API_KEY- When switching to OpenRouter
Bot Tokens
TELEGRAM_BOT_TOKEN- When regenerating Telegram tokenDISCORD_BOT_TOKEN- When regenerating Discord token
Configuration
AI_MODEL- Switch between models (e.g.,gpt-4,claude-4.5-sonnet)SYSTEM_PROMPT- Update agent personality/instructionsMAX_TOKENS- Adjust response length limitsTEMPERATURE- Control randomness (0.0-2.0)
Why Restart is Required
Environment variables are loaded when the instance starts. Changes don't take effect until the instance restarts because:
- Variables are read once at startup
- OpenClaw caches configuration in memory
- API connections are established with original values
- Restart ensures clean initialization with new values
Best Practices
Before Updating
- Document current values: Keep a backup of working configuration
- Plan downtime: Restart causes brief interruption (30-60 seconds)
- Test new values: Verify API keys work before updating
- Update during low traffic: Minimize impact on users
During Update
- Double-check values: Verify no typos or extra spaces
- Update related variables together: E.g., change both
AI_MODELand API key if switching providers - Save before restarting: Ensure changes are committed
After Update
- Check logs: Verify successful restart with new values
- Test functionality: Send a test message to your bot
- Monitor for errors: Watch logs for authentication issues
Security Considerations
Variable Values Are Hidden
For security, environment variable values are never displayed after being saved. You can see variable names but not values.
Encryption
All environment variables are encrypted at rest using AES-256-GCM encryption. Only your running instance can decrypt them.
Key Rotation
Regularly rotate API keys for security:
- Create new API key in provider dashboard
- Update environment variable in AgentClaw
- Restart instance
- Verify new key works
- Revoke old key in provider dashboard
Bulk Updates
To update multiple variables at once:
- Update all variables in the Configuration tab
- Click "Save Changes" (saves all at once)
- Restart instance once for all changes
This is more efficient than restarting after each individual change.
Common Update Scenarios
Switching AI Providers
- Add new provider's API key (e.g.,
ANTHROPIC_API_KEY) - Update
AI_MODELto new model name - Save and restart
- Optional: Remove old API key if not needed
Changing Bot Personality
- Update
SYSTEM_PROMPTwith new instructions - Optionally adjust
TEMPERATUREfor creativity - Save and restart
- Test with sample messages
Reducing Costs
- Switch
AI_MODELto cheaper model (e.g.,gpt-3.5-turbo) - Reduce
MAX_TOKENSto limit response length - Save and restart
- Monitor quality and adjust as needed
Troubleshooting
Changes Not Taking Effect
- Verify you clicked "Save Changes"
- Ensure you restarted the instance
- Check logs for errors during startup
- Wait for instance to fully start before testing
Instance Won't Start After Update
- Check logs for specific error messages
- Verify new API key is correct
- Ensure no typos in variable names or values
- Try reverting to previous working values
- See instance won't start guide
Lost Previous Value
Since values are hidden after saving, if you lose a working value:
- Cannot retrieve from AgentClaw (security measure)
- Must get new value from original source (e.g., OpenAI dashboard)
- Update with new value and restart
Variable Naming Conventions
- Use UPPERCASE for variable names
- Separate words with underscores:
MY_VARIABLE - Be descriptive:
OPENAI_API_KEYnotKEY1 - Follow OpenClaw conventions for compatibility
Next Steps
- Learn about adding API keys securely
- Read the complete environment variables guide
- Understand restarting instances
- See how to read logs after updates