> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch31-configuration-system/31.2-configuration-type-system-deep-dive.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 31.2 Configuration Type System Deep Dive

> **Generated by**: Claude Opus 4.6 (initial draft) / Claude Opus 5 (`v2026.3.9` revision) **Token usage**: Input \~170k tokens, Output \~7k tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

OpenClaw's configuration type system is the largest collection of type definitions in the entire project—`src/config/types.ts` as a barrel file re-exports over 30 sub-type modules. This section clarifies its core structure to help readers understand the complete picture of the configuration object.

***

## 31.2.1 Core Type Overview (`src/config/types.ts`)

### Modular Splitting

`types.ts` itself is only 32 lines—it's a pure re-export file:

```typescript
// src/config/types.ts
export * from "./types.agent-defaults.js";
export * from "./types.agents.js";
export * from "./types.approvals.js";
export * from "./types.auth.js";
export * from "./types.base.js";
export * from "./types.browser.js";
export * from "./types.channels.js";
export * from "./types.discord.js";
// ... 30+ sub-modules in total
export * from "./types.memory.js";
```

This splitting strategy follows the "edit locality" principle—modifying Telegram configuration types only requires editing `types.telegram.ts`, without triggering recompilation of 20+ other modules.

### Top-Level Structure of OpenClawConfig

`OpenClawConfig` is the root type for all configurations (defined in `types.openclaw.ts`, exported via barrel). The table below lists its main top-level keys:

| Key        | Type Module         | Description                                                   |
| ---------- | ------------------- | ------------------------------------------------------------- |
| `gateway`  | `types.gateway.ts`  | Gateway server settings (port, authentication, remote access) |
| `agents`   | `types.agents.ts`   | Agent list and default configuration                          |
| `models`   | `types.models.ts`   | Model providers and model definitions                         |
| `tools`    | `types.tools.ts`    | Tool configuration (bash, browser, media understanding, etc.) |
| `channels` | `types.channels.ts` | Various channel configurations (WhatsApp, Telegram, etc.)     |
| `hooks`    | `types.hooks.ts`    | Hook system configuration                                     |
| `skills`   | `types.skills.ts`   | Skill system configuration                                    |
| `plugins`  | `types.plugins.ts`  | Plugin system configuration                                   |
| `session`  | `types.base.ts`     | Session management configuration                              |
| `messages` | `types.messages.ts` | Message processing configuration                              |
| `logging`  | `types.base.ts`     | Logging configuration                                         |
| `env`      | —                   | Environment variable definitions                              |
| `meta`     | —                   | Version stamps, metadata                                      |

***

## 31.2.2 Agent Configuration (`types.agents.ts` / `types.agent-defaults.ts`)

### Two-Layer Configuration Structure

Agent configuration uses a **defaults + instance override** two-layer structure:

```typescript
// types.agents.ts
export type AgentsConfig = {
  defaults?: AgentDefaultsConfig;   // Global defaults
  list?: AgentConfig[];             // Agent instance list
};
```

`AgentDefaultsConfig` defines default configuration shared by all Agents—heartbeat settings, model selection, context compression strategy, sandbox behavior, etc. Each `AgentConfig` instance can selectively override these defaults.

### Key Fields of AgentConfig

```typescript
export type AgentConfig = {
  id: string;                       // Unique identifier
  default?: boolean;                // Whether default Agent
  name?: string;                    // Display name
  workspace?: string;               // Workspace directory
  agentDir?: string;                // Agent-specific directory
  model?: AgentModelConfig;         // Model configuration (string or primary+fallbacks object)
  skills?: string[];                // Skill whitelist
  identity?: IdentityConfig;        // Identity configuration (name, theme color, avatar)
  sandbox?: {                       // Sandbox settings
    mode?: "off" | "non-main" | "all";
    workspaceAccess?: "none" | "ro" | "rw";
    scope?: "session" | "agent" | "shared";
    docker?: SandboxDockerSettings;
  };
  tools?: AgentToolsConfig;         // Tool overrides
  subagents?: {                     // Sub-agent configuration
    allowAgents?: string[];
    model?: string | { primary?; fallbacks? };
  };
};
```

Model configuration `AgentModelConfig` supports two syntaxes:

```json5
// Shorthand: directly specify model ID
{ "model": "anthropic/claude-sonnet-4-20250514" }

// Full syntax: specify primary model and fallback models
{
  "model": {
    "primary": "anthropic/claude-sonnet-4-20250514",
    "fallbacks": ["openai/gpt-4o", "google/gemini-2.5-pro"]
  }
}
```

### Fine-Grained Control in Default Configuration

Several nested configurations in `AgentDefaultsConfig` are particularly worth noting:

**Context Pruning**—automatically trim old tool call results when conversations become long:

```typescript
export type AgentContextPruningConfig = {
  mode?: "off" | "cache-ttl";
  ttl?: string;                   // Cache expiration time
  keepLastAssistants?: number;     // Keep last N assistant messages
  softTrimRatio?: number;          // Soft trim threshold (e.g., 0.7 = 70%)
  hardClearRatio?: number;         // Hard clear threshold
  minPrunableToolChars?: number;   // Minimum prunable characters
};
```

**CLI Backend**—allow CLI commands to replace built-in model providers:

```typescript
export type CliBackendConfig = {
  command: string;                 // CLI command
  args?: string[];                 // Arguments
  output?: "json" | "text" | "jsonl";
  input?: "arg" | "stdin";
  modelArg?: string;               // Model argument flag (e.g., --model)
  sessionArgs?: string[];           // Session recovery arguments
};
```

***

## 31.2.3 Channel Configuration (`types.channels.ts` / `types.discord.ts` / `types.telegram.ts` etc.)

Each channel has its own configuration type, but they share some common patterns:

| Channel     | Type File             | Key Configuration Items                  |
| ----------- | --------------------- | ---------------------------------------- |
| WhatsApp    | `types.whatsapp.ts`   | `web` (WebSocket), `allowFrom`, `groups` |
| Telegram    | `types.telegram.ts`   | `botToken`, `webhookSecret`, `groups`    |
| Discord     | `types.discord.ts`    | `botToken`, `guildId`, `threadMode`      |
| Slack       | `types.slack.ts`      | `botToken`, `appToken`, `socketMode`     |
| Signal      | `types.signal.ts`     | `signalCliPath`, `attachmentsDir`        |
| iMessage    | `types.imessage.ts`   | `dbPath`, `pollInterval`                 |
| MS Teams    | `types.msteams.ts`    | `appId`, `appSecret`, `tenantId`         |
| Google Chat | `types.googlechat.ts` | `credentials`, `projectId`               |

Common patterns in channel configuration include:

* **DM Policy**: `pairing` (requires pairing) / `open` (open) / `allowlist` (whitelist)
* **Group Policy**: each group can independently configure whether @mention is required, reply mode, session scope
* **Send Policy**: control which channels/chat types allow Agent to proactively send messages

***

## 31.2.4 Security Configuration (`types.sandbox.ts` / `types.auth.ts`)

### Sandbox Configuration

```typescript
// types.sandbox.ts (partial)
export type SandboxDockerSettings = {
  image?: string;              // Docker image name
  network?: string;            // Network mode
  memory?: string;             // Memory limit
  cpus?: number;               // CPU limit
  extraMounts?: string[];      // Extra mount volumes
  extraArgs?: string[];        // Extra Docker arguments
};
```

Sandbox modes have three levels:

* `"off"` — no sandbox
* `"non-main"` — sandbox only for non-main sessions (default recommended)
* `"all"` — all sessions run in sandbox

### Authentication Configuration

```typescript
// types.auth.ts
export type GatewayAuthConfig = {
  token?: string;              // Gateway access Token
  password?: string;           // Web console password
};
```

***

## 31.2.5 Model Configuration (`types.models.ts`)

Model configuration is designed to be extremely flexible—users can define custom model providers and even integrate privately deployed APIs:

```typescript
export type ModelProviderConfig = {
  baseUrl: string;                    // API endpoint
  apiKey?: string;                    // API key
  auth?: "api-key" | "aws-sdk" | "oauth" | "token";
  api?: ModelApi;                     // API protocol
  headers?: Record<string, string>;   // Custom request headers
  models: ModelDefinitionConfig[];    // Model definition list
};

export type ModelDefinitionConfig = {
  id: string;                         // Model ID
  name: string;                       // Display name
  api?: ModelApi;                     // Override provider-level API protocol
  reasoning: boolean;                 // Whether reasoning mode is supported
  input: Array<"text" | "image">;     // Supported input types
  cost: {                             // Cost information (per million tokens)
    input: number;
    output: number;
    cacheRead: number;
    cacheWrite: number;
  };
  contextWindow: number;              // Context window size
  maxTokens: number;                  // Maximum output tokens
};
```

Supported API protocols include:

| API Identifier            | Corresponding Service   |
| ------------------------- | ----------------------- |
| `openai-completions`      | OpenAI Chat Completions |
| `openai-responses`        | OpenAI Responses API    |
| `anthropic-messages`      | Anthropic Messages API  |
| `google-generative-ai`    | Google Gemini           |
| `github-copilot`          | GitHub Copilot          |
| `bedrock-converse-stream` | AWS Bedrock             |

`ModelsConfig` also supports a `mode` field—`"merge"` merges custom models with built-in models, while `"replace"` completely replaces the built-in model list.

***

## 31.2.6 Tool/Skill/Hook Configuration (`types.tools.ts` / `types.skills.ts` / `types.hooks.ts`)

### Tool Configuration

Tool configuration controls which tools Agents can use and their behavior. The most important sub-configurations:

* **exec**: bash tool execution limits (timeout, working directory, forbidden commands)
* **media**: media processing configuration (audio transcription model, image understanding, video understanding)
* **browser**: browser control configuration (whether enabled, evaluate permissions)
* **agentToAgent**: cross-Agent communication configuration

### Skill Configuration

```typescript
export type SkillsConfig = {
  allowBundled?: string[];               // Built-in skill whitelist
  load?: {
    extraDirs?: string[];                // Extra skill directories
    watch?: boolean;                     // Auto-refresh on file changes
    watchDebounceMs?: number;            // Refresh debounce
  };
  install?: {
    preferBrew?: boolean;                // Prefer Homebrew installation
    nodeManager?: "npm" | "pnpm" | "yarn" | "bun";
  };
  entries?: Record<string, SkillConfig>; // Configuration for each skill
};
```

### Hook Configuration

Hook configuration is split into two layers: the outer layer controls HTTP hook endpoints, the inner layer controls internal event hooks.

```typescript
export type HooksConfig = {
  // HTTP hook endpoint
  enabled?: boolean;
  path?: string;                         // Endpoint path (default /hooks)
  token?: string;                        // Authentication Token
  presets?: string[];                    // Preset mappings (e.g., ["gmail"])
  mappings?: HookMappingConfig[];        // Custom mapping rules
  gmail?: HooksGmailConfig;             // Gmail integration-specific configuration

  // Internal event hooks
  internal?: {
    enabled?: boolean;
    handlers?: InternalHookHandlerConfig[];  // Legacy handlers
    entries?: Record<string, HookConfig>;    // Configuration for each hook
    load?: { extraDirs?: string[] };         // Extra hook directories
    installs?: Record<string, HookInstallRecord>;  // Installation records
  };
};
```

Each hook entry `HookConfig` supports `enabled` (enable/disable) and `env` (environment variable injection), and can have arbitrary additional fields for hook handlers to read (e.g., the `messages` field of `session-memory`).

***

## Summary of This Section

1. **Type system** adopts a modular splitting strategy, with 30+ sub-type files unified through a barrel file, balancing type completeness and edit locality.
2. **Agent configuration** uses a two-layer structure of defaults + instance overrides, supporting flexible model selection (primary + fallback list), sandbox isolation, skill whitelisting, and other fine-grained controls.
3. **Channel configuration** provides independent type definitions for each messaging channel while sharing common patterns like DM policy, group policy, and send policy.
4. **Model configuration** supports custom providers and 6 API protocols, allowing integration with any compatible LLM service, including privately deployed ones.
5. **Tool/Skill/Hook configuration** are independent yet interrelated—together they define the Agent's capability boundaries and behavior rules.
