Environment Variables
Reference for all environment variables used by swarm — both user-provided and runtime-injected.
User-Provided Variables
These variables must be set in your environment before running swarm:
| Variable | Required | Description |
|---|---|---|
ANTHROPIC_API_KEY | Yes (default) | API key for the Anthropic provider. The env var name can be overridden per-provider via api_key_env in config. |
BRAVE_SEARCH_API_KEY | No | API key for the Brave Search tool (used by web_search) |
HOME | Yes | User home directory. Used to locate ~/.swarm/settings.json and global skills at ~/.claude/skills/. |
Runtime-Injected Variables
These variables are set by swarm and injected into each agent's backend session environment:
| Variable | Value | Description |
|---|---|---|
SWARM_AGENT_ID | Agent name (e.g., "backend") | Identifies the current agent within the swarm session |
SWARM_SESSION_ID | Session ID (e.g., "20250115-a3f2") | Unique identifier for the current session |
SWARM_DB_PATH | Path (e.g., .swarm/messages.db) | Absolute path to the SQLite mailbox database |
SWARM_AGENTS | Comma-separated names (e.g., "backend,frontend,reviewer") | List of all agent names in the session |
These variables allow agent tools and hooks to interact with the swarm infrastructure programmatically.
Logging
| Variable | Default | Description |
|---|---|---|
RUST_LOG | info | Controls log verbosity via the tracing crate. Set to debug for detailed output, warn for quieter operation. Supports per-module filtering (e.g., swarm=debug,rusqlite=warn). |
Provider-Specific Variables
The API key environment variable name is configurable per provider:
{
"providers": {
"default": {
"type": "anthropic",
"api_key_env": "ANTHROPIC_API_KEY"
},
"custom": {
"type": "anthropic",
"api_key_env": "CUSTOM_ANTHROPIC_KEY"
}
}
}
MCP Server Variables
MCP servers configured with the env field receive those environment variables when launched:
{
"mcpServers": {
"myserver": {
"transport": { "type": "stdio", "command": "my-mcp-server" },
"env": {
"MY_SERVER_TOKEN": "secret123"
}
}
}
}
Related
- Configuration — Where env var names are configured
- Agent Lifecycle — How variables are injected into sessions