Cascading Configuration Resolution
OpenClaw uses a 5-layer cascading configuration system for flexible runtime configuration.
Key Files
src/config/runtime-overrides.ts(92 lines): In-memory runtime overridessrc/config/io.ts: File-based config loading and mergingsrc/config/env-vars.ts: Environment variable application
Resolution Layers (Highest to Lowest Priority)
Layer 1: Runtime Overrides (In-Memory)
- Highest priority
- Set via
setConfigOverride(path, value) - Persisted in memory only, not written to config file
- Used for temporary overrides during execution
From src/config/runtime-overrides.ts:
Layer 2: Environment Variables
- Applied from
process.envwithOPENCLAW_*prefix - Config can define additional env vars via
config.env - Environment variables are resolved during config load
Layer 3: Agent-Specific Config
- Configuration scoped to a specific agent ID
- Defined in
config.agents[agentId] - Merged with higher and lower layers
Layer 4: Session-Level Config
- Configuration specific to a session
- Stored in session metadata
- Overrides global defaults but yields to higher layers
Layer 5: Global Defaults
- Lowest priority, fallback values
- Defined in
src/agents/defaults.ts,src/config/defaults.ts - Applied when no higher layer provides a value
Merge Strategy
Deep Merge for Objects
Arrays: Replace Entirely
- Arrays are not merged element-by-element
- Higher-priority array completely replaces lower-priority array
Prototype-Polluting Keys Blocked
From src/config/prototype-keys.ts:
Tool Policy Cascading
Tool policies use a similar 7-layer cascading allowlist system:
- Runtime overrides
- Environment variables
- Agent-specific policy
- Session-level policy
- User-level policy
- Tool-specific defaults
- Global defaults
Each layer is an allowlist that merges with lower layers.
Config Hot-Reload
OpenClaw supports hot-reloading configuration files via chokidar:
- Watcher: Monitors config file for changes
- Debounce: 300ms delay to batch rapid changes
- Modes:
off: No watchingrestart: Restart process on changehot: Reload config in-placehybrid: Hot-reload with restart fallback