Loading...
Loading...
AI Agent配置策略及安全指南。包含项目说明文件编写方法、Hooks/Skills/Plugins配置、安全策略、团队共享工作流定义。
npx skill4agent add supercent-io/skills-template agent-configuration/init # Claude分析代码库后生成初稿# Project: [项目名称]
## Tech Stack
- **Frontend**: React + TypeScript
- **Backend**: Node.js + Express
- **Database**: PostgreSQL
- **ORM**: Drizzle
## Coding Standards
- Use TypeScript strict mode
- Prefer server components over client components
- Use `async/await` instead of `.then()`
- Always validate user input with Zod
## DO NOT
- Never commit `.env` files
- Never use `any` type in TypeScript
- Never bypass authentication checks
- Never expose API keys in client code
## Common Commands
- `npm run dev`: Start development server
- `npm run build`: Build for production
- `npm run test`: Run testsOur authentication system is built using NextAuth.js, which is a
complete authentication solution for Next.js applications...
(5行以上的说明)## Authentication
- NextAuth.js with Credentials provider
- JWT session strategy
- **DO NOT**: Bypass auth checks, expose session secrets"一开始可以不用项目说明文件就启动。当你开始重复说同样的话时,再添加进去。"
| Hook | 执行时机 | 使用场景 |
|---|---|---|
| 工具执行前 | 拦截危险命令 |
| 工具执行后 | 日志记录、发送通知 |
| 请求权限时 | 自动批准/拒绝 |
| 发送通知时 | 集成外部系统 |
| 子Agent启动时 | 监控 |
| 子Agent停止时 | 收集结果 |
// ~/.claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"pattern": "rm -rf /",
"action": "block",
"message": "拦截根目录删除命令"
},
{
"pattern": "rm -rf /*",
"action": "block",
"message": "拦截危险删除命令"
},
{
"pattern": "sudo rm",
"action": "warn",
"message": "注意使用sudo删除命令"
},
{
"pattern": "curl * | sh",
"action": "block",
"message": "拦截管道执行脚本"
},
{
"pattern": "chmod 777",
"action": "warn",
"message": "注意设置过度权限"
}
]
}
}| 功能 | 加载时机 | 主要用户 | Token效率 |
|---|---|---|---|
| 项目说明文件 | 始终加载 | 项目团队 | 低(始终加载) |
| Skills | 需要时加载 | AI自动调用 | 高(按需加载) |
| Slash Commands | 用户调用时 | 开发者 | 中等 |
| Plugins/MCP | 安装时 | 团队/社区 | 多样 |
需始终应用的规则 → 项目说明文件
仅特定任务需要的知识 → Skills(Token高效)
常用命令 → Slash Commands
外部服务集成 → Plugins / MCP# 创建Skill目录
mkdir -p ~/.claude/skills/my-skill
# 编写SKILL.md
cat > ~/.claude/skills/my-skill/SKILL.md << 'EOF'
---
name: my-skill
description: 我的自定义Skill
platforms: [Claude, Gemini, ChatGPT]
---
# My Skill
## When to use
- 需要执行特定任务时
## Instructions
1. 第一步
2. 第二步
EOF.envcredentials.jsonsudocurl | shchmod 777# 使用cc-safe工具检测危险命令
npx cc-safe .
npx cc-safe ~/projects
# 检测目标:
# - sudo, rm -rf, chmod 777
# - curl | sh, wget | bash
# - git reset --hard, git push --force
# - npm publish, docker run --privileged# 仅自动批准安全命令
/sandbox "npm test"
/sandbox "npm run lint"
/sandbox "git status"
/sandbox "git diff"
# 模式批准
/sandbox "git *" # 所有git命令
/sandbox "npm test *" # 所有npm test相关命令
# MCP工具模式
/sandbox "mcp__server__*"project/
├── .claude/ # Claude Code配置
│ ├── team-settings.json
│ ├── hooks/
│ └── skills/
├── .agent-skills/ # 通用Skill
│ ├── backend/
│ ├── frontend/
│ └── ...
├── CLAUDE.md # 面向Claude的项目说明
├── .cursorrules # Cursor配置
└── ...{
"permissions": {
"allow": [
"Read(src/)",
"Write(src/)",
"Bash(npm test)",
"Bash(npm run lint)"
],
"deny": [
"Bash(rm -rf /)",
"Bash(sudo *)"
]
},
"hooks": {
"PreToolUse": {
"command": "bash",
"args": ["-c", "echo 'Team hook: validating...'"]
}
},
"mcpServers": {
"company-db": {
"command": "npx",
"args": ["@company/db-mcp"]
}
}
}提交.claude/目录 → 团队成员克隆 → 自动应用相同配置 → 维持团队标准| Agent | 配置文件 | 位置 |
|---|---|---|
| Claude Code | CLAUDE.md, settings.json | 项目根目录, ~/.claude/ |
| Gemini CLI | .geminirc | 项目根目录, ~/ |
| Cursor | .cursorrules | 项目根目录 |
| ChatGPT | Custom Instructions | UI设置 |
.agent-skills/
├── backend/
├── frontend/
├── code-quality/
├── infrastructure/
├── documentation/
├── project-management/
├── search-analysis/
└── utilities//initcccgcxexport EDITOR=vimcc-safe~/.claude/settings.json # 全局配置
~/.claude/skills/ # 全局Skill
.claude/settings.json # 项目配置
.claude/skills/ # 项目Skill
.agent-skills/ # 通用Skill
CLAUDE.md # 项目AI说明书1. 使用Hooks拦截危险命令
2. 使用/sandbox仅自动批准安全命令
3. 使用cc-safe定期审计
4. 仅在容器中使用实验模式项目说明文件:始终加载(保持简洁)
Skills:按需加载(Token高效)
.toon模式:节省95% Token