Skip to content

基础配置

本指南介绍 OpenClaw 的核心配置选项。

配置文件位置

OpenClaw 的配置文件位于:

  • macOS/Linux: ~/.openclaw/config.json
  • Windows: %USERPROFILE%\.openclaw\config.json

配置命令

查看配置

bash
openclaw config list

设置配置

bash
openclaw config set <key> <value>

示例:

bash
openclaw config set model.provider anthropic
openclaw config set server.port 3000

获取配置

bash
openclaw config get <key>

重置配置

bash
openclaw config reset

核心配置项

模型配置

json
{
  "model": {
    "provider": "anthropic",
    "modelId": "claude-3-5-sonnet-20241022",
    "apiKey": "your-api-key",
    "baseUrl": "https://api.anthropic.com",
    "temperature": 0.7,
    "maxTokens": 4096
  }
}

支持的模型提供商

提供商provider 值支持的模型
AnthropicanthropicClaude 3.5 Sonnet, Claude 3 Opus
OpenAIopenaiGPT-4, GPT-4 Turbo, GPT-3.5
GooglegoogleGemini Pro, Gemini Ultra
KimikimiKimi-K2.5
MiniMaxminimaxMiniMax-M2.5
OllamaollamaLlama 3, Mistral, Qwen

服务器配置

json
{
  "server": {
    "port": 3000,
    "host": "localhost",
    "https": {
      "enabled": true,
      "cert": "/path/to/cert.pem",
      "key": "/path/to/key.pem"
    }
  }
}

安全配置

json
{
  "security": {
    "mode": "sandbox",
    "allowedPaths": [
      "~/Documents",
      "~/Projects"
    ],
    "allowedCommands": [
      "ls",
      "cat",
      "grep",
      "git"
    ],
    "blockedCommands": [
      "rm -rf /",
      "sudo"
    ],
    "maxFileSize": 10485760,
    "sessionTimeout": 3600
  }
}

安全模式

  • sandbox: 沙盒模式,限制文件系统和命令执行
  • full: 完全访问模式,允许完全访问系统资源

记忆配置

json
{
  "memory": {
    "enabled": true,
    "storage": "local",
    "maxEntries": 1000,
    "retention": 2592000,
    "embedding": {
      "provider": "openai",
      "model": "text-embedding-3-small"
    }
  }
}

IM 平台配置

json
{
  "im": {
    "platforms": {
      "telegram": {
        "enabled": true,
        "token": "your-bot-token",
        "webhook": {
          "enabled": true,
          "url": "https://your-domain.com/webhook/telegram"
        }
      },
      "discord": {
        "enabled": true,
        "token": "your-bot-token",
        "clientId": "your-client-id"
      },
      "wechat_work": {
        "enabled": true,
        "corpId": "your-corp-id",
        "agentId": "your-agent-id",
        "secret": "your-secret"
      }
    }
  }
}

技能配置

json
{
  "skills": {
    "directory": "~/.openclaw/skills",
    "autoUpdate": true,
    "trustedAuthors": [
      "openclaw",
      "community-trusted"
    ],
    "permissions": {
      "network": true,
      "filesystem": true,
      "commands": true
    }
  }
}

日志配置

json
{
  "logging": {
    "level": "info",
    "format": "json",
    "file": {
      "enabled": true,
      "path": "~/.openclaw/logs",
      "maxSize": 10485760,
      "maxFiles": 5
    },
    "console": {
      "enabled": true,
      "colorize": true
    }
  }
}

环境变量

OpenClaw 支持通过环境变量配置:

bash
# 模型配置
export OPENCLAW_MODEL_PROVIDER=anthropic
export OPENCLAW_MODEL_API_KEY=your-api-key

# 服务器配置
export OPENCLAW_SERVER_PORT=3000

# 安全配置
export OPENCLAW_SECURITY_MODE=sandbox

配置优先级

配置的优先级从高到低:

  1. 命令行参数
  2. 环境变量
  3. 配置文件
  4. 默认值

配置验证

使用 doctor 命令验证配置:

bash
openclaw doctor

该命令会检查:

  • 配置文件格式
  • 必需配置项
  • API 连接
  • 权限设置

下一步

基于 MIT 许可发布