Skip to content

OpenClaw 高级配置

深入配置 OpenClaw,满足复杂需求。


🔧 配置文件结构

主配置文件

~/.openclaw/openclaw.json

配置层次

1. 全局配置 (openclaw.json)
2. 通道配置 (channels/)
3. 代理配置 (agents/)
4. 凭证配置 (credentials/)

📋 核心配置项

1. 模型配置

多模型配置

json
{
  "models": {
    "mode": "merge",
    "providers": {
      "modelstudio": {
        "baseUrl": "https://api.dashscope.aliyuncs.com/v1",
        "api": "openai-completions",
        "models": [
          {
            "id": "qwen3.5-plus",
            "name": "通义千问 Plus",
            "cost": {
              "input": 0.004,
              "output": 0.012
            },
            "contextWindow": 1000000,
            "maxTokens": 65536
          },
          {
            "id": "qwen3-max-2026-01-23",
            "name": "通义千问 Max",
            "cost": {
              "input": 0.02,
              "output": 0.06
            },
            "contextWindow": 262144,
            "maxTokens": 65536
          }
        ]
      }
    }
  }
}

模型故障转移

json
{
  "agents": {
    "defaults": {
      "model": {
        "primary": "modelstudio/qwen3.5-plus",
        "fallbacks": [
          "modelstudio/qwen3-max-2026-01-23",
          "modelstudio/qwen3-coder-next"
        ]
      }
    }
  }
}

2. 通道配置

飞书高级配置

json
{
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxx",
      "appSecret": "xxxxx",
      "connectionMode": "websocket",
      "domain": "feishu",
      "groupPolicy": "allowlist",
      "groupAllowFrom": ["ou_xxx1", "ou_xxx2"],
      "allowFrom": ["ou_xxx1", "ou_xxx2"],
      "dmPolicy": "pairing",
      "tools": {
        "profile": "messaging",
        "fs": {
          "workspaceOnly": true
        }
      },
      "capabilities": {
        "inlineButtons": "allowlist",
        "reactions": true,
        "threads": true
      }
    }
  }
}

多通道配置

json
{
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxx",
      "appSecret": "xxx"
    },
    "telegram": {
      "enabled": true,
      "token": "bot_xxx"
    },
    "discord": {
      "enabled": false,
      "token": "xxx"
    }
  }
}

3. 代理配置

默认代理配置

json
{
  "agents": {
    "defaults": {
      "workspace": "/home/pao/.openclaw/workspace",
      "model": {
        "primary": "modelstudio/qwen3.5-plus"
      },
      "compaction": {
        "mode": "safeguard",
        "threshold": 100
      },
      "maxConcurrent": 4,
      "subagents": {
        "maxConcurrent": 8
      },
      "sandbox": {
        "mode": "all",
        "allowedCommands": ["ls", "cat", "grep"],
        "blockedCommands": ["rm", "sudo"]
      }
    }
  }
}

自定义代理

json
{
  "agents": {
    "custom": {
      "main": {
        "model": "modelstudio/qwen3.5-plus",
        "workspace": "/home/pao/.openclaw/workspace",
        "thinking": "on"
      },
      "coding": {
        "model": "modelstudio/qwen3-coder-plus",
        "workspace": "/home/pao/.openclaw/workspace-coding",
        "tools": {
          "profile": "coding"
        }
      }
    }
  }
}

4. 网关配置

网络配置

json
{
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "loopback",
    "auth": {
      "mode": "token",
      "token": "your-token-here"
    },
    "tailscale": {
      "mode": "off",
      "resetOnExit": false
    },
    "trustedProxies": ["127.0.0.1", "192.168.1.0/24"]
  }
}

远程访问配置

json
{
  "gateway": {
    "port": 18789,
    "mode": "remote",
    "bind": "0.0.0.0",
    "publicUrl": "https://your-domain.com",
    "auth": {
      "mode": "token",
      "token": "secure-token"
    }
  }
}

5. 插件配置

插件加载

json
{
  "plugins": {
    "load": {
      "paths": [
        "/home/pao/.nvm/versions/node/v22.22.1/lib/node_modules/openclaw/extensions/feishu",
        "/home/pao/.openclaw/plugins/custom"
      ]
    },
    "entries": {
      "feishu": {
        "enabled": true
      },
      "custom-plugin": {
        "enabled": true,
        "config": {
          "option1": "value1"
        }
      }
    },
    "allow": ["feishu", "custom-plugin"]
  }
}

🔐 安全配置

凭证加密

bash
# 加密敏感配置
gpg --symmetric --cipher-algo AES256 credentials.json

# 解密使用
gpg --decrypt credentials.json.gpg

权限控制

json
{
  "security": {
    "groupPolicy": "allowlist",
    "elevated": {
      "requireApproval": true,
      "allowList": ["read", "write"]
    },
    "fs": {
      "workspaceOnly": true,
      "allowedPaths": ["/home/pao/.openclaw/workspace"]
    }
  }
}

⚡ 性能配置

缓存配置

json
{
  "cache": {
    "enabled": true,
    "maxSize": 1000,
    "ttl": 600000,
    "strategy": "lru"
  }
}

会话配置

json
{
  "sessions": {
    "maxConcurrent": 50,
    "timeout": 3600000,
    "compaction": {
      "mode": "safeguard",
      "threshold": 100,
      "target": 50
    }
  }
}

日志配置

json
{
  "logging": {
    "level": "info",
    "format": "json",
    "output": "file",
    "path": "/var/log/openclaw",
    "rotation": {
      "maxSize": "100M",
      "maxFiles": 10
    }
  }
}

🎯 场景配置

场景 1:个人使用

json
{
  "gateway": {
    "mode": "local",
    "bind": "loopback"
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "groupPolicy": "allowlist"
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "modelstudio/qwen3.5-plus"
      }
    }
  }
}

场景 2:团队使用

json
{
  "gateway": {
    "mode": "remote",
    "bind": "0.0.0.0"
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "groupPolicy": "allowlist",
      "groupAllowFrom": ["ou_xxx1", "ou_xxx2", "ou_xxx3"]
    }
  },
  "agents": {
    "defaults": {
      "maxConcurrent": 10
    }
  }
}

场景 3:生产环境

json
{
  "gateway": {
    "mode": "remote",
    "bind": "0.0.0.0",
    "trustedProxies": ["10.0.0.0/8"]
  },
  "security": {
    "groupPolicy": "allowlist",
    "elevated": {
      "requireApproval": true
    }
  },
  "logging": {
    "level": "warn",
    "format": "json"
  },
  "cache": {
    "enabled": true,
    "maxSize": 5000
  }
}

🛠️ 配置验证

验证配置

bash
# 验证配置文件
openclaw config validate

# 查看当前配置
openclaw config get

# 导出配置
openclaw config export > config.json

测试配置

bash
# 测试模型配置
openclaw models test qwen3.5-plus

# 测试通道配置
openclaw channels test feishu

# 测试完整配置
openclaw doctor

📋 配置检查清单

基础配置

  • [ ] 模型配置正确
  • [ ] 通道凭证有效
  • [ ] 网关端口可用
  • [ ] 工作区路径存在

安全配置

  • [ ] 使用 allowlist 策略
  • [ ] 凭证已加密
  • [ ] 文件权限正确
  • [ ] elevated 工具受限

性能配置

  • [ ] 缓存已启用
  • [ ] 会话限制合理
  • [ ] 日志轮转配置
  • [ ] 资源限制设置

提示

配置前备份,修改后验证!

🟢🐉 泡泡龙

Released under the MIT License.