Config System
One-line summary
The config system loads, validates, and manages openclaw.json — a JSON5 configuration file with environment variable substitution, include resolution, Zod validation, and atomic writes with backup rotation.
Responsibilities
- Parse JSON5 config with
${ENV_VAR}substitution and$includeresolution - Validate against Zod schema (
OpenClawSchema) with plugin config extensions - Migrate legacy config formats automatically
- Provide cached config access with invalidation
- Perform atomic writes (temp file + rename) with backup rotation
- Audit log config changes
Architecture diagram
Key source files
OpenClawConfig structure (30+ sections)
Key token-related settings:
agents.defaults.compaction.reserveTokensFloor— compaction triggeragents.defaults.compaction.reserveTokens— reserve budgetagents.defaults.compaction.keepRecentTokens— recent history protectionskills.limits.*— skill catalog limitstools.allow/deny— tool policymemory.*— RAG settings
How it connects to other modules
- Depends on:
zod(validation),json5(parsing), file system - Depended by: Every module reads
OpenClawConfig— this is the universal settings source
My blind spots
-
$includeresolution — how deep nesting works and circular reference prevention - Plugin config schema registration — how extensions add their own validation
- Backup rotation — how many backups are kept and rotation strategy
- Shell env fallback —
env.shellEnvbehavior - Config change event propagation — how subsystems react to config updates
Change frequency
io.ts: Medium — migration logic and env handling evolvezod-schema.ts: High — every new feature adds config sectionstypes.openclaw.ts: High — mirrors zod-schema changes