常见 OpenClaw 配置场景的完整可复制示例。

快速入门

绝对最小配置

{
  agents: { defaults: { workspace: "~/.openclaw/workspace" } },
  channels: { whatsapp: { allowFrom: ["+15555550123"] } },
}

保存到 ~/.openclaw/openclaw.json,即可从该号码 DM 机器人。

推荐入门配置

{
  agents: {
    defaults: {
      workspace: "~/.openclaw/workspace",
      model: { primary: "anthropic/claude-sonnet-4-6" },
    },
    list: [
      {
        id: "main",
        identity: { name: "Clawd", theme: "helpful assistant", emoji: "🦞" },
      },
    ],
  },
  channels: {
    whatsapp: {
      allowFrom: ["+15555550123"],
      groups: { "*": { requireMention: true } },
    },
  },
  messages: {
    visibleReplies: "automatic",
    groupChat: { visibleReplies: "message_tool" },
  },
}

常用模式

多平台接入

{
  agents: { defaults: { workspace: "~/.openclaw/workspace" } },
  channels: {
    whatsapp: { allowFrom: ["+15555550123"] },
    telegram: {
      enabled: true,
      botToken: "YOUR_TOKEN",
      allowFrom: ["123456789"],
    },
    discord: {
      enabled: true,
      token: "YOUR_TOKEN",
      dm: { allowFrom: ["123456789012345678"] },
    },
  },
}

多用户安全 DM 模式

多人可以 DM 机器人时,启用安全 DM 模式防止不同发送者共享上下文:

{
  session: { dmScope: "per-channel-peer" },
  channels: {
    whatsapp: {
      dmPolicy: "allowlist",
      allowFrom: ["+15555550123", "+15555550124"],
    },
    discord: {
      enabled: true,
      token: "YOUR_DISCORD_BOT_TOKEN",
      dm: { enabled: true, allowFrom: ["123456789012345678", "987654321098765432"] },
    },
  },
}

共享 Skill 基线 + 单个覆盖

{
  agents: {
    defaults: {
      workspace: "~/.openclaw/workspace",
      skills: ["github", "weather"],
    },
    list: [
      { id: "main", default: true },
      { id: "docs", workspace: "~/.openclaw/workspace-docs", skills: ["docs-search"] },
    ],
  },
}

Anthropic API Key + MiniMax 回退

{
  auth: {
    profiles: { "anthropic:api": { provider: "anthropic", mode: "api_key" } },
    order: { anthropic: ["anthropic:api"] },
  },
  models: {
    providers: {
      minimax: {
        baseUrl: "https://api.minimax.io/anthropic",
        api: "anthropic-messages",
        apiKey: "${MINIMAX_API_KEY}",
      },
    },
  },
  agents: {
    defaults: {
      workspace: "~/.openclaw/workspace",
      model: {
        primary: "anthropic/claude-opus-4-6",
        fallbacks: ["minimax/MiniMax-M2.7"],
      },
    },
  },
}

本地模型(LM Studio)

{
  agents: {
    defaults: {
      workspace: "~/.openclaw/workspace",
      model: { primary: "lmstudio/my-local-model" },
    },
  },
  models: {
    mode: "merge",
    providers: {
      lmstudio: {
        baseUrl: "http://127.0.0.1:1234/v1",
        apiKey: "lmstudio",
        api: "openai-responses",
        models: [
          {
            id: "my-local-model",
            name: "Local Model",
            reasoning: false,
            input: ["text"],
            cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
            contextWindow: 196608,
            maxTokens: 8192,
          },
        ],
      },
    },
  },
}

工作机器人(受限访问)

{
  agents: {
    defaults: {
      workspace: "~/work-openclaw",
      elevatedDefault: "off",
    },
    list: [
      {
        id: "main",
        identity: { name: "WorkBot", theme: "professional assistant" },
      },
    ],
  },
  channels: {
    slack: {
      enabled: true,
      botToken: "xoxb-...",
      channels: {
        "#engineering": { allow: true, requireMention: true },
        "#general": { allow: true, requireMention: true },
      },
    },
  },
}

受信任节点网络自动审批

{
  gateway: {
    nodes: {
      pairing: {
        autoApproveCidrs: ["192.168.1.0/24", "fd00:1234:5678::/64"],
      },
    },
  },
}

仅适用于首次 role: node 配对且无请求 scope 的场景,operator/browser 客户端仍需手动审批。

完整扩展示例(主要选项)

{
  // 环境变量
  env: {
    OPENROUTER_API_KEY: "sk-or-...",
    shellEnv: { enabled: true, timeoutMs: 15000 },
  },
 
  // 日志
  logging: {
    level: "info",
    file: "/tmp/openclaw/openclaw.log",
    consoleStyle: "pretty",
    redactSensitive: "tools",
  },
 
  // 消息格式
  messages: {
    visibleReplies: "automatic",
    responsePrefix: ">",
    ackReaction: "👀",
    groupChat: { historyLimit: 50, visibleReplies: "message_tool" },
    queue: { mode: "steer", debounceMs: 500, cap: 20 },
  },
 
  // Session
  session: {
    dmScope: "per-channel-peer",
    reset: { mode: "daily", atHour: 4, idleMinutes: 60 },
    maintenance: { mode: "warn", pruneAfter: "30d", maxEntries: 500 },
  },
 
  // Agent
  agents: {
    defaults: {
      workspace: "~/.openclaw/workspace",
      model: {
        primary: "anthropic/claude-sonnet-4-6",
        fallbacks: ["anthropic/claude-opus-4-6", "openai/gpt-5.4"],
      },
      skills: ["github", "weather"],
      thinkingDefault: "low",
      heartbeat: { every: "30m", target: "last" },
      sandbox: {
        mode: "non-main",
        scope: "session",
        docker: { image: "openclaw-sandbox:bookworm-slim", network: "none" },
      },
    },
    list: [
      {
        id: "main",
        default: true,
        identity: { name: "Samantha", theme: "helpful sloth", emoji: "🦥" },
        groupChat: { mentionPatterns: ["@openclaw", "openclaw"] },
      },
    ],
  },
 
  // 工具
  tools: {
    allow: ["exec", "process", "read", "write", "edit", "apply_patch"],
    deny: ["browser", "canvas"],
    elevated: {
      enabled: true,
      allowFrom: { whatsapp: ["+15555550123"] },
    },
  },
 
  // Gateway
  gateway: {
    mode: "local",
    port: 18789,
    bind: "loopback",
    auth: { mode: "token", token: "gateway-token" },
    reload: { mode: "hybrid", debounceMs: 300 },
  },
 
  // Cron
  cron: { enabled: true, maxConcurrentRuns: 2, sessionRetention: "24h" },
}

提示

  • dmPolicy: "open" 时,allowFrom 必须包含 "*"
  • 各平台 ID 格式不同(电话号码、用户 ID、频道 ID),参考各 channel 文档确认格式
  • 可选后续添加的模块:web、browser、ui、discovery、plugins、talk

相关链接