Flux-CLI

Environment Variables

Flux-CLI uses environment variables for sensitive configuration that should not be stored in configuration files.

Core Variables

VariableRequiredDefaultDescription
API_KEY✅ YesYour LLM provider API key
BASE_URL❌ Nohttps://openrouter.ai/api/v1API base URL for the LLM provider

Using .env Files

Create a .env file in your working directory:

.env

Dotenv files are loaded automatically by Flux-CLI on startup.

# Required: Your API key
API_KEY=sk-or-v1-your-key-here

# Optional: Override the base URL
BASE_URL=https://openrouter.ai/api/v1

How Environment Variables Are Loaded

  1. Dotenv loadingmain.py calls dotenv.load_dotenv() to load .env files
  2. Config file fallback — If api_key or base_url is set in the TOML config, it's exported to the environment
  3. Environment override — Existing environment variables take precedence
Config to environment flow

Configuration values are exported to the environment if not already set.

# From config/loader.py
if "api_key" in config_dict and isinstance(config_dict["api_key"], str):
  if not os.environ.get("API_KEY"):
      os.environ["API_KEY"] = config_dict["api_key"]

if "base_url" in config_dict and isinstance(config_dict["base_url"], str):
  if not os.environ.get("BASE_URL"):
      os.environ["BASE_URL"] = config_dict["base_url"]

Hook Environment Variables

When lifecycle hooks execute, the following environment variables are available:

VariableTriggerDescription
AI_AGENT_TRIGGERAllThe hook trigger name
AI_AGENT_CWDAllThe current working directory
AI_AGENT_USER_MESSAGEBefore/After AgentThe user's message
AI_AGENT_RESPONSEAfter AgentThe agent's response
AI_AGENT_TOOL_NAMEBefore/After ToolThe tool being executed
AI_AGENT_TOOL_PARAMSBefore/After ToolJSON-serialized tool parameters
AI_AGENT_TOOL_RESULTAfter ToolThe tool execution result
AI_AGENT_ERROROn ErrorThe error message

Shell Environment Variables

When executing shell commands, Flux-CLI sanitizes the environment:

On this page