对比 OpenClaw、Claude Code、Cursor、GitHub Copilot、Continue.dev 等主流 AI Agent 平台的配置方式与最佳实践
AI Agent 的配置文件是持久化上下文的载体。与临时提示词(prompt)不同,配置文件:
正如 Cursor 文档 所述:
"Prompts are ephemeral. They exist in a single chat session, carry no institutional memory, and cannot be reviewed in a pull request. A
.cursorrulesfile, by contrast, lives in the repository, applies automatically to every Cursor session scoped to that project, and can be versioned, diffed, and debated like any other piece of infrastructure."
| 平台 | 配置文件 | 位置 | 格式 | 作用域 | 版本控制 |
|---|---|---|---|---|---|
| OpenClaw | SOUL.md, AGENTS.md, TOOLS.md, MEMORY.md, USER.md, IDENTITY.md |
~/.openclaw/workspace/ |
Markdown | 全局/用户 | 推荐 Git |
| Claude Code | CLAUDE.md, .claude/settings.json |
项目根目录 / ~/.claude/ |
Markdown / JSON | 项目/用户 | 项目级可版本控制 |
| Cursor | .cursorrules (legacy) / .cursor/rules/*.mdc |
项目根目录 / .cursor/rules/ |
Markdown + frontmatter | 项目 | 是 |
| GitHub Copilot | copilot-instructions.md |
项目根目录 / .github/ |
Markdown | 项目/仓库 | 是 |
| Continue.dev | config.yaml, .continuerc.json |
~/.continue/ / 项目根目录 |
YAML / JSON | 用户/项目 | 用户级不可,项目级可 |
OpenClaw 采用多文件配置体系,每个文件负责不同维度的配置。配置文件位于 ~/.openclaw/workspace/ 目录下,由 Gateway 在会话启动时自动加载。
官方文档 推荐首次运行时复制模板文件:
cp docs/reference/templates/AGENTS.md ~/.openclaw/workspace/AGENTS.md
cp docs/reference/templates/SOUL.md ~/.openclaw/workspace/SOUL.md
cp docs/reference/templates/TOOLS.md ~/.openclaw/workspace/TOOLS.md
| 文件 | 用途 | 关键内容 |
|---|---|---|
SOUL.md |
定义 Agent 人格与行为风格 | 语气、价值观、边界、沟通风格 |
AGENTS.md |
工作空间规则与工具使用规范 | 安全边界、工具使用规则、记忆系统 |
TOOLS.md |
环境特定的工具与设备信息 | SSH 别名、摄像头名称、TTS 偏好 |
MEMORY.md |
长期记忆(跨会话保持) | 重要决策、偏好、待办、经验教训 |
USER.md |
关于用户的信息 | 用户姓名、偏好、工作背景 |
IDENTITY.md |
Agent 自我认知 | Agent 名称、角色定位、emoji |
来源: OpenClaw 官方文档 及 社区实践
文件位置: ~/.openclaw/workspace/SOUL.md
核心原则:
示例结构:
# SOUL.md - Who You Are
## Core Truths
**Be genuinely useful, not performatively helpful.**
Skip the "Great question!" — just solve it.
**Have opinions. Disagree when warranted.**
You are allowed to say "that's a bad idea" or "this is overcomplicated."
**Autonomous problem-solving is the default.**
Before asking the user for clarification, exhaust reasonable self-resolution.
## Boundaries
- **Privacy is absolute.** Do not log, summarize, or transmit sensitive data.
- **No half-baked external actions.** Drafts only until explicitly approved.
- **No autonomous spending or irreversible ops.** No API calls that cost money, no `rm -rf`.
常见陷阱:
来源: OpenClaw 官方文档
文件位置: ~/.openclaw/workspace/AGENTS.md
核心内容:
memory/YYYY-MM-DD.md)关键配置项:
## Session Startup
Use runtime-provided startup context first.
## Memory
- **Daily notes:** `memory/YYYY-MM-DD.md` — raw logs of what happened
- **Long-term:** `MEMORY.md` — curated memories
## Red Lines
- Don't exfiltrate private data. Ever.
- Don't run destructive commands without asking.
- `trash` > `rm` (recoverable beats gone forever)
最佳实践:
~/.openclaw/workspace 初始化为 Git 仓库,确保配置备份| 文件 | 用途 | 最佳实践 |
|---|---|---|
TOOLS.md |
记录环境特定信息 | 保持更新,如新增 SSH 主机、摄像头变更 |
MEMORY.md |
长期记忆 | 定期整理,从日常笔记中提取精华 |
USER.md |
用户信息 | 随着了解用户而不断丰富 |
IDENTITY.md |
Agent 身份 | 让 Agent 有"自我认知",提升一致性 |
HEARTBEAT.md |
周期性任务 | 定义心跳检查内容,避免过度打扰 |
Claude Code 采用分层配置体系,支持项目级、用户级和全局设置。配置文件包括:
CLAUDE.md: 项目级持久化上下文(Markdown).claude/settings.json: 项目级结构化配置(JSON)~/.claude/settings.json: 用户级全局配置~/.claude.json: 用户状态与缓存(OAuth、MCP 配置等)官方文档 详细说明了各配置层级的作用。
来源: Claude Code 官方文档 及 社区实践
文件位置: 项目根目录 ./CLAUDE.md
用途: 项目级持久化上下文,每次会话自动加载。
最佳实践:
示例:
# Project Overview
This is a payment processing system built with Kotlin/Spring Boot.
## Tech Stack
- **Backend**: Kotlin, Spring Boot 3.x, PostgreSQL
- **Frontend**: React, TypeScript, Tailwind CSS
- **Infrastructure**: Kubernetes, AWS
## Key Commands
```bash
./gradlew build # Build
./gradlew test # Run tests
./gradlew bootRun # Start dev server
Result type for error handling
**创建方式**:
- 运行 `/memory` 命令,Claude Code 自动分析项目并生成
- 手动创建并编辑
### settings.json
**来源**: [Claude Code 官方文档](https://code.claude.com/docs/en/settings)
**文件位置**:
- 项目级: `.claude/settings.json`
- 用户级: `~/.claude/settings.json`
- 本地覆盖: `.claude/settings.local.json`
**配置层级优先级**(从高到低):
1. 环境变量
2. 命令行参数 (`--settings`)
3. 项目级 `.claude/settings.json`
4. 用户级 `~/.claude/settings.json`
5. 默认值
**关键配置项**:
| 配置项 | 说明 | 示例 |
|--------|------|------|
| `permissions.allow` | 允许的命令模式 | `["Bash(npm run *)"]` |
| `permissions.deny` | 禁止的命令模式 | `["Bash(rm -rf *)"]` |
| `hooks.PostToolUse` | 工具使用后自动执行 | 格式化代码、运行检查 |
| `attribution.commit` | 提交归因信息 | `"Generated with Claude Code"` |
| `language` | 默认响应语言 | `"chinese"` |
| `includeGitInstructions` | 是否包含 Git 工作流指令 | `true` / `false` |
**示例配置**:
```json
{
"$schema": "https://code.claude.com/schemas/settings.json",
"permissions": {
"allow": [
"Bash(npm run lint)",
"Bash(npm run test *)",
"Bash(npx prettier --write *)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Bash(rm -rf *)",
"Bash(git push --force *)"
]
},
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "npx prettier --write \"$CLAUDE_TOOL_INPUT_FILE_PATH\""
}
]
}
]
}
}
常见陷阱:
permissions.deny 使用过于宽泛的模式,导致合法操作被拦截hooks 配置不当,导致每次保存都触发耗时操作$schema,失去 IDE 自动补全Cursor 的配置经历了从单文件 .cursorrules 到多文件 .cursor/rules/ 目录的演进。官方文档 说明:
"The legacy
.cursorrulesfile is still supported but will be deprecated. Migrating to the modern.cursor/rules/system gives you multiple files, activation controls, glob patterns, and better organization."
.cursor/rules/来源: Cursor 官方文档 及 社区指南
文件位置: 项目根目录 .cursor/rules/*.mdc
文件格式: Markdown + YAML frontmatter(.mdc 扩展名)
frontmatter 字段:
| 字段 | 说明 | 示例 |
|---|---|---|
description |
规则描述,帮助 AI 判断何时应用 | "React component patterns" |
globs |
文件匹配模式,控制规则作用范围 | "*.tsx,*.jsx" |
alwaysApply |
是否总是应用 | true / false |
示例规则文件:
---
description: TypeScript coding standards
globs: "*.ts,*.tsx"
alwaysApply: true
---
# TypeScript Standards
- Use strict mode always
- Prefer `interface` over `type` for object shapes
- Use explicit return types on public functions
- Avoid `any`; use `unknown` with type guards
目录结构示例:
.cursor/rules/
├── typescript-standards.mdc # globs: "*.ts,*.tsx"
├── react-patterns.mdc # globs: "src/**/*.tsx"
├── testing-conventions.mdc # globs: "*.test.ts,*.spec.ts"
├── api-guidelines.mdc # globs: "src/api/**/*.ts"
└── documentation.mdc # globs: "*.md"
创建方式:
/create-rule,描述规则内容,AI 自动生成Cursor Settings > Rules, Commands 中点击 + Add Rule.mdc 文件.cursorrules来源: Cursor 官方文档 及 社区资源
文件位置: 项目根目录 .cursorrules
状态: 仍支持,但将被弃用
格式: 纯 Markdown,无 frontmatter
示例:
# Cursor Rules
## General
- Use TypeScript strict mode
- Prefer functional components
- Write tests with Vitest
- Use Tailwind CSS for styling
## React
- Use React hooks, not class components
- Keep components under 200 lines
- Use React.memo for expensive renders
## API
- Follow REST conventions
- Use Zod for request/response validation
- Document all endpoints with OpenAPI
迁移建议:
.cursorrules 拆分为多个 .cursor/rules/*.mdc 文件globs 作用域控制description 帮助 AI 理解何时应用规则来源: Cursor 官方文档 及 社区指南
.mdc 文件只覆盖一个主题.cursor/rules/ 应提交到 GitGitHub Copilot 通过 copilot-instructions.md 文件提供项目级自定义指令。此外,VS Code 设置和 GitHub 个人设置也提供配置选项。
官方文档 详细说明了配置方式。
来源: GitHub 官方文档 及 GitHub Blog
文件位置:
./copilot-instructions.md.github/copilot-instructions.md用途: 每次 Copilot 聊天或 Agent 请求时自动读取,作为系统提示的一部分。
GitHub Blog 推荐的 5 个必含内容:
示例:
# Copilot Instructions
## Project Overview
This is a cross-border payment platform serving e-commerce merchants.
We prioritize security, compliance, and transaction reliability.
## Tech Stack
- **Backend**: Java 17, Spring Boot 3.2, PostgreSQL 15
- **Frontend**: Vue 3, TypeScript, Element Plus
- **Infrastructure**: Kubernetes, AWS, Terraform
## Coding Standards
- Follow Google Java Style Guide
- Use Spring's validation annotations for input validation
- All service methods must have `@Transactional` where appropriate
- Use constructor injection, not field injection
- Write unit tests with JUnit 5 and Mockito
## Project Structure
src/
main/
java/
com/company/payment/
domain/ # Entity and value objects
application/ # Service layer
infrastructure/# Repository implementations
api/ # REST controllers
resources/
db/migration/ # Flyway migrations
## Resources
- [API Design Guide](https://internal.company/api-guide)
- [Security Checklist](https://internal.company/security)
VS Code 设置:
在 .vscode/settings.json 中:
{
"github.copilot.chat.customInstructions": [
{
"file": ".github/copilot-instructions.md"
}
]
}
来源: GitHub 官方文档
在 GitHub 个人设置中,可以设置跨仓库的个人自定义指令:
copilot-instructions.md 合并使用来源: GitHub Blog
Continue.dev 采用 YAML 配置体系,支持用户级和项目级配置。配置文件定义模型、上下文提供者、规则、提示词等。
官方文档 详细说明了配置方式。
来源: Continue.dev 官方文档 及 config.yaml 参考
文件位置:
~/.continue/config.yaml (MacOS/Linux) 或 %USERPROFILE%\.continue\config.yaml (Windows).continuerc.json 在项目根目录顶级结构:
name: My Project
version: 1.0.0
schema: v1
models:
- name: GPT-4
provider: openai
model: gpt-4
apiKey: ${OPENAI_API_KEY}
context:
- provider: file
- provider: codebase
rules:
- "Use TypeScript strict mode"
- "Prefer functional components"
prompts:
- name: explain
description: Explain selected code
prompt: "Explain this code in simple terms: {{input}}"
关键配置项:
| 配置项 | 说明 | 示例 |
|---|---|---|
models |
定义可用的 LLM | OpenAI, Anthropic, Ollama 等 |
context |
上下文提供者 | 文件、代码库、文档等 |
rules |
全局规则 | 编码规范、约束条件 |
prompts |
自定义提示词模板 | 可参数化的常用操作 |
tools |
MCP 工具配置 | 外部工具集成 |
模型配置示例:
models:
- name: Claude 3.5 Sonnet
provider: anthropic
model: claude-3-5-sonnet-20241022
apiKey: ${ANTHROPIC_API_KEY}
roles:
- chat
- edit
- name: Local Ollama
provider: ollama
model: codellama:7b
apiBase: http://localhost:11434
roles:
- chat
文件位置: 项目根目录 .continuerc.json
用途: 覆盖用户级配置,提供项目特定的规则、模型、提示词。
示例:
{
"rules": [
"This is a Python project using FastAPI",
"Use Pydantic for data validation",
"Follow PEP 8 style guide",
"Use pytest for testing"
],
"prompts": [
{
"name": "fastapi-route",
"description": "Generate FastAPI route",
"prompt": "Create a FastAPI route for: {{input}}. Include Pydantic models, dependency injection, and error handling."
}
]
}
文件位置: ~/.continue/config.ts
用途: 需要程序化扩展配置时使用 TypeScript。
适用场景:
${ENV_VAR} 引用config.yaml,项目特定放 .continuerc.jsonroles(chat/edit/apply),避免混用prompts,提升效率.continuerc.json 应提交到 Git所有平台都支持某种形式的分层配置。建议采用:
用户级(全局)→ 项目级(特定)
项目级配置文件应提交到版本控制:
# Cursor
git add .cursor/rules/
# Claude Code
git add CLAUDE.md .claude/settings.json
# Copilot
git add copilot-instructions.md
# Continue.dev
git add .continuerc.json
避免在单个配置文件中堆砌所有规则。建议:
| 平台 | 建议规则数 | 单文件长度 |
|---|---|---|
| Cursor | 5-10 个 .mdc 文件 |
每个 < 100 行 |
| Claude Code | 1 个 CLAUDE.md + 设置 |
< 500 行 |
| Copilot | 1 个 copilot-instructions.md |
< 1000 字 |
| Continue.dev | 5-10 条 rules |
简洁明了 |
配置不是一次性工作。建议:
permissions.allow/deny).gitignore 忽略配置文件(项目级配置应共享)| 平台 | 文档链接 |
|---|---|
| OpenClaw | 官方文档 |
| Claude Code | Settings 文档 |
| Cursor | Rules 文档 |
| GitHub Copilot | Custom Instructions |
| Continue.dev | Configuration |
| 资源 | 链接 | 说明 |
|---|---|---|
| Awesome Cursor Rules | GitHub | 社区收集的 .cursorrules 模板 |
| Claude Code Setup Template | GitHub | CLAUDE.md 和配置模板 |
| Cursor Rules Generator | design.dev | .cursorrules 生成工具 |
| OpenClaw Workspace Guide | Blog | 工作空间文件详解 |
项目根目录/
├── .cursor/ # Cursor (现代)
│ └── rules/
│ ├── typescript.mdc
│ └── react.mdc
├── .cursorrules # Cursor (旧版,可选)
├── CLAUDE.md # Claude Code 项目上下文
├── .claude/
│ └── settings.json # Claude Code 项目设置
├── copilot-instructions.md # GitHub Copilot
├── .github/
│ └── copilot-instructions.md # Copilot (仓库级)
├── .continuerc.json # Continue.dev 项目级
└── .vscode/
└── settings.json # VS Code 设置 (Copilot 配置)
核心洞察: 配置文件的质量直接决定 AI Agent 的输出质量。投入时间编写清晰、具体、可维护的配置,比反复在聊天中纠正 AI 更高效。
本文最后更新:2026-05-31
所有信息均来自官方文档或社区实践,引用链接已标注。如有更新,请以各平台官方文档为准。