Skip to content

配置管理

Claude Code SOLO 系统提供灵活的配置管理机制,支持全局配置、项目配置和环境特定配置。

配置层级

1. 全局配置

bash
~/.claude/
├── config.json          # Claude Code 全局配置
├── CLAUDE.md            # 全局用户指令
└── settings/
    ├── commands/        # 全局自定义命令
    └── agents/          # 全局代理配置

2. 项目配置

bash
project-root/
├── claude-settings/     # 项目级 Claude Code 配置
   ├── commands/       # 项目自定义命令
   └── agents/         # 项目代理配置
├── CLAUDE.md           # 项目指令文档
└── .solo/              # SOLO 工作区
    ├── config/         # SOLO 项目配置
    └── .solo-metadata.json  # 项目状态元数据

配置文件详解

Claude Code 全局配置 (~/.claude/config.json)

json
{
  "apiKey": "your-api-key",
  "model": "claude-3.5-sonnet",
  "maxTokens": 4096,
  "temperature": 0.1,
  "timeout": 30000,
  "solo": {
    "enabled": true,
    "defaultWorkspace": ".solo",
    "autoSaveInterval": 300,
    "backupEnabled": true,
    "backupRetention": 30
  },
  "ui": {
    "theme": "auto",
    "language": "zh-CN",
    "showLineNumbers": true,
    "tabSize": 2
  }
}

SOLO 项目配置 (.solo/config/solo-settings.json)

json
{
  "project": {
    "name": "example-project",
    "type": "web-api",
    "techStack": ["java", "spring-boot", "postgresql"],
    "version": "1.0.0"
  },
  "workflow": {
    "currentPhase": "engineer",
    "enabledPhases": ["product", "architect", "engineer", "qa"],
    "autoTransition": false,
    "requireApproval": true
  },
  "agents": {
    "product-manager": {
      "enabled": true,
      "customPrompts": {},
      "tools": ["Read", "Write", "Edit", "Grep", "Glob", "TodoWrite"]
    },
    "architect": {
      "enabled": true,
      "customPrompts": {},
      "tools": ["Read", "Write", "Edit", "Grep", "Glob", "TodoWrite"]
    },
    "engineer": {
      "enabled": true,
      "tddMode": "strict",
      "testFramework": "junit5",
      "tools": ["Read", "Write", "Edit", "MultiEdit", "Bash", "Grep", "Glob", "TodoWrite"]
    },
    "qa-engineer": {
      "enabled": true,
      "coverageThreshold": 80,
      "tools": ["Read", "Write", "Edit", "Bash", "Grep", "Glob", "TodoWrite"]
    }
  },
  "integrations": {
    "git": {
      "enabled": true,
      "autoCommit": false,
      "commitMessageTemplate": "feat: {summary}\n\n🤖 Generated with [Claude Code](https://claude.ai/code)\n\nCo-Authored-By: Claude <noreply@anthropic.com>"
    },
    "ci": {
      "provider": "github-actions",
      "runTestsOnCommit": true,
      "deployOnMerge": false
    }
  }
}

配置管理命令

查看配置

bash
# 查看全局配置
claude config show

# 查看项目配置
claude config show --project

# 查看 SOLO 配置
/solo__status config

修改配置

bash
# 设置全局配置
claude config set apiKey "your-new-api-key"
claude config set solo.enabled true

# 设置项目配置
claude config set --project workflow.autoTransition true
claude config set --project agents.engineer.tddMode "strict"

重置配置

bash
# 重置全局配置
claude config reset

# 重置项目配置
claude config reset --project

# 重置 SOLO 工作区
/solo__switch product --reset

环境变量

Claude Code 环境变量

bash
# API 配置
export CLAUDE_API_KEY="your-api-key"
export CLAUDE_MODEL="claude-3.5-sonnet"
export CLAUDE_MAX_TOKENS=4096

# SOLO 配置
export SOLO_WORKSPACE_DIR=".solo"
export SOLO_AUTO_SAVE=true
export SOLO_BACKUP_ENABLED=true

# 代理配置  
export CLAUDE_AGENT_TIMEOUT=30000
export CLAUDE_CONCURRENT_AGENTS=3

项目环境变量 (.env)

bash
# 数据库配置
DATABASE_URL=postgresql://localhost:5432/mydb
DATABASE_POOL_SIZE=10

# API 配置
API_PORT=8080
API_BASE_URL=/api/v1

# 测试配置
TEST_DATABASE_URL=postgresql://localhost:5432/test_db
COVERAGE_THRESHOLD=80

配置模板

项目类型模板

Web API 项目

json
{
  "project": {
    "type": "web-api",
    "techStack": ["java", "spring-boot", "postgresql"],
    "structure": "layered"
  },
  "workflow": {
    "enabledPhases": ["product", "architect", "engineer", "qa"],
    "autoTransition": false
  },
  "agents": {
    "engineer": {
      "tddMode": "strict",
      "testFramework": "junit5"
    }
  }
}

微服务项目

json
{
  "project": {
    "type": "microservice",
    "techStack": ["spring-boot", "docker", "kubernetes"],
    "structure": "hexagonal"
  },
  "workflow": {
    "enabledPhases": ["product", "architect", "engineer", "qa"],
    "requireApproval": true
  }
}

前端项目

json
{
  "project": {
    "type": "frontend",
    "techStack": ["typescript", "react", "vite"],
    "structure": "component-based"
  },
  "agents": {
    "engineer": {
      "testFramework": "jest",
      "e2eFramework": "playwright"
    }
  }
}

配置最佳实践

1. 分层配置管理

  • 全局配置:API 密钥、默认模型、UI 偏好
  • 项目配置:技术栈、工作流、代理设置
  • 环境配置:数据库连接、API 端点、密钥

2. 版本控制策略

bash
# 应该提交到 Git
claude-settings/     # 项目配置
CLAUDE.md           # 项目指令
.solo/config/       # SOLO 配置

# 不应该提交到 Git
.solo/.solo-metadata.json    # 状态文件
.solo/contexts/              # 工作上下文
.env                         # 环境变量

3. 团队协作配置

json
{
  "team": {
    "sharedCommands": true,
    "sharedAgents": true,
    "requireCodeReview": true,
    "conventionalCommits": true
  },
  "workflow": {
    "branchStrategy": "git-flow",
    "prTemplate": "default",
    "requireApproval": true
  }
}

4. 安全配置

  • 使用环境变量存储敏感信息
  • 启用配置文件加密
  • 定期轮换 API 密钥
  • 限制代理工具权限

配置迁移

从旧版本迁移

bash
# 备份现有配置
cp -r ~/.claude ~/.claude.backup

# 迁移配置
claude config migrate --from-version=1.0 --to-version=2.0

# 验证迁移结果
claude config validate

项目配置迁移

bash
# 从 .claude/ 迁移到 claude-settings/
claude config migrate-project --from=.claude --to=claude-settings

# 更新 CLAUDE.md 中的路径引用
claude config update-paths

故障排除

常见配置问题

1. API 密钥问题

bash
# 验证 API 密钥
claude auth verify

# 重新设置 API 密钥
claude config set apiKey "new-api-key"

2. 权限问题

bash
# 检查文件权限
ls -la ~/.claude/config.json

# 修复权限
chmod 600 ~/.claude/config.json

3. 配置冲突

bash
# 检查配置冲突
claude config check

# 解决冲突
claude config resolve-conflicts

4. SOLO 状态问题

bash
# 检查 SOLO 状态
/solo__status diagnose

# 重置 SOLO 状态
/solo__switch product --reset

调试配置

启用调试模式

json
{
  "debug": {
    "enabled": true,
    "logLevel": "debug",
    "logFile": "~/.claude/debug.log"
  }
}

配置验证

bash
# 验证配置文件格式
claude config validate

# 测试配置
claude config test

# 生成配置报告
claude config report

相关资源

SOLO Development Guide