1. Project Overview & Quickstart (jnMetaCode/agency-agents-zh)
File: README.md
agency-agents 中文版(AI 智能体专家团队)
🌐 简体中文 | 繁體中文 | English (upstream)
268 个即插即用的 AI 专家角色 — 覆盖工程、设计、营销、产品、游戏、安全、GIS、金融等 20 个部门。不是通用提示词模板,每个智能体都有独立的人设、专业流程和可交付成果。支持 Claude Code / Cursor / Copilot 等 18 种 AI 编程工具。
agency-agents 的中文社区版。在完整翻译上游的基础上,新增了 50 个中国市场原创智能体(小红书、抖音、微信、B站、飞书、钉钉等平台运营,以及跨境电商、政务ToG、医疗合规、Qt 工业上位机、机械设计、畜禽养殖档案核对等垂直领域)。
想更好地用起来,或想给团队打造统一的智能体工作台?下载桌面客户端(原生 App,免装 Node,macOS / Windows / Linux),或在线体验 ao.aiolaola.com/experts。
📊 项目规模
| 🤖 AI 智能体 | 🌏 英文版翻译 | 🇨🇳 中国市场原创 | 🧠 支持工具 | 🏢 部门 |
|---|---|---|---|---|
| 268 | 215 | 53 | 18 种 | 20 个 |
📖 官方配套课程 → AI 专家团队实战(33 节,免费):手把手把这仓 268 位专家用成一支团队——单兵点名、自动组队、一人公司全流程,桌面端零代码教学。另有 从零学会 AI 编程(180 节)+ 从零构建 AI 智能体(40 节)
🙏 赞助商 想出现在这里?联系 [[email protected]](mailto:[email protected])
感谢 APINEBULA 大屏赞助本项目!APINEBULA 是银河录像局旗下的企业级 AI 聚合平台,背靠大平台资源,面向开发者、团队与企业用户提供稳定、高性价比的大模型 API 接入服务。平台聚合 Claude、GPT、Gemini 等主流满血模型,一个接口接入全球顶尖 AI 大模型,各大模型价格低至 1 折起,支持企业级高并发、正式合同、对公打款与开票服务,适合 AI 编程、Agent 开发、业务系统集成等多种场景!
🎁 通过此链接注册并在充值时填写 "agent" 优惠码可享九折优惠!
| 感谢 AICodeMirror 赞助了本项目!AICodeMirror 提供 Claude / Codex / Gemini 官方高稳定中转服务,支持企业级高并发、极速开票、7×24 专属技术支持。Codex 官方渠道低至 0.7 折,充值更有折上折!🎁 AICodeMirror 为 agency-agents-zh 项目的用户提供了特别福利,通过此链接注册的用户,可享受首充 8 折! |
|---|
感谢 Cubence 对本项目的支持。Cubence 是一家致力为客户提供稳定、高效的 API 中转服务商。从 25 年 9 月运营至今,提供了 Claude Code、Codex、Gemini 等多种模型支持。🎁 通过此链接注册的用户,首次购买时填写专属优惠码 AGENCY 即可享受 9 折优惠! |
|---|
| | 感谢 火山引擎 赞助了本项目!火山引擎AI巅峰盛惠来袭!豆包大模型限时5折起,19元即可入手约440万Tokens文本模型,新客首单再享AI统一节省计划。从文本生成、图像创作到视频合成、语音复刻,全模态AI能力一站式配齐。开发者专属编程模型套餐2.5折订阅,支持Kimi-K2.7、GLM-5.2等主流模型。
🎁 注册即领2500万Tokens,立即访问火山引擎活动页面抢购。 |
| --- | --- |
| 感谢优云智算赞助了本项目!优云智算是UCloud旗下AI云平台,主打包月、按次的高性价比国模Agent Plan套餐,支持GLM5.2 低至49元/月起。同时提供官转稳定海外模型。支持接入 Claude Code、Codex 及 API 调用。支持企业高并发、7*24技术支持、自助开票。🎁 通过此链接注册的用户,可得免费5元平台体验金! |
|---|
| 感谢 LanoX AI 赞助了本项目!LanoX AI 为开发者、团队与企业提供稳定、高性价比的全球模型接入服务,覆盖 GPT、Claude、Gemini、Qwen、Grok 等主流模型,以及 Seedance 2.0、GPT Image、Gemini Nano Banana 等多模态创作能力。高可用、原生能力输出、不降智、不混模、调用与计费透明,顶级模型低至官方价 1 折起,文档清晰、接入简单,支持开票与企业批量调用,适用于 AI 产品、Agent、内容平台与研发团队。🎁 通过此链接注册的用户,可获赠 5 美金体验额度与百万免费 Token,另有 500+ 免费模型可用! |
|---|
| 感谢胜算云对本项目的赞助!胜算云是面向 AI 原生团队的模型 API 聚合平台,汇集 Claude、ChatGPT、Gemini 等海内外大语言模型及多媒体模型,支持统一接入与按量调用。平台坚持合规 API 服务,杜绝逆向工程和资源稀释。此外平台提供企业级定制网关,包括团队成本与权限管理、智能路由、安全防护及 BYOK 密钥托管,并提供发票服务。🎁 新用户通过此链接注册,即可领取 5 元 Token 体验额度! |
|---|
🚀 让角色库跑起来 · Agency Orchestrator
一句话,让多个 AI 专家自动组队协作,几分钟交付完整方案。
npm install agency-orchestrator
ao compose "帮我写一篇关于 AI Agent 的深度分析文章" --run不想用命令行? 下载桌面客户端(原生 App,免装 Node,macOS / Windows / Linux),或在线体验 ao.aiolaola.com/experts。
零代码编排 · DAG 并行 · 断点续跑 · 10 种大模型(7 种免 key)· 现成模板开箱即用 —— 了解 Agency Orchestrator →
🖼️ 在线浏览全部专家(无需安装)
搜索 / 按部门筛选 / 查看与复制每位专家的完整提示词 —— 全部 268 位,直接在浏览器里看:
这是什么?
一套开箱即用的 AI 角色库。每个智能体都有明确的身份定义、关键规则、工作流程和交付物,安装到你的 AI 编程工具后用自然语言激活。
和普通提示词的区别:普通提示词告诉 AI "你是一个专家";这里的智能体定义了专家怎么思考、怎么做事、交付什么。例如安全工程师会按 OWASP Top 10 逐项审查代码,小红书运营专家会输出完整的种草笔记策略和达人合作方案。
快速开始
方式一:一键安装到你的 AI 工具
支持 18 种主流 AI 编程工具,一条命令搞定:
# 自动检测已安装的工具,一键安装
./scripts/install.sh
# 或指定安装到特定工具
./scripts/install.sh --tool openclaw # OpenClaw ⭐ 推荐
./scripts/install.sh --tool claude-code # Claude Code
./scripts/install.sh --tool copilot # GitHub Copilot
./scripts/install.sh --tool cursor # Cursor
./scripts/install.sh --tool kiro # Kiro (Amazon)
./scripts/install.sh --tool trae # Trae
./scripts/install.sh --tool opencode # OpenCode
./scripts/install.sh --tool aider # Aider
./scripts/install.sh --tool windsurf # Windsurf
./scripts/install.sh --tool antigravity # Antigravity
./scripts/install.sh --tool gemini-cli # Gemini CLI
./scripts/install.sh --tool qwen # Qwen Code
./scripts/install.sh --tool codex # Codex CLI
./scripts/install.sh --tool deerflow # DeerFlow 2.0 (ByteDance)
./scripts/install.sh --tool workbuddy # WorkBuddy (Tencent)
./scripts/install.sh --tool codewhale # CodeWhale (原 DeepSeek-TUI)
./scripts/install.sh --tool hermes # Hermes Agent (NousResearch)
./scripts/install.sh --tool qoder # QoderClaude Code 和 GitHub Copilot 可直接安装;其他工具需先运行
./scripts/convert.sh转换格式。
🔥 OpenClaw 用户快速上手
OpenClaw 是目前社区用户最多的集成方式,每个智能体会拆分为三个文件:SOUL.md(身份人设)+ AGENTS.md(业务能力)+ IDENTITY.md(简介),天然支持多智能体协作编排。
./scripts/convert.sh --tool openclaw # 第一步:转换为 SOUL.md 格式
./scripts/install.sh --tool openclaw # 第二步:安装到 ~/.openclaw/安装后重启 OpenClaw 网关即可使用。
方式二:手动复制
# Claude Code / GitHub Copilot(直接复制即可)
cp -r marketing/*.md ~/.claude/agents/
# 在 Claude Code 中激活:
# "激活前端开发者模式,帮我构建一个 React 组件"方式三:作为提示词参考
浏览下方智能体列表,复制/改编你需要的内容!
智能体阵容
🛠️ 工程部
构建未来,一个 commit 一个脚印。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 前端开发者 | React/Vue、UI 实现、性能优化 | 现代 Web 应用、像素级 UI |
| 后端架构师 | API 设计、数据库架构、可扩展性 | 服务端系统、微服务 |
| AI 工程师 | 机器学习、模型部署、AI 集成 | ML 功能、数据管线 |
| DevOps 自动化师 | CI/CD、基础设施自动化 | 流水线开发、部署自动化 |
| 安全工程师 | 威胁建模、代码审计、安全架构 | 应用安全、漏洞评估 |
| 快速原型师 | 快速 POC、MVP 开发 | 概念验证、黑客马拉松 |
| 高级开发者 | Laravel/Livewire/FluxUI、高端 CSS、Three.js | 高品质 Web 体验 |
| 移动应用开发者 | iOS/Android 原生、跨平台框架 | 移动端开发、App 性能优化 |
| 数据工程师 | ETL/ELT、数据湖、Spark/dbt | 数据管线、数据仓库 |
| 技术文档工程师 | API 文档、开发者文档、docs-as-code | 技术文档、知识库 |
| 自主优化架构师 | 自适应系统、自动调优 | 智能运维、自愈系统 |
| 嵌入式固件工程师 | RTOS、外设驱动、低功耗设计 | IoT、嵌入式系统 |
| 上位机工程师 ⭐ | Qt/QML、QSerialPort、Modbus/CAN、QChart 实时可视化 | 工业上位机、检测设备、HMI |
| 机械设计工程师 ⭐ | 传动选型、强度刚度疲劳振动校核、DFMA、GB/ISO 标准件 | 工业装备、自动化产线、检测仪器 |
| 嵌入式 Linux 驱动工程师 ⭐ | 内核模块、设备树、Platform/I2C/SPI 驱动 | 嵌入式 Linux BSP 开发 |
| FPGA/ASIC 数字设计工程师 ⭐ | Verilog/SystemVerilog、时序收敛、AXI 总线 | FPGA 开发、数字逻辑设计 |
| IoT 方案架构师 ⭐ | MQTT/CoAP、边缘计算、设备管理、云平台 | 物联网端到端方案设计 |
| 国内网络工程师 ⭐ | 华为 VRP/华三 Comware/锐捷、VLAN/OSPF/BGP/VXLAN、信创国产化、等保组网 | 国产设备园区网/数据中心/广域网 |
| 故障响应指挥官 | 故障处置、SLO 管理、事后复盘 | 线上故障、应急响应 |
| 威胁检测工程师 | SIEM、威胁狩猎、检测规则 | 安全运营、威胁检测 |
| Solidity 智能合约工程师 | Solidity、EVM、Gas 优化、DeFi | 智能合约开发、Web3 |
| 微信小程序开发者 ⭐ | WXML/WXSS、微信支付、云开发 | 微信小程序全栈开发 |
| 代码审查员 | 代码审查、安全审计、质量把关 | PR 审查、代码质量 |
| 数据库优化师 | Schema 设计、查询优化、索引策略 | 数据库性能调优 |
| Git 工作流大师 | 分支策略、约定式提交、变基 | Git 工作流规范 |
| 软件架构师 | 系统设计、DDD、架构决策 | 系统架构设计 |
| SRE (站点可靠性工程师) | SLO、可观测性、混沌工程 | 站点可靠性工程 |
| AI 数据修复工程师 | 自愈管道、SLM 语义聚类、零数据丢失 | 大规模数据异常修复 |
| 飞书集成开发工程师 ⭐ | 飞书机器人、审批流、多维表格 | 飞书生态集成开发 |
| 钉钉集成开发工程师 ⭐ | 钉钉机器人、酷应用、连接器 | 钉钉生态集成开发 |
| CMS 开发者 | Drupal/WordPress、主题开发、自定义插件 | CMS 站点开发与内容架构 |
| 邮件智能工程师 | 邮件解析、结构化提取、AI 推理数据 | 智能体邮件集成 |
| Filament 优化专家 | Filament PHP 后台重构、高影响力改造 | PHP 后台管理优化 |
🎨 设计部
让产品好看、好用、有惊喜。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| UI 设计师 | 视觉设计、组件库、设计系统 | 界面设计、品牌一致性 |
| UX 研究员 | 用户测试、行为分析 | 用户研究、可用性测试 |
| UX 架构师 | 信息架构、交互设计、导航系统 | 复杂产品的 UX 架构 |
| 品牌守护者 | 品牌标识、一致性、定位 | 品牌策略、视觉规范 |
| 图像提示词工程师 | AI 图像生成、提示词优化 | Midjourney/DALL-E 出图 |
| 视觉叙事师 | 数据可视化、视觉叙事 | 信息图、演示文稿 |
| 趣味注入师 | 微交互、彩蛋、趣味元素 | 产品细节体验提升 |
| 包容性视觉专家 | 多元化视觉、无障碍设计 | 包容性设计、全球化视觉 |
📢 营销部
一个真实互动一个粉丝地增长。
国内平台:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 小红书运营专家 ⭐ | 种草笔记、达人合作、爆款内容 | 小红书获客、品牌种草 |
| 抖音策略师 ⭐ | 短视频策划、算法优化、直播带货 | 抖音增长、短视频营销 |
| 微信公众号运营 ⭐ | 公众号内容、社群运营、裂变增长 | 微信生态营销 |
| B站内容策略师 ⭐ | UP主运营、弹幕文化、中长视频 | B站内容增长、品牌合作 |
| 快手策略师 ⭐ | 下沉市场、老铁文化、直播电商 | 快手运营、社区信任 |
| 中国电商运营专家 | 淘宝/拼多多/京东、广告投放、大促作战 | 电商全链路深度运营 |
| 电商运营师 ⭐ | 淘宝/拼多多/京东、直播带货、大促 | 电商全平台运营(简洁版) |
| 百度 SEO 专家 ⭐ | 百度优化、百科/知道/贴吧生态 | 百度搜索营销 |
| 私域流量运营师 ⭐ | 企微SCRM、社群运营、用户生命周期 | 私域体系搭建、复购增长 |
| 直播电商主播教练 ⭐ | 直播话术、选品排品、千川投放 | 直播带货、主播孵化 |
| 跨境电商运营专家 ⭐ | Amazon/Shopee/Lazada、海外仓、品牌出海 | 跨境电商全链路运营 |
| 短视频剪辑指导师 ⭐ | 剪映/PR/达芬奇、调色、音频、特效 | 短视频剪辑技术指导 |
| 微博运营策略师 ⭐ | 热搜运营、超话、舆情公关、粉丝经济 | 微博全链路运营 |
| 播客内容策略师 ⭐ | 小宇宙/喜马拉雅、音频制作、商业化 | 播客内容创作与增长 |
| 微信视频号运营策略师 ⭐ | 视频号直播、社交裂变、私域闭环 | 视频号运营与变现 |
| 知识付费产品策划师 ⭐ | 得到/知识星球/小鹅通、内容定价 | 知识付费产品运营 |
| 小红书专家 | 生活方式内容、趋势策略 | 小红书品牌建设 |
| 微信公众号管理 | 订阅者运营、内容营销 | 微信公众号增长 |
| 知乎策略师 | 知识型内容、思想领袖建设 | 知乎品牌权威 |
| 中国市场本地化策略师 ⭐ | 抖音/小红书/微信/B站全栈本地化 | 中国市场进入策略 |
| 新闻情报官 ⭐ | 国内外多源新闻采集、交叉验证、结构化简报 | 内容生产线上游素材供应 |
⭐ 标记的是本项目原创,更贴合国内实操。其余为上游英文版翻译。
出海营销:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| TikTok 策略师 | 病毒式内容、算法优化 | 出海短视频营销 |
| Twitter 互动官 | 实时互动、思想领袖 | 出海品牌社交 |
| Instagram 策展师 | 视觉叙事、社区运营 | 出海视觉营销 |
| Reddit 社区运营 | 社区文化、真实互动 | 出海社区营销 |
| 应用商店优化师 | ASO、转化优化 | App 出海推广 |
| 视频优化专家 | YouTube 算法、观众留存、跨平台分发 | 视频营销与 SEO |
通用:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 增长黑客 | 快速获客、病毒循环、实验 | 用户增长、转化优化 |
| 内容创作者 | 多平台内容、编辑日历 | 内容策略、品牌故事 |
| 社交媒体策略师 | 跨平台策略、整合营销 | 全渠道社交运营 |
| SEO 专家 | 搜索引擎优化、技术 SEO | Google SEO、内容优化 |
| 轮播图增长引擎 | 轮播图内容、自动化投放 | 社交媒体轮播素材 |
| LinkedIn 内容创作专家 | LinkedIn 职场内容、B2B 获客 | LinkedIn 品牌建设 |
| 图书联合作者 | 思想领袖力图书、代笔协作 | 图书策划与撰写 |
| AI 引文策略师 | AEO/GEO 优化、AI 平台可见性审计 | AI 搜索引擎品牌可见性 |
💰 付费媒体部
精准投放,每一分预算都花在刀刃上。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 付费媒体审计师 | 广告账户审计、预算优化 | 广告效果诊断、降本增效 |
| 广告创意策略师 | 广告素材策划、A/B 测试 | 广告创意优化 |
| 社交广告策略师 | 社交平台广告投放 | Meta/TikTok/LinkedIn 广告 |
| PPC 竞价策略师 | 搜索竞价、关键词管理 | Google Ads、百度推广 |
| 程序化广告采买专家 | DSP、RTB、程序化购买 | 程序化广告投放 |
| 搜索词分析师 | 搜索词挖掘、否词优化 | 搜索广告精细化运营 |
| 追踪与归因专家 | 转化追踪、归因模型 | 广告效果衡量、数据打通 |
💼 销售部
从线索到成交,让每一单都有章法。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 客户拓展策略师 | 大客户拓展、ABM 策略 | 重点客户攻关 |
| 销售教练 | 销售辅导、技能提升 | 团队销售能力建设 |
| 赢单策略师 | 成交策略、MEDDPICC | 复杂销售推进 |
| Discovery 教练 | 需求挖掘、客户洞察 | 销售前期沟通 |
| 售前工程师 | 技术方案、Demo 演示 | 技术售前支持 |
| Outbound 策略师 | 外呼策略、Cold outreach | 新客户开拓 |
| Pipeline 分析师 | 销售漏斗、预测分析 | 销售数据分析、预测 |
| 投标策略师 | 投标方案、提案撰写 | 招投标、方案竞标 |
🏦 金融部
让每一笔钱都清清楚楚。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 财务预测分析师 ⭐ | 收入预测、场景建模、现金流 | SaaS 财务规划、融资对接 |
| 发票管理专家 ⭐ | 增值税发票、金税系统、三单匹配 | 发票全生命周期管理 |
| 金融风控分析师 ⭐ | 交易风控、反洗钱、电信诈骗 | 支付风控、合规审查 |
👔 人力资源部
找对人、用好人、留住人。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 招聘专家 ⭐ | Boss直聘/猎聘、校招社招、背调 | 招聘全流程管理 |
| 绩效管理专家 ⭐ | OKR/KPI、361分布、晋升答辩 | 绩效体系搭建与评估 |
⚖️ 法务部
合规是底线,风控是生命线。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 合同审查专家 ⭐ | 民法典合同编、电子签章、风险评估 | 合同审查与风控 |
| 制度文件撰写专家 ⭐ | PIPL/数据安全法、隐私政策 | 合规制度与政策撰写 |
🚚 供应链部
从工厂到用户,每一环都不掉链子。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 库存预测专家 ⭐ | 需求预测、安全库存、618/双11备货 | 库存管理与补货优化 |
| 供应商评估专家 ⭐ | 1688供应商、验厂、国标质检 | 供应商准入与分级管理 |
| 物流路线优化师 ⭐ | 顺丰/通达系、冷链、跨境物流 | 物流成本优化与路线规划 |
| 供应链采购策略师 ⭐ | 1688采购、质检、供应商管理、ERP | 供应链与采购管理 |
📦 产品部
在正确的时间做正确的事。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| Sprint 排序师 | 敏捷规划、功能优先级 | Sprint 规划、资源分配 |
| 趋势研究员 | 市场情报、竞品分析 | 市场调研、机会评估 |
| 反馈分析师 | 用户反馈分析、洞察提取 | 反馈分析、产品优先级 |
| 行为助推引擎 | 行为心理学、用户引导 | 用户行为设计、转化提升 |
| 产品经理 | 产品全生命周期、PRD、路线图 | 产品策略与交付管理 |
📋 项目管理部
让项目按时按质交付。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 高级项目经理 | 需求拆解、范围管控 | 大型项目管理 |
| 项目牧羊人 | 跨团队协调、进度跟踪 | 多团队项目协调 |
| 实验追踪员 | A/B 测试、实验管理 | 数据驱动决策 |
| 工作室制片人 | 创意项目管理、资源调度 | 内容/创意项目 |
| 工作室运营 | 工作室日常运营管理 | 团队运营效率 |
| Jira 工作流管家 | Jira 配置、工作流优化 | Jira 项目管理 |
🧪 测试部
打破一切,让用户不必承受。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 证据收集者 | 截图 QA、视觉验证 | UI 测试、Bug 文档 |
| 现实检验者 | 证据驱动认证、质量关卡 | 生产就绪评估 |
| API 测试员 | API 验证、集成测试 | 接口测试、端点验证 |
| 性能基准师 | 性能测试、优化 | 压测、性能调优 |
| 无障碍审核员 | WCAG 审核、辅助技术测试 | 无障碍合规、包容性设计 |
| 测试结果分析师 | 测试数据分析、质量度量 | 质量趋势、发布决策 |
| 工具评估师 | 工具选型、功能对比 | 技术选型、工具采购 |
| 工作流优化师 | 流程分析、自动化 | 效率提升、流程改进 |
| 嵌入式测试工程师 ⭐ | HIL 测试、固件自动化测试、EMC 测试 | 嵌入式质量保障、量产测试 |
🤝 支持部
运营的中流砥柱。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 客服响应者 | 客户服务、工单处理 | 客户支持、用户体验 |
| 数据分析师 | 数据分析、仪表盘 | 商业智能、KPI 追踪 |
| 法务合规员 | 合规审查、法规检查 | 法律合规、风险管理 |
| 高管摘要师 | 业务摘要、战略沟通 | 高管汇报、决策支持 |
| 财务追踪员 | 财务分析、预算管理 | 财务规划、成本管控 |
| 基础设施运维师 | 系统运维、可靠性工程 | 基础设施管理、故障排查 |
| 招聘运营专家 ⭐ | Boss直聘/猎聘、劳动法、校招社招 | 招聘全流程与HR合规 |
🔬 专项部
不走寻常路的专家。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 智能体编排者 | 多智能体协调、工作流管理 | 复杂项目的多智能体协作 |
| 提示词工程师 ⭐ | LLM 提示词设计、优化、评测 | 提示词开发、AI 应用优化 |
| 身份信任架构师 | AI 身份验证、信任框架 | AI 系统安全与信任 |
| 数据整合师 | 多源数据整合、仪表盘 | 数据汇总与可视化 |
| LSP 索引工程师 | 代码智能、语义索引 | 代码导航、IDE 集成 |
| 报告分发师 | 报告分发、多渠道推送 | 自动化报告分发 |
| 销售数据提取师 | 销售数据采集、结构化 | CRM 数据处理 |
| 合规审计师 | SOC 2/ISO 27001/HIPAA 合规 | 合规审计、安全认证 |
| 应付账款智能体 | 发票处理、付款自动化 | 财务流程自动化 |
| 身份图谱操作员 | 身份解析、多源匹配 | 用户身份治理 |
| 文化智能策略师 | 文化洞察、跨文化设计 | 全球化产品、本地化策略 |
| 开发者布道师 | 开发者关系、DX 工程 | 开发者社区、技术推广 |
| 模型 QA 专家 | ML 模型审计、质量验证 | 模型上线前检查 |
| ZK 管家 | Zettelkasten 知识管理 | 知识库构建、笔记系统 |
| 区块链安全审计师 | 智能合约审计、漏洞检测 | 合约安全、DeFi 审计 |
| 留学规划顾问 ⭐ | 多国申请策略、选校定位 | 留学规划、文书指导 |
| 政务数字化售前顾问 ⭐ | 方案设计、标书、等保/信创 | 政务ToG项目售前 |
| 企业培训课程设计师 ⭐ | ADDIE/SAM、企业学习平台、TTT | 培训体系搭建与课程开发 |
| MCP 构建器 | MCP 服务器、工具设计、API 集成 | MCP 开发、AI 工具扩展 |
| 文档生成器 | PDF/PPTX/DOCX/XLSX 生成 | 程序化文档创建 |
| 工作流架构师 | 工作流树设计、交接契约、故障恢复 | 系统流程规格化 |
| 自动化治理架构师 | 自动化审计、n8n 工作流治理、风险评估 | 业务自动化决策 |
| Salesforce 架构师 | Salesforce 多云设计、集成、数据模型 | 企业级 Salesforce 架构 |
| 医疗健康营销合规师 ⭐ | 医疗广告法、NMPA、互联网医疗 | 医疗健康营销合规 |
| 高考志愿填报顾问 ⭐ | 平行志愿、位次法、冲稳保策略 | 高考志愿填报规划 |
| 动态定价策略师 ⭐ | 淘宝/京东/拼多多定价、大促机制 | 电商定价与促销策略 |
| AI 治理政策专家 ⭐ | 算法备案、生成式AI管理、伦理审查 | AI 合规与治理框架 |
| 企业风险评估师 ⭐ | COSO本土化、国企风控、ESG | 企业风险管理与审计 |
| 会议效率专家 ⭐ | 飞书/钉钉/腾讯会议、OKR周会 | 会议管理与纪要输出 |
| 土木工程师 | Eurocode/DIN/ACI/GB 多标准结构分析 | 土木与结构工程设计 |
| 法国咨询市场专家 | ESN/SI 生态、Malt 平台、薪资代管 | 法国自由职业市场导航 |
| 韩国商务专家 | 품의流程、KakaoTalk 礼仪、层级关系 | 韩国商务文化导航 |
| 招聘专家 ⭐ | 国内招聘平台、人才评估、劳动法合规 | 招聘运营与雇主品牌 |
| 技术翻译专家 | 中英文双向翻译、编程/AI/云计算术语 | 技术文档翻译 |
🥽 空间计算部
构建下一代空间交互体验。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| visionOS 空间工程师 | visionOS、SwiftUI 空间 UI | Apple Vision Pro 开发 |
| macOS Metal 空间工程师 | Metal、GPU 渲染 | macOS 高性能图形 |
| XR 界面架构师 | 空间 UI 架构、交互设计 | XR 应用界面设计 |
| XR 沉浸式开发者 | WebXR、沉浸式体验 | VR/AR 应用开发 |
| XR 座舱交互专家 | 座舱 UI、多模态交互 | 汽车/航空 XR 交互 |
| 终端集成专家 | 终端模拟、系统集成 | 空间计算终端工具 |
🎮 游戏开发部
从独立游戏到 3A 大作,全引擎覆盖。
通用:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 游戏设计师 | 游戏机制、系统设计、平衡性 | 游戏核心玩法设计 |
| 关卡设计师 | 关卡布局、节奏控制、空间叙事 | 关卡设计、场景构建 |
| 叙事设计师 | 剧情设计、对话系统、世界观 | 游戏剧情、互动叙事 |
| 技术美术 | Shader、渲染管线、美术工具 | 画面效果、性能优化 |
| 游戏音频工程师 | 音效设计、音频引擎、空间音频 | 游戏音效、配乐 |
Unity:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| Unity 架构师 | Unity 架构、ECS、性能优化 | Unity 项目架构 |
| Unity 编辑器工具开发者 | 编辑器扩展、自定义工具 | Unity 工具链开发 |
| Unity 多人游戏工程师 | Netcode、同步、网络架构 | Unity 联机游戏 |
| Unity Shader Graph 美术师 | Shader Graph、URP/HDRP | Unity 视觉效果 |
Unreal Engine:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| Unreal 多人游戏架构师 | Replication、网络同步 | UE 联机架构 |
| Unreal 系统工程师 | Gameplay 框架、C++ 系统 | UE 核心系统开发 |
| Unreal 技术美术 | 材质、Niagara、渲染管线 | UE 画面与性能 |
| Unreal 世界构建师 | 开放世界、地形、关卡串流 | UE 场景构建 |
Blender:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| Blender 插件工程师 | Python 插件、资源验证、导出自动化 | Blender 管线工具开发 |
Godot:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| Godot 游戏脚本开发者 | GDScript、场景树、信号系统 | Godot 游戏逻辑 |
| Godot 多人游戏工程师 | MultiplayerAPI、网络同步 | Godot 联机游戏 |
| Godot Shader 开发者 | Godot Shader Language、视觉效果 | Godot 画面效果 |
Roblox Studio:
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| Roblox 虚拟形象创作者 | 虚拟形象、UGC 资产 | Roblox 角色设计 |
| Roblox 体验设计师 | 体验设计、游戏循环 | Roblox 游戏设计 |
| Roblox 系统脚本工程师 | Luau 脚本、数据存储 | Roblox 游戏开发 |
📖 学术部
为叙事设计、世界构建和文化研究提供学术级支撑。
| 智能体 | 专长 | 适用场景 |
|---|---|---|
| 人类学家 | 文化体系、仪式、民族志 | 世界观设计、文化构建 |
| 地理学家 | 自然与人文地理、空间分析 | 地图构建、场景设计 |
| 历史学家 | 历史分析、史料考证 | 历史题材验证、年代设定 |
| 叙事学家 | 叙事理论、故事结构 | 剧情设计、角色弧线 |
| 心理学家 | 行为心理、人格理论 | 角色心理塑造、动机设计 |
| 学习规划师 ⭐ | 考研/考公/法考备考、学习方法论 | 个性化学习计划与备考规划 |
🎯 战略部
从发现到运营的全流程战略指导。详见 strategy/ 目录。
| 文档 | 内容 |
|---|---|
| 高管简报 | NEXUS 战略概览 |
| 快速上手 | 5 分钟上手指南 |
| 完整战略 | 运营纲领全文 |
| 智能体激活提示词 | 各智能体的激活指令 |
| 交接模板 | 智能体间的交接规范 |
| Phase 0-6 Playbooks | 发现 · 策略 · 基础 · 构建 · 加固 · 上线 · 运营 |
| 场景 Runbook | 创业 MVP · 企业功能 · 事故响应 · 营销活动 |
工具集成
支持 18 种主流 AI 编程工具,通过 scripts/ 目录下的脚本实现格式转换和一键安装。
支持的工具
| 工具 | 安装位置 | 类型 |
|---|---|---|
| OpenClaw ⭐ | ~/.openclaw/agency-agents/ |
全局,需转换 |
| Claude Code | ~/.claude/agents/ |
全局,直接复制 |
| GitHub Copilot | ~/.github/agents/ + ~/.copilot/agents/ |
全局,直接复制 |
| Kiro (Amazon) | ~/.kiro/agents/ |
全局,需转换 |
| Antigravity | ~/.gemini/antigravity/skills/ |
全局,需转换 |
| Gemini CLI | ~/.gemini/extensions/agency-agents/ |
全局,需转换 |
| Qwen Code | .qwen/agents/ |
项目级,需转换 |
| Cursor | .cursor/rules/ |
项目级,需转换 |
| Trae | .trae/rules/ |
项目级,需转换 |
| OpenCode | .opencode/agents/ |
项目级,需转换 |
| Aider | CONVENTIONS.md |
项目级,需转换 |
| Windsurf | .windsurfrules |
项目级,需转换 |
| Codex CLI | .codex/agents/ |
项目级,需转换 |
| WorkBuddy (腾讯) | ~/.workbuddy/skills/ |
全局,需转换 |
| CodeWhale (原 DeepSeek-TUI) | ~/.codewhale/skills/ |
全局,需转换 |
| Hermes Agent (NousResearch) | ~/.hermes/skills/ |
全局,需转换 |
| DeerFlow 2.0 (字节跳动) | skills/custom/ |
项目级,需转换 |
| Qoder | ~/.qoder/agents/ 或 .qoder/agents/ |
全局/项目级,需转换 |
使用方法
# 第一步:转换格式(Claude Code 和 GitHub Copilot 可跳过此步)
./scripts/convert.sh # 转换为所有工具格式
./scripts/convert.sh --tool cursor # 只转换 Cursor 格式
# 第二步:安装到本地
./scripts/install.sh # 自动检测并安装
./scripts/install.sh --tool cursor # 安装到指定工具
# 检查智能体文件格式
./scripts/lint-agents.sh各工具安装说明
⭐ OpenClaw(推荐)
OpenClaw 会将每个智能体拆分为三个文件,天然支持多智能体协作:
SOUL.md— 身份、记忆、沟通风格、关键规则AGENTS.md— 核心使命、技术交付物、工作流程IDENTITY.md— 名称与简介
./scripts/convert.sh --tool openclaw
./scripts/install.sh --tool openclaw
# 安装后重启 OpenClaw 网关
openclaw gateway restartClaude Code
智能体直接从仓库复制到 ~/.claude/agents/,无需转换。
./scripts/install.sh --tool claude-code在 Claude Code 中激活:
激活前端开发者模式,帮我审查这个组件。GitHub Copilot
智能体直接从仓库复制到 ~/.github/agents/ 和 ~/.copilot/agents/,无需转换。
./scripts/install.sh --tool copilot在 GitHub Copilot 中激活:
使用前端开发者智能体帮我审查这个组件。Antigravity (Gemini)
转换为 Antigravity skill 格式并安装到 ~/.gemini/antigravity/skills/。
./scripts/convert.sh --tool antigravity
./scripts/install.sh --tool antigravityGemini CLI
转换为 Gemini CLI 扩展格式并安装到 ~/.gemini/extensions/agency-agents/。
./scripts/convert.sh --tool gemini-cli
./scripts/install.sh --tool gemini-cliQwen Code
转换为 Qwen Code SubAgent 格式并安装到项目目录 .qwen/agents/。
./scripts/convert.sh --tool qwen
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool qwen在 Qwen Code 中激活:
使用前端开发者智能体帮我审查这个组件。提示:安装后在 Qwen Code 中运行
/agents manage刷新,或重启会话。
Cursor
每个智能体会变成一个 .mdc 规则文件,安装到项目目录 .cursor/rules/。
Cursor 使用 "智能匹配"模式(alwaysApply: false):AI 根据每个规则的 description 字段自动判断是否相关,相关时自动引用完整内容。
安装:
# 第一步:转换格式(在仓库目录运行)
./scripts/convert.sh --tool cursor
# 第二步:安装到项目(在你的项目目录运行)
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool cursor⚠️ 重要:建议精选安装
全部安装 186 个规则会导致 Cursor 需要扫描大量 description 来判断相关性,可能影响匹配准确度。推荐做法:
# 方法一:全量安装后删除不需要的
/path/to/agency-agents-zh/scripts/install.sh --tool cursor
# 然后手动删除 .cursor/rules/ 中不需要的 .mdc 文件,保留 10-20 个常用的
# 方法二:只复制你需要的智能体(转换后)
./scripts/convert.sh --tool cursor
mkdir -p /your/project/.cursor/rules
cp integrations/cursor/rules/engineering-frontend-developer.mdc /your/project/.cursor/rules/
cp integrations/cursor/rules/engineering-code-reviewer.mdc /your/project/.cursor/rules/
# ... 按需复制安装后如何使用:
- 安装后
.cursor/rules/中的.mdc文件会自动被 Cursor 识别 - 在 Chat 或 Composer 中正常提问,Cursor 自动匹配相关智能体:text
帮我审查这个组件的性能问题 → 自动匹配前端开发者 这段代码有安全漏洞吗 → 自动匹配安全审计员 - 也可以在 Cursor Settings(
Cmd+,)→ Rules → Project Rules 中查看所有规则 - 还可以在 Chat 中用
@规则名手动指定引用某个智能体
排查:如果看不到规则,确认
.cursor/rules/在项目根目录、文件扩展名是.mdc、已重新打开项目。
Trae
转换为 Trae rule 文件并安装到项目目录 .trae/rules/。格式与 Cursor 同源(仅扩展名 .md 不同)。
./scripts/convert.sh --tool trae
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool trae⚠️ 关于"装了但几乎不自动触发"(见 issue #59):
转换出的 rule 默认 alwaysApply: false + 空 globs:,属于 "agent-requested rule"——Trae 模型读 description 自行决定是否加载。全装 268 条 rule 会让 description 互相稀释、几乎命中不到任何一条,这是设计行为不是 bug。
正确姿势:
- 精选安装(推荐):只挑 10–20 条常用 rule 放进
.trae/rules/,自动匹配才会真正起作用。 @显式调用:对话里输入@engineering-pc-host-engineer ...强制加载某条 rule。- 核心 rule 改 alwaysApply:把代码审查、git 工作流之类的 1–3 条改成
alwaysApply: true长期生效。
详细说明见 integrations/trae/README.md。
OpenCode
转换为 OpenCode agent 文件并安装到项目目录 .opencode/agents/。
./scripts/convert.sh --tool opencode
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool opencodeAider
所有智能体编译为单个 CONVENTIONS.md 文件,Aider 会自动读取。
./scripts/convert.sh --tool aider
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool aider在 Aider 会话中激活:
使用前端开发者智能体帮我重构这个组件。Windsurf
所有智能体编译为单个 .windsurfrules 文件。
./scripts/convert.sh --tool windsurf
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool windsurfCodex CLI
转换为 OpenAI Codex CLI agent 文件(TOML 格式)并安装到项目目录 .codex/agents/。
./scripts/convert.sh --tool codex
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool codex在 Codex 中使用时,智能体会作为 subagent 被调用。也可以在 AGENTS.md 中引用。
Kiro (Amazon)
Amazon 的 Spec 驱动 AI IDE,基于 Claude 模型。每个智能体转换为 JSON 配置 + 提示词文件,安装到 ~/.kiro/agents/(全局)。
./scripts/convert.sh --tool kiro
./scripts/install.sh --tool kiro在 Kiro 中切换智能体:
/agent swap或启动时直接指定:
kiro-cli --agent engineering-frontend-developerWorkBuddy (腾讯)
腾讯推出的全场景 AI 桌面智能体,兼容 OpenClaw 技能,支持多模型切换。每个智能体转换为 SKILL.md 技能文件,安装到 ~/.workbuddy/skills/(全局)。
./scripts/convert.sh --tool workbuddy
./scripts/install.sh --tool workbuddy安装后重启 WorkBuddy 即可在技能列表中看到所有智能体。
CodeWhale(原 DeepSeek-TUI)
专为 DeepSeek 优化、对国内网络友好的终端编程 Agent(Rust 实现,原名 DeepSeek-TUI)。每个智能体转换为 SKILL.md 技能文件,安装到 ~/.codewhale/skills/(全局),在 CodeWhale 里用 /skills 加载。
./scripts/convert.sh --tool codewhale
./scripts/install.sh --tool codewhale安装后在 CodeWhale 中输入 /skills 即可看到并调用所有智能体。
Hermes Agent (NousResearch)
NousResearch 的开源 AI 智能体框架,支持技能系统、子代理编排、会话记忆。每个智能体转换为 SKILL.md 技能文件,按分类目录安装到 ~/.hermes/skills/(全局)。
./scripts/convert.sh --tool hermes
./scripts/install.sh --tool hermes安装后推荐在 Hermes CLI 中通过 hermes skills 查看和管理所有技能,或在对话中自然语言激活。
⚠️ Discord 模式下不要一次性全量安装
Hermes 的 Discord 集成会把每一个 skill 注册成 Discord 斜杠命令,Discord API 对 bot 所有命令的 JSON 序列化总长度有 8000 字符硬上限,超过后会返回
error code 50035(见 issue #45)。本仓库有近 200 个 skill,一次装全会直接炸 Discord。解决办法:在 Discord 中使用时请按分类分批安装,用
--category参数(可多次传入):bash# 只装 marketing 分类 ./scripts/install.sh --tool hermes --category marketing # 同时装 engineering 和 design ./scripts/install.sh --tool hermes --category engineering --category design可选分类:
academic, blender, design, engineering, finance, game-development, godot, hr, legal, marketing, paid-media, product, project-management, roblox-studio, sales, spatial-computing, specialized, supply-chain, support, testing, unity, unreal-engine。Hermes CLI 本身没有此限制,全量安装可以继续使用。
DeerFlow 2.0 (字节跳动)
字节跳动的开源 SuperAgent 框架,支持子代理、沙箱、持久记忆。每个智能体转换为 SKILL.md 技能文件。
./scripts/convert.sh --tool deerflow
./scripts/install.sh --tool deerflow默认安装到当前目录的 skills/custom/。可通过环境变量自定义路径:
DEERFLOW_SKILLS_DIR=/path/to/deerflow/skills/custom ./scripts/install.sh --tool deerflow安装后在 DeerFlow 的任务中,相关技能会自动加载。
Qoder
转换为 Qoder SubAgent 格式(Markdown + YAML frontmatter)并安装到 ~/.qoder/agents/(全局)或项目目录 .qoder/agents/。
./scripts/convert.sh --tool qoder
./scripts/install.sh --tool qoder在 Qoder 中使用:
- 自动触发:用自然语言描述任务,Qoder 根据 description 自动选择智能体
- 手动触发:输入
/agent-name(如/engineering-frontend-developer)
修改智能体后重新生成
添加新智能体或编辑现有智能体后,重新生成集成文件:
./scripts/convert.sh # 重新生成所有工具
./scripts/convert.sh --tool cursor # 只重新生成指定工具🇨🇳 中国市场原创智能体
除翻译外,本项目包含 50 个原创智能体,专为中国平台和业务场景打造:
- 平台运营:小红书、抖音、微信公众号/视频号/小程序、B站、快手、微博、知乎
- 企业协作:飞书、钉钉集成开发
- 垂直领域:跨境电商、政务ToG、医疗合规、高考志愿、留学规划、Qt 工业上位机、通用机械设计、畜禽养殖档案核对
- 业务支撑:私域流量、直播电商、库存预测、合同审查、发票管理
在上方智能体阵容中标有 ⭐ 的即为原创智能体。
实战案例
场景一:出海产品 MVP
你的团队:
- 前端开发者 — 构建 React 应用
- 后端架构师 — 设计 API 和数据库
- 增长黑客 — 规划用户获取
- 快速原型师 — 快速迭代
- 现实检验者 — 上线前质量把关
场景二:[小红书品牌推广](examples/workflow-xiaohongshu-launch.md)(完整流程)
你的团队:
- 小红书运营专家 — 种草内容策略和达人合作
- 内容创作者 — 产出种草笔记
- 品牌守护者 — 品牌调性把关
- 数据分析师 — 追踪投放数据、出复盘报告
- 增长黑客 — 设计转化和裂变路径
贡献
欢迎参与!翻译智能体、改进内容、新增中国平台智能体都行。详见 CONTRIBUTING.md。
交流 · Community
| 微信扫码关注 | 微信公众号 「AI不止语」(微信搜索 AI_BuZhiYu)— 技术问答 · 项目更新 · 实战文章
渠道 加入方式
QQ 2群 点击加入(群号 1071280067)
微信群 关注公众号后回复「群」获取入群方式 |
| --- | --- |
姊妹项目
| 项目 | 定位 | 一句话 |
|---|---|---|
| 本项目(agency-agents-zh) | 🎭 专家角色库 | 268 个即插即用 AI 专家,含 53 中国原创(小红书 / 抖音 / 飞书 / 钉钉 / Qt 上位机 / 机械设计) |
| agency-orchestrator | 🚀 编排引擎 | 一句话 → 268 专家协作,几分钟出方案(10 家 LLM / 7 免费) |
| superpowers-zh | 🧠 工作方法论 | 20 个 skills 教 AI 怎么干活(TDD / 调试 / 代码审查等) |
| ai-coding-guide | 📖 实战教程 | 66 个 Claude Code 技巧 + 9 款工具最佳实践 + 配置模板 |
| shellward | 🛡️ 安全中间件 | 8 层防御 + DLP 数据流 + 注入检测,零依赖(含 MCP Server) |
| 🆕 ai-shortfilm-prompts | 🎬 视频提示词 | Mx-Shell《丧尸清道夫》5 段式方法论 + Skill,Seedance / 小云雀 / Sora / 可灵 / 即梦通用 |
| 🆕 local-agent-toolkit | 🛠️ Agent 本地三件套 | 给 agent 配上记忆 / 技能管理 / 运行追踪,零依赖、数据不出本机(engram · skillet · tracelet,npx 即用) |
| 🆕 codepet | 🐾 桌面养成桌宠 | 码宠 CodePet —— 你写代码 / 用 Claude Code,它就涨经验、升级、换状态、跳舞。全本地、隐私优先、开源 |
致谢
- 原始英文版:msitarzewski/agency-agents(MIT 协议)
- 感谢原作者 @msitarzewski 创建了这个优秀的项目
许可证
MIT License — 自由使用,商业或个人均可。
⭐ Star 趋势
File: examples/README.md
Examples
This directory contains example outputs demonstrating how the agency's agents can be orchestrated together to tackle real-world tasks.
Why This Exists
The agency-agents repo defines dozens of specialized agents across engineering, design, marketing, product, support, spatial computing, and project management. But agent definitions alone don't show what happens when you deploy them all at once on a single mission.
These examples answer the question: "What does it actually look like when the full agency collaborates?"
Contents
[nexus-spatial-discovery.md](./nexus-spatial-discovery.md)
What: A complete product discovery exercise where 8 agents worked in parallel to evaluate a software opportunity and produce a unified plan.
The scenario: Web research identified an opportunity at the intersection of AI agent orchestration and spatial computing. The entire agency was then deployed simultaneously to produce:
- Market validation and competitive analysis
- Technical architecture (8-service system design with full SQL schema)
- Brand strategy and visual identity
- Go-to-market and growth plan
- Customer support operations blueprint
- UX research plan with personas and journey maps
- 35-week project execution plan with 65 sprint tickets
- Spatial interface architecture specification
Agents used:
| Agent | Role |
|---|---|
| Product Trend Researcher | Market validation, competitive landscape |
| Backend Architect | System architecture, data model, API design |
| Brand Guardian | Positioning, visual identity, naming |
| Growth Hacker | GTM strategy, pricing, launch plan |
| Support Responder | Support tiers, onboarding, community |
| UX Researcher | Personas, journey maps, design principles |
| Project Shepherd | Phase plan, sprints, risk register |
| XR Interface Architect | Spatial UI specification |
Key takeaway: All 8 agents ran in parallel and produced coherent, cross-referencing plans without coordination overhead. The output demonstrates the agency's ability to go from "find an opportunity" to "here's the full blueprint" in a single session.
Adding New Examples
If you run an interesting multi-agent exercise, consider adding it here. Good examples show:
- Multiple agents collaborating on a shared objective
- The breadth of the agency's capabilities
- Real-world applicability of the agent definitions
File: integrations/opencode/README.md
OpenCode Integration
OpenCode agents are .md files with YAML frontmatter stored in.opencode/agents/. The converter maps named colors to hex codes and addsmode: subagent so agents are invoked on-demand via @agent-name rather
than cluttering the primary agent picker.
Install
# Run from your project root
cd /your/project
/path/to/agency-agents/scripts/install.sh --tool opencodeThis creates .opencode/agents/<slug>.md files in your project directory.
Activate an Agent
In OpenCode, invoke a subagent with the @ prefix:
@frontend-developer help build this component.@reality-checker review this PR.You can also select agents from the OpenCode UI's agent picker.
Agent Format
Each generated agent file contains:
---
name: Frontend Developer
mode: subagent
color: "#00FFFF"
---- mode: subagent — agent is available on-demand, not shown in the primary Tab-cycle list
- color — hex code (named colors from source files are converted automatically)
Project vs Global
Agents in .opencode/agents/ are project-scoped. To make them available
globally across all projects, copy them to your OpenCode config directory:
mkdir -p ~/.config/opencode/agents
cp integrations/opencode/agents/*.md ~/.config/opencode/agents/Regenerate
./scripts/convert.sh --tool opencodeFile: integrations/openclaw/README.md
OpenClaw Integration
OpenClaw agents are installed as workspaces containing SOUL.md, AGENTS.md,
and IDENTITY.md files. The installer copies each workspace into~/.openclaw/agency-agents/ and registers it when the openclaw CLI is
available.
Before installing, generate the OpenClaw workspaces:
./scripts/convert.sh --tool openclawInstall
./scripts/install.sh --tool openclawActivate an Agent
After installation, agents are available by agentId in OpenClaw sessions.
If the OpenClaw gateway is already running, restart it after installation:
openclaw gateway restartRegenerate
./scripts/convert.sh --tool openclawFile: integrations/mcp-memory/README.md
MCP Memory Integration
Give any agent persistent memory across sessions using the Model Context Protocol (MCP).
What It Does
By default, agents in The Agency start every session from scratch. Context is passed manually via copy-paste between agents and sessions. An MCP memory server changes that:
- Cross-session memory: An agent remembers decisions, deliverables, and context from previous sessions
- Handoff continuity: When one agent hands off to another, the receiving agent can recall exactly what was done — no copy-paste required
- Rollback on failure: When a QA check fails or an architecture decision turns out wrong, roll back to a known-good state instead of starting over
Setup
You need an MCP server that provides memory tools: remember, recall, rollback, and search. Add it to your MCP client config (Claude Code, Cursor, etc.):
{
"mcpServers": {
"memory": {
"command": "your-mcp-memory-server",
"args": []
}
}
}Any MCP server that exposes remember, recall, rollback, and search tools will work. Check the MCP ecosystem for available implementations.
How to Add Memory to Any Agent
To enhance an existing agent with persistent memory, add a Memory Integration section to the agent's prompt. This section instructs the agent to use MCP memory tools at key moments.
The Pattern
## Memory Integration
When you start a session:
- Recall relevant context from previous sessions using your role and the current project as search terms
- Review any memories tagged with your agent name to pick up where you left off
When you make key decisions or complete deliverables:
- Remember the decision or deliverable with descriptive tags (your agent name, the project, the topic)
- Include enough context that a future session — or a different agent — can understand what was done and why
When handing off to another agent:
- Remember your deliverables tagged for the receiving agent
- Include the handoff metadata: what you completed, what's pending, and what the next agent needs to know
When something fails and you need to recover:
- Search for the last known-good state
- Use rollback to restore to that point rather than rebuilding from scratchWhat the Agent Does With This
The LLM will use MCP memory tools automatically when given these instructions:
remember— store a decision, deliverable, or context snapshot with tagsrecall— search for relevant memories by keyword, tag, or semantic similarityrollback— revert to a previous state when something goes wrongsearch— find specific memories across sessions and agents
No code changes to the agent files. No API calls to write. The MCP tools handle everything.
Example: Enhancing the Backend Architect
See backend-architect-with-memory.md for a complete example — the standard Backend Architect agent with a Memory Integration section added.
Example: Memory-Powered Workflow
See ../../examples/workflow-with-memory.md for the Startup MVP workflow enhanced with persistent memory, showing how agents pass context through memory instead of copy-paste.
Tips
- Tag consistently: Use the agent name and project name as tags on every memory. This makes recall reliable.
- Let the LLM decide what's important: The memory instructions are guidance, not rigid rules. The LLM will figure out when to remember and what to recall.
- Rollback is the killer feature: When a Reality Checker fails a deliverable, the original agent can roll back to its last checkpoint instead of trying to manually undo changes.
File: integrations/github-copilot/README.md
GitHub Copilot Integration
The Agency works with GitHub Copilot out of the box. No conversion needed —
agents use the existing .md + YAML frontmatter format.
Install
# Copy all agents to your GitHub Copilot agents directories
./scripts/install.sh --tool copilot
# Or manually copy a category
cp engineering/*.md ~/.github/agents/
cp engineering/*.md ~/.copilot/agents/Activate an Agent
In any GitHub Copilot session, reference an agent by name:
Activate Frontend Developer and help me build a React component.Use the Reality Checker agent to verify this feature is production-ready.Agent Directory
Agents are organized into divisions. See the main README for
the full current roster.
File: integrations/gemini-cli/README.md
Gemini CLI Integration
Packages all 61 Agency agents as a Gemini CLI extension. The extension
installs to ~/.gemini/extensions/agency-agents/.
Install
# Generate the Gemini CLI integration files first
./scripts/convert.sh --tool gemini-cli
# Then install the extension
./scripts/install.sh --tool gemini-cliActivate a Skill
In Gemini CLI, reference an agent by name:
Use the frontend-developer skill to help me build this UI.Extension Structure
~/.gemini/extensions/agency-agents/
gemini-extension.json
skills/
frontend-developer/SKILL.md
backend-architect/SKILL.md
reality-checker/SKILL.md
...Regenerate
./scripts/convert.sh --tool gemini-cliFile: integrations/cursor/README.md
Cursor Integration
Converts all 180 Agency agents into Cursor .mdc rule files. Rules are
project-scoped — install them from your project root.
Install
# Convert first, then install from your project root
./scripts/convert.sh --tool cursor
cd /your/project
/path/to/agency-agents-zh/scripts/install.sh --tool cursorThis creates .cursor/rules/<agent-slug>.mdc files in your project.
Finding and Activating Rules
After installation, rules default to alwaysApply: false, meaning they
won't activate automatically. You need to enable them manually:
- Open Cursor Settings (
Cmd+,/Ctrl+,) → Rules → Project Rules - You'll see all installed agent rules listed there
- Toggle on the agents you need (avoid enabling all 180 at once — too much context)
- Once enabled, the rules automatically apply in Cursor Chat and Composer
Alternatively, reference an agent in your prompt:
@rules Use the frontend developer standards to review this component.Or enable a rule as always-on by editing its frontmatter:
---
globs: "**/*.tsx,**/*.ts"
alwaysApply: true
---Troubleshooting
If you can't see rules in Cursor:
- Ensure
.cursor/rules/is in your project root (not a global directory) - Files must have
.mdcextension (not.md) - Try reopening the project or restarting Cursor
Regenerate
./scripts/convert.sh --tool cursorFile: integrations/claude-code/README.md
Claude Code Integration
The Agency was built for Claude Code. No conversion needed — agents work
natively with the existing .md + YAML frontmatter format.
Install
# Copy all agents to your Claude Code agents directory
./scripts/install.sh --tool claude-code
# Or manually copy a category
cp engineering/*.md ~/.claude/agents/Activate an Agent
In any Claude Code session, reference an agent by name:
Activate Frontend Developer and help me build a React component.Use the Reality Checker agent to verify this feature is production-ready.Agent Directory
Agents are organized into divisions. See the main README for
the full current roster.
File: integrations/antigravity/README.md
Antigravity Integration
Installs all 61 Agency agents as Antigravity skills. Each agent is prefixed
with agency- to avoid conflicts with existing skills.
Install
./scripts/install.sh --tool antigravityThis copies files from integrations/antigravity/ to~/.gemini/antigravity/skills/.
Activate a Skill
In Antigravity, activate an agent by its slug:
Use the agency-frontend-developer skill to review this component.Available slugs follow the pattern agency-<agent-name>, e.g.:
agency-frontend-developeragency-backend-architectagency-reality-checkeragency-growth-hacker
Regenerate
After modifying agents, regenerate the skill files:
./scripts/convert.sh --tool antigravityFile Format
Each skill is a SKILL.md file with Antigravity-compatible frontmatter:
---
name: agency-frontend-developer
risk: low
source: community
date_added: '2026-03-08'
---2. Official Technical Reference & Guides (jnMetaCode/ai-coding-guide)
File: README.md
AI 编程工具实战指南
简体中文 | English
10 款主流 AI 编程工具的中文最佳实践 — 不讲概念,只讲怎么用好。从提示词技巧到工作流设计,从单工具精通到多工具协作,帮你把 AI 编程效率拉满。
📖 免费配套学习 → 从零学会 AI 编程(180 节)+ 从零构建 AI 智能体(40 节)· 🌍 English / 日本語 / Español / 한국어 / 繁體中文
📖 免费配套学习 → 从零学会 AI 编程:180 节免费实操课 + 《AI 编程实战三卷书》在线阅读(卷一·入门 / 卷二·工作流 / 卷三·架构 / 别册·速查)+ 实战社区 · 永久免费 · 有想法或需求,欢迎来社区一起拆解
| 10 款工具全覆盖教程 | 66 个技巧Claude Code 深度 | 7 套方法论提示词/调试/测试 | 可复制模板即装即用配置 |
|---|
🚀 快速开始
先看一眼 📋 速查表 — 10 款工具一页横向对比:类型、上下文、配置文件、常用命令。知道自己选哪个、怎么配、怎么用。
按画像走推荐路径:
| 你是... | 推荐顺序 |
|---|---|
| 纯新手,还没用过 AI 编程 | 速查表 → Trae(免费入门)→ 提示词工程 |
| 前端 / 日常编码为主 | Cursor → 提示词工程 → 实战场景 |
| 后端 / 重构 / 大项目 | Claude Code → 需求拆解 → 实战场景 |
| 从 Copilot 迁来 | Copilot → Claude Code(对比差异)→ 多工具选型 |
| 已订阅 ChatGPT Plus/Pro | Codex CLI → Claude Code 对比 → 多工具选型 |
| 控成本 / 独立开发者 | 速查表 → Gemini CLI 或 Aider + 本地模型 |
| 团队协作 / 高质量交付 | Kiro → 代码审查 → 测试策略 |
已经在用了? 直接看:速查表 · 进阶技巧 · 实战工作流 · 生态项目
🔧 10 款工具教程
| 工具 | 类型 | 亮点 |
|---|---|---|
| Claude Code | CLI Agent | 66 个技巧,Agent + Skill + Hook 完整工作流 |
| Codex CLI | CLI Agent | OpenAI 官方开源(Rust),Sandbox + AGENTS.md,ChatGPT 订阅可用 |
| Cursor | IDE | .cursorrules 配置,Composer Agent 模式 |
| GitHub Copilot | IDE 插件 | 行内补全 + Agent 模式 + 自定义指令 |
| OpenClaw | AI Agent 框架 | 338k Stars,多平台连接 + Skills + Cron 自动化 |
| Windsurf | IDE | Cascade Agent,自动上下文 |
| Gemini CLI | CLI | Google 出品,大代码库分析 |
| Kiro | IDE | AWS 出品,Spec 驱动开发 |
| Aider | CLI | Git 原生,支持几乎所有 LLM |
| Trae | IDE | 字节出品,免费 Claude/GPT,国内直连 |
每个工具都有:核心概念 → 快速上手 → 提示词技巧 → 进阶用法 → 配置模板
📚 通用方法论
不管用哪个工具,这些方法都能让你写出更好的提示词、设计更高效的工作流:
| 主题 | 解决什么问题 |
|---|---|
| 提示词工程 | AI 编程场景下的提示词技巧,不是通用 prompt engineering |
| 需求拆解 | 把大任务拆成 AI 能一次做好的小任务 |
| 代码审查 | 让 AI 审查代码的最佳实践 |
| 调试方法论 | 用 AI 高效调试的系统方法 |
| 上下文管理 | 控制 AI 的上下文窗口,避免"变笨" |
| 测试策略 | 用 AI 写测试的方法和注意事项 |
| 安全注意事项 | AI 编程中的安全风险和防护 |
🔗 实战工作流
真实项目怎么跑完整流程,以及不同工具怎么各展所长。
| 工作流 | 说明 |
|---|---|
| 实战场景脚本 | 重构 / 协作开发 / 补测试——3 个端到端对话脚本,复制改就能用 |
| ⚠️ 陷阱合集 | Claude Code / Cursor / Copilot 各 8 个真实踩坑,症状 / 根因 / 出坑 / 预防 四段式 |
| Claude Code + Cursor 协作 | Claude Code 做架构设计和复杂重构,Cursor 做日常编码 |
| Claude Code + Copilot 协作 | Claude Code 做 Agent 任务,Copilot 做行内补全 |
| 多工具选型指南 | 什么场景用什么工具,一张表说清楚 |
🌐 相关项目
以下项目均由「AI不止语」品牌持续维护,构成从 AI 编程到 AI 视频创作的完整链路:
AI 编程线:
读书 → 学工具 → 注入方法论 → 加载专家 → 多角色编排 → 安全防护
(book) (guide) (superpowers) (agents) (orchestrator) (shellward)
AI 视频线:
方法论 + 案例 + Skill
(ai-shortfilm-prompts)| 项目 | 定位 | 一句话 | 教程 |
|---|---|---|---|
| ai-coding-trilogy | 📚 三卷书 | 把本仓内容按读者画像重组:入门/工作流/架构(PDF + 在线版) | 产品页 |
| 本项目(ai-coding-guide) | 📖 实战教程 | 66 个 Claude Code 技巧 + 10 款工具最佳实践 + 配置模板 | — |
| superpowers-zh | 🧠 工作方法论 | 20 个 skills 教 AI 怎么干活(TDD / 调试 / 代码审查等) | 安装与使用 |
| agency-agents-zh | 🎭 专家角色库 | 211 个即插即用 AI 专家,含 46 中国原创(小红书 / 抖音 / 飞书 / 钉钉) | 安装与使用 |
| agency-orchestrator | 🚀 编排引擎 | 一句话 → 211 专家协作,几分钟出方案(9 家 LLM / 6 免费) | 安装与使用 |
| shellward | 🛡️ 安全中间件 | 8 层防御 + DLP 数据流 + 注入检测,零依赖(含 MCP Server) | 安装与使用 |
| 🆕 ai-shortfilm-prompts | 🎬 视频提示词 | Mx-Shell《丧尸清道夫》5 段式方法论 + Skill,覆盖 Seedance / 小云雀 / Sora / 可灵 / 即梦 | — |
交流 · Community
| 微信扫码关注 | 微信公众号 「AI不止语」(微信搜索 AI_BuZhiYu)— 技术问答 · 项目更新 · 实战文章
渠道 加入方式
QQ 2群 点击加入(群号 1071280067)
微信群 关注公众号后回复「群」获取入群方式 |
| --- | --- |
商业合作 · 内训咨询
仓库主体(教程 / 模板 / 脚本)永久 Apache-2.0 免费开源,欢迎个人无障碍使用。
但以下场景建议先沟通:
| 场景 | 适合谁 |
|---|---|
| 企业内训(10 人以上 / 系列课) | 团队 lead / HR / 技术总监 |
| 付费课程 / 训练营整合本仓内容 | 教育机构 / 自媒体培训方 |
| AI 编程团队咨询(选型 / 工作流设计 / CI 改造) | 技术 leadership |
纸书 / 电子书出版(基于 book/ 内容) |
出版社 / 编辑 |
| 演讲 / 闭门分享(线下活动 / 公司年会 / 行业大会) | 大会主办方 / 企业 |
| 白标 / 内部知识库(把内容嵌入企业内部 Wiki) | 大型团队 |
联系方式:
- 微信公众号 「AI不止语」(搜索
AI_BuZhiYu)后台留言「合作」 - GitHub Issue(标题加
[BUSINESS]前缀):提交咨询
关于 license:仓库主体 Apache-2.0 永远不变;
book/目录下的书用 CC BY-NC-SA 4.0(个人免费 / 商业使用需授权)。如果你只是个人学习、研究、写博客、做 demo——尽情使用,不用打招呼,注明来源就好。
贡献
欢迎参与!详见 CONTRIBUTING.md。
简单来说:补技巧、修过时内容、分享协作经验,提 Issue 或 PR 都可以。
📚 延伸学习
本项目讲"怎么用好 9 款工具",要继续深入推荐看 延伸学习资源——精选了 20+ 个高质量 GitHub 仓库 / 博客 / 播客,按主题分类(Prompt 工程 / MCP 生态 / Claude Code 进阶 / Agent 工程 / 中文优秀资源 / 官方博客)。
🆕 更新日志
查看 CHANGELOG 了解项目重要更新。最近一次重大更新:2026-04 新增速查表、31 个深度陷阱合集、端到端实战脚本、画像推荐路径、20+ 外部学习资源。
致谢
本指南参考了以下优秀的开源项目:
- claude-code-best-practice — Claude Code 最佳实践
- awesome-cursorrules — Cursor 规则集合
- awesome-copilot — GitHub Copilot 官方资源
- gemini-cli-tips — Gemini CLI 技巧
- Everything Claude Code — 本能评分、AgentShield、多语言规则
- BMAD-METHOD — 完整 SDLC、Agent 角色、多平台
File: aider/README.en.md
简体中文 | English
Aider Best Practices
Aider is an open-source CLI AI coding tool. Its defining feature is being Git-native — every change is auto-committed, with built-in version control support. It works with virtually all major LLMs (Claude, GPT, DeepSeek, Qwen, local models), making it the most flexible AI coding CLI out there.
Core Concepts
| Concept | Description | Use Case |
|---|---|---|
| Chat Modes | code / ask / architect |
Different modes for different tasks |
| Auto Git Commits | Every change auto-committed | Roll back anytime |
| Map Mode | Auto-indexes project structure | Understand large codebases |
| Multi-Model Support | Claude/GPT/DeepSeek/Ollama etc. | Flexible selection, cost control |
| Lint & Test | Built-in code checking and testing | Auto-verify after changes |
Getting Started
Installation
pip install aider-chat
# Set an API key (pick one)
export ANTHROPIC_API_KEY=sk-xxx # Claude
export OPENAI_API_KEY=sk-xxx # GPT
export DEEPSEEK_API_KEY=sk-xxx # DeepSeekBasic Usage
cd /your/project
aider
# Specify a model
aider --model claude-sonnet-4-5
# Use DeepSeek (cheaper)
aider --model deepseek/deepseek-chat
# Use a local model (free)
aider --model ollama/qwen2.5-coderThree Chat Modes
# code mode (default) — directly edits code
/code Add a retry decorator to utils.py
# ask mode — read-only, no changes
/ask What's the time complexity of this function?
# architect mode — design first, implement later
/architect Design a task queue system. Give me the plan, don't write code yetPrompting Tips
1. Adding Files to Context
# Manually add files
/add src/models/user.py src/api/auth.py
# Add an entire directory
/add src/services/
# Remove files you don't need
/drop src/legacy/old_auth.pyAider only modifies files that have been added. This is how you precisely control scope.
2. Architect Mode for Large Tasks
/architect
I need to add a WebSocket real-time notification system to the project.
Requirements:
1. User online/offline notifications
2. Real-time new message push
3. Channel subscribe/unsubscribe support
4. Handle disconnect and reconnect
Give me a technical plan first, including:
- Which libraries to use
- Data flow design
- Which new files to create
- Which existing files to modify
Once confirmed, I'll switch to code mode to implement.3. Leverage Auto Git Commits
# Every change gets its own commit — roll back anytime
git log --oneline # View Aider's commit history
git diff HEAD~1 # See the last change
git revert HEAD # Not happy? One-command rollback
# Set a custom commit prefix
aider --commit-prefix "[ai] "4. Multi-Model Strategy
# Complex architecture design — use the strongest model
aider --model claude-sonnet-4-5
/architect Design a microservices split plan
# Daily coding — use a cost-effective model
aider --model deepseek/deepseek-chat
/code Implement user-service according to the plan
# Code review — use a free local model
aider --model ollama/qwen2.5-coder
/ask Any issues with this code?Advanced Tips
.aider.conf.yml — Project Configuration
# .aider.conf.yml
model: claude-sonnet-4-5
auto-commits: true
auto-lint: true
auto-test: true
test-cmd: pytest
lint-cmd: ruff checkLint + Test Automation
# After every change, automatically:
# 1. Run the linter
# 2. Run related tests
# 3. If either fails, auto-fix and retry
auto-lint: true
auto-test: true
lint-cmd: "ruff check --fix"
test-cmd: "pytest -x"Git Workflow Integration
# Work on a feature branch
git checkout -b feature/add-notifications
aider
# Every Aider change stays on this branch
# When done, follow your normal PR process
git push -u origin feature/add-notificationsHow It Differs from Other CLI Tools
| Dimension | Aider | Claude Code | Gemini CLI |
|---|---|---|---|
| Git integration | 3/3 (auto-commit) | 2/3 (manual) | 1/3 |
| Model flexibility | 3/3 (almost all LLMs) | 1/3 (Claude only) | 1/3 (Gemini only) |
| Agent capabilities | 2/3 | 3/3 | 2/3 |
| Context management | Manual /add /drop | Automatic | Automatic |
| Open source | Fully open source | No | Open source |
| Cost control | 3/3 (free models available) | 1/3 | 3/3 |
| Best for | Flexibility, saving money, Git power users | Complex Agent tasks | Large codebase analysis |
Common Pitfalls
| Pitfall | Description | Solution |
|---|---|---|
| Auto-commit swallows WIP | Auto-commit sweeps your unstaged changes into the commit | git stash before session, or use a dedicated branch |
/add misses deps |
Incomplete context, AI guesses from filenames | Have it /ask list dependencies first, then /add all of them |
| Model-switch quality drop | Cheaper model → cliff drop in output quality | Switch by task type; return to Claude for complex work |
| Lint loop burns tokens | auto-lint retries failing checks via LLM |
--max-reflections 3, use --fix linters |
👉 Deep dive: Aider Pitfalls — 7 real-world traps, each with Symptom / Cause / Recovery / Prevention
Configuration Templates
| Template | Purpose |
|---|---|
| .aider.conf.yml | Project config template (multi-model, lint, test config), copy to project root |
Further Reading
- Aider Official Docs
- Aider GitHub (42k+ stars)
- superpowers-zh — Skills methodology (also supports Aider)
File: aider/README.md
Aider 最佳实践
Aider 是一个开源的 CLI AI 编程工具,核心特色是 Git 原生 — 每次修改自动提交,天然支持版本控制。支持几乎所有主流 LLM(Claude、GPT、DeepSeek、Qwen、本地模型),是最灵活的 AI 编程 CLI。
核心概念
| 概念 | 说明 | 用途 |
|---|---|---|
| Chat 模式 | code / ask / architect |
不同任务用不同模式 |
| 自动 Git 提交 | 每次修改自动 commit | 随时可以回滚 |
| Map 模式 | 自动索引项目结构 | 理解大代码库 |
| 多模型支持 | Claude/GPT/DeepSeek/Ollama 等 | 灵活选择,控制成本 |
| Lint & Test | 内置代码检查和测试 | 修改后自动验证 |
快速上手
安装
pip install aider-chat
# 设置 API Key(选一个)
export ANTHROPIC_API_KEY=sk-xxx # Claude
export OPENAI_API_KEY=sk-xxx # GPT
export DEEPSEEK_API_KEY=sk-xxx # DeepSeek基本使用
cd /your/project
aider
# 指定模型
aider --model claude-sonnet-4-5
# 用 DeepSeek(便宜)
aider --model deepseek/deepseek-chat
# 用本地模型(免费)
aider --model ollama/qwen2.5-coder三种 Chat 模式
# code 模式(默认)— 直接修改代码
/code 给 utils.py 加一个 retry 装饰器
# ask 模式 — 只问不改
/ask 这个函数的时间复杂度是多少?
# architect 模式 — 先设计再实现
/architect 设计一个任务队列系统,先给方案不要写代码提示词技巧
1. 添加文件到上下文
# 手动添加文件
/add src/models/user.py src/api/auth.py
# 添加整个目录
/add src/services/
# 移除不需要的文件
/drop src/legacy/old_auth.pyAider 只会修改已添加的文件。这是精确控制范围的方式。
2. Architect 模式做大任务
/architect
我要给项目加一个 WebSocket 实时通知系统。
要求:
1. 用户上线/下线通知
2. 新消息实时推送
3. 支持频道订阅/退订
4. 需要考虑断线重连
先给出技术方案,包括:
- 用什么库
- 数据流设计
- 需要新建哪些文件
- 需要修改哪些现有文件
确认后切到 code 模式实现。3. 利用自动 Git 提交
# 每次修改都有独立 commit,随时回滚
git log --oneline # 看 Aider 的提交记录
git diff HEAD~1 # 看最后一次修改
git revert HEAD # 不满意?一键回滚
# 设置自定义提交前缀
aider --commit-prefix "[ai] "4. 多模型策略
# 复杂架构设计 — 用最强模型
aider --model claude-sonnet-4-5
/architect 设计微服务拆分方案
# 日常编码 — 用性价比模型
aider --model deepseek/deepseek-chat
/code 按方案实现 user-service
# 代码审查 — 用免费本地模型
aider --model ollama/qwen2.5-coder
/ask 看看这段代码有没有问题进阶技巧
.aider.conf.yml — 项目配置
# .aider.conf.yml
model: claude-sonnet-4-5
auto-commits: true
auto-lint: true
auto-test: true
test-cmd: pytest
lint-cmd: ruff checkLint + Test 自动化
# 每次修改后自动:
# 1. 跑 linter 检查
# 2. 跑相关测试
# 3. 如果失败,自动修复再重试
auto-lint: true
auto-test: true
lint-cmd: "ruff check --fix"
test-cmd: "pytest -x"与 Git 工作流集成
# 在 feature 分支上工作
git checkout -b feature/add-notifications
aider
# Aider 的每次修改都在这个分支上
# 完成后正常走 PR 流程
git push -u origin feature/add-notifications与其他 CLI 工具的区别
| 维度 | Aider | Claude Code | Gemini CLI |
|---|---|---|---|
| Git 集成 | ★★★(自动提交) | ★★☆(手动) | ★☆☆ |
| 模型灵活性 | ★★★(几乎所有 LLM) | ★☆☆(仅 Claude) | ★☆☆(仅 Gemini) |
| Agent 能力 | ★★☆ | ★★★ | ★★☆ |
| 上下文管理 | 手动 /add /drop | 自动 | 自动 |
| 开源 | ✅ 完全开源 | ❌ | ✅ 开源 |
| 成本控制 | ★★★(可用免费模型) | ★☆☆ | ★★★ |
| 适合 | 灵活、省钱、Git 重度用户 | 复杂 Agent 任务 | 大代码库分析 |
常见陷阱
| 陷阱 | 说明 | 解决 |
|---|---|---|
| auto-commit 吃变更 | 自动提交把你未 stage 的工作一起吞了 | 会话前 git stash,或开独立分支 |
| /add 漏依赖 | 上下文不全,AI 靠文件名脑补 | 让它先 /ask 列出所有依赖再 /add |
| 模型切换质量塌 | 切到便宜模型后产出质量断崖下跌 | 分任务类型切,复杂任务回 Claude |
| lint 循环烧 token | auto-lint 失败反复让 LLM 修 | --max-reflections 3,lint 用 --fix 模式 |
👉 深度展开版:Aider 陷阱合集 — 7 个真实踩坑场景,每个带症状 / 根因 / 出坑 / 预防
配置模板
| 模板 | 用途 |
|---|---|
| .aider.conf.yml | 项目配置模板(含多模型、lint、test 配置),复制到项目根目录 |
延伸阅读
- Aider 官方文档
- Aider GitHub(42k+ star)
- superpowers-zh — Skills 方法论(也支持 Aider)
File: book/README.md
book/ — AI 编程实战三卷书脚手架
把 ai-coding-guide 仓库的现成内容重组成 3 卷 + 1 别册 的渐进式读本。
用 mdBook 编译成静态 HTML 网站 + PDF。
结构
book/
├── README.md ← 你正在看
├── book.toml ← mdbook 配置
├── .gitignore ← 忽略 book/book/ 输出目录
└── src/
├── SUMMARY.md ← 主目录(决定章节顺序)
├── intro.md ← 总序
├── v1-intro.md ← 卷一·入门 序
├── v2-intro.md ← 卷二·工作流 序
├── v3-intro.md ← 卷三·架构 序
├── about.md ← 关于本书
│
├── cheatsheet.md ← 软链 → ../../cheatsheet.md
├── changelog.md ← 软链 → ../../CHANGELOG.md
├── resources.md ← 软链 → ../../resources.md
├── methods/ ← 软链 → ../../common/ (7 套方法论)
├── workflows-src/ ← 软链 → ../../workflows/ (协作 + 场景)
├── pitfalls-src/ ← 软链 → ../../pitfalls/ (踩坑合集)
└── tools/
├── claude-code/ ← 软链 → ../../../claude-code/
├── codex/ ← 软链 → ../../../codex/
├── cursor/ ← 软链 → ../../../cursor/
└── ...(10 工具全部)关键设计:所有内容都是 symlink 而不是复制。仓库主目录改了,重新 mdbook build 立刻同步。零内容重复维护。
怎么本地预览
# 一次性装 mdbook
brew install mdbook
# 或 cargo install mdbook
# 预览(实时热更新,浏览器自动打开)
cd book
mdbook serve --open
# 编译成静态 HTML(输出在 book/book/)
mdbook build怎么发布
选项 1:GitHub Pages ⭐ 已配置
CI 已经接好——.github/workflows/book.yml 在每次 push 到 main 时自动 build 并 deploy。
只需在仓库 Settings 里开 Pages 一次。完整步骤 + 自定义域名教程见 DEPLOY.md。
默认 URL:https://aibuzhiyu.com/
选项 2:Netlify / Vercel(PR preview 友好)
仓库根目录加 netlify.toml:
[build]
command = "cd book && mdbook build"
publish = "book/book"
[build.environment]
RUST_VERSION = "1.78"netlify 会自动装 mdbook(用 cargo install mdbook build 命令前面手动加一下)。
选项 3:Leanpub / GitBook 商业版
如果想出电子书赚钱:mdbook build 出 HTML 之后,用 pandoc 转成 epub / mobi / PDF:
mdbook build
cd book/book
# 把所有 HTML 串起来转 PDF
pandoc -o ../../ai-coding-guide.pdf $(find . -name "*.html" | sort) \
--pdf-engine=xelatex \
-V mainfont="PingFang SC" -V CJKmainfont="PingFang SC"节奏
这是 v0.1 脚手架——目录结构、3 卷序、symlink 就位,可以 build 出能看的版本了,但内容主要靠的是仓库里既有的章节。后续要加的:
- 各卷之间的"过渡章"(卷一末→卷二首的承上启下)
- 卷三的「CI 集成 / 团队治理」实战章节(仓库里还没有,需要新写)
- 端到端项目案例("用 Claude Code + Codex CLI 做完一个真实小项目")
- 出版用的封面 / ISBN / 版式(如果要走出版社)
- PDF 导出脚本调优(中文字体 / 代码块换行)
每一项都可以独立 PR 进来。
License
CC BY-NC-SA 4.0 — 个人免费 / 禁商业 / 派生开源。详见 LICENSE 或 中文友好版。
与主仓库 Apache-2.0 是双 license 关系:
book/目录下用 CC,其他都是 Apache。
上游
GitHub: jnMetaCode/ai-coding-guide
File: claude-code/README.en.md
简体中文 | English
Claude Code Best Practices
Claude Code is Anthropic's official CLI AI coding tool. It's not just a code completion tool — it's an Agent that understands your entire project and executes complex tasks autonomously.
Core Concepts
Before diving into tips, get familiar with these core concepts:
| Concept | Description | Use Case |
|---|---|---|
| Subagent | Child process Agent, executes tasks independently | Parallel processing, context isolation |
| Command | Shortcuts starting with / |
Quick access to common operations |
| Skill | Methodology files under .claude/skills/ |
Teach the AI how to do things |
| Hook | Scripts that run before/after tool calls | Automated validation, notifications |
| MCP Server | Model Context Protocol service | Extend AI capabilities (databases, APIs, etc.) |
| Memory | Persistent memory | Retain context across conversations |
| Checkpoint | Auto-saved snapshots | Safe rollback |
Getting Started
Installation
# Install globally via npm
npm install @anthropic-ai/claude-code
# Or run directly with npx
npx @anthropic-ai/claude-codeFirst Run
cd /your/project
claudeOnce in interactive mode, try these:
# Understand the project
> What does this project do? Walk me through the architecture.
# Small task
> Add a truncate function to utils/string.ts that cuts strings at a given length and appends an ellipsis.
# Big task (just describe it — Claude Code plans and executes automatically)
> Refactor all endpoints under src/api/ to use a unified error handling format.CLAUDE.md — Project Configuration File
Create a CLAUDE.md in your project root. Claude Code reads it on every startup:
# Project Overview
This is an e-commerce admin dashboard built with Next.js 14 + TypeScript.
# Code Conventions
- Use TypeScript strict mode
- Components use PascalCase
- API routes go under src/app/api/
- Tests use Vitest, placed in __tests__/
# Common Commands
- Dev server: pnpm dev
- Run tests: pnpm test
- Type check: pnpm typecheck
- Lint: pnpm lint
# Important Notes
- Do NOT modify anything under src/legacy/ — it's a compatibility layer for the old version
- Database migrations must be generated via drizzle-kit — never write raw SQLPrompting Tips
1. Provide Full Context in One Go
❌ Bad: Add a login feature.
✅ Good: Add a JWT login endpoint under src/app/api/. Use bcrypt for password
verification, set token expiry to 7 days, and return errors in a unified
{ code, message } format. Follow the style of src/app/api/register/route.ts.2. Point to Reference Files
Follow the style of src/components/UserTable.tsx.
Create a new src/components/OrderTable.tsx with
pagination, sorting, and search using TanStack Table.3. Analyze First, Act Second
Read src/services/payment.ts and src/services/order.ts first.
Analyze the current payment flow for issues,
propose improvements, and wait for my confirmation before making changes.4. Limit the Scope
Only modify src/utils/date.ts.
Don't touch other files. Don't add new dependencies.5. Draw Red Lines with Negatives
Implement a caching layer.
Don't use Redis — use in-memory caching.
Don't add new dependencies — use a plain Map.
Don't change any existing function signatures.Advanced Techniques
Agent Capabilities
Claude Code is an Agent by design — describe the task and it plans and executes autonomously:
> Add unit tests to the entire project, targeting 80% coverage.Claude Code will: read code → make a plan → write tests → run tests → fix failures → verify passing.
Tip: No special commands or flags needed. Just describe the desired outcome. Claude Code decides on its own whether multi-step execution is necessary.
Subagent Parallelism
Split large tasks across multiple Subagents running in parallel:
Do these three things in parallel:
1. Add pagination parameters to src/api/users.ts
2. Add date filtering to src/api/orders.ts
3. Add search to src/api/products.ts
Use subagents to execute each one independently.Skill Files
Skills are one of the most powerful features. Place methodology files under .claude/skills/ and the AI loads them automatically:
.claude/skills/
├── brainstorming.md # Requirements analysis workflow
├── debugging.md # Debugging methodology
├── code-review.md # Code review standards
└── verification.md # Pre-completion verificationQuick-install superpowers-zh (20 battle-tested skills):
cd /your/project
npx superpowers-zh
# Auto-detects project type, installs to .claude/skills/
# Also supports Cursor, Gemini CLI, etc.After installation, Claude Code loads these skills automatically. Invoke them with / commands — e.g., /brainstorming for requirements analysis, /debugging for systematic debugging. See superpowers-zh.
Need specialized roles? Use the 211 AI expert personas from agency-agents-zh:
# Copy role files to .claude/skills/ to use them
# Examples: database optimizer, security engineer, code reviewer, etc.Reference roles in CLAUDE.md:
# Roles
When I say "review as a security expert", act according to .claude/skills/security-engineer.md.Hook Automation
Hooks run scripts automatically before or after tool calls:
// .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "echo 'About to run a command'" }
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{ "type": "command", "command": "pnpm lint --fix" }
]
}
]
}
}Hook trigger points include
PreToolUse,PostToolUse,Notification, etc. Each trigger usesmatcherto match tool names. See the official docs.
Use cases:
- Auto-run related tests after every file edit
- Auto-lint before every commit
- Auto-add copyright headers to new files
Git Worktree Isolation
Use worktrees for experimental changes without affecting the main branch:
Do this refactor in a git worktree.
If the result is good, merge it. If not, discard it.Memory Across Conversations
Claude Code stores memory under ~/.claude/ for cross-conversation use:
Remember: this project deploys on Vercel,
CI uses GitHub Actions, and the database is Supabase PostgreSQL.
Factor these in for all deployment-related tasks going forward.Multi-Agent Orchestration
When tasks are complex enough to need multiple AI roles collaborating (e.g., architect designs → developer implements → reviewer audits), use agency-orchestrator for YAML-based orchestration:
# workflow.yaml
name: New Feature Development
steps:
- agent: Software Architect
task: Analyze requirements, produce technical design
output: design.md
- agent: Backend Developer
task: Implement code per design.md
input: design.md
- agent: Code Reviewer
task: Review code quality and securityBest for: team-scale complex tasks, deliverables requiring multiple review rounds, standardized development workflows.
Debugging Tips
1. Let It Read Logs — Don't Let It Guess
❌ Bad: Tests are failing, fix them.
✅ Good: Run pnpm test src/api/users.test.ts,
show me the failure output, analyze the root cause, then fix.2. Narrow the Scope
Look only at lines 45-80 of src/services/auth.ts.
A user reports "token still shows expired after refresh".
Analyze possible causes first — don't change anything yet.3. Diff Analysis
Check git log for recent changes to src/api/payment.ts.
Compare logic before and after to find which commit introduced this bug.Tips Cheat Sheet (60+)
Organized by category, one tip per row. Bookmark this section — it's all you need.
Prompting (12)
| # | Tip | Details |
|---|---|---|
| 1 | Analyze before acting | Have Claude read the code and propose a plan. Confirm before it makes changes. Prevents premature rewrites |
| 2 | Start over | Not happy? Say "Scrap this approach. Use what you've learned to design an elegant solution from scratch" |
| 3 | Quiz me | "Review this change and ask me questions until you're confident I understand it, then open the PR" |
| 4 | Limit scope | "Only modify this one file. Don't touch anything else. Don't add new dependencies" |
| 5 | Specify reference files | "Follow the style of src/api/users.ts when writing orders.ts" — 10x better than a vague description |
| 6 | Draw red lines with negatives | "Don't use Redis. Don't add new dependencies. Don't change function signatures" |
| 7 | Ask for 2-3 options | "Give me 2 options with pros and cons. I'll pick one, then you implement it" |
| 8 | Confirm step by step | "Pause after each step and wait for my confirmation. Don't do everything at once" |
| 9 | Define done criteria | "Definition of done: all tests pass + zero TypeScript errors + lint passes" |
| 10 | Use ultrathink for deep reasoning | Start your prompt with "ultrathink" or "think really hard" to trigger extended thinking |
| 11 | Let it write commit messages | "Write a commit message that explains why this change was made, not what changed" |
| 12 | English prompts are more precise | For complex technical tasks, English prompts yield more precise results. Use your native language for simple tasks |
CLAUDE.md (10)
| # | Tip | Details |
|---|---|---|
| 1 | Keep it under 200 lines | Too long and the AI ignores the bottom. For large projects, split into .claude/rules/ |
| 2 | The "run tests" test | If anyone opens Claude Code and says "run tests" and it succeeds, your CLAUDE.md is good enough |
| 3 | Use settings.json over "don't" | "Don't modify file X" in CLAUDE.md gets ignored easily. Permission controls in settings.json are more reliable |
| 4 | Use `` tags | Wrap critical rules in `` tags — the model pays more attention to them |
| 5 | List common commands | Include dev, test, build, lint, and deploy commands so the AI doesn't have to guess |
| 6 | List prohibitions | Explicitly state which files are off-limits, which methods are banned, which dependencies must not be added |
| 7 | Document directory structure | Describe key directories so the AI knows where things live |
| 8 | Layer your CLAUDE.md files | Global rules in the root, module-specific rules in subdirectories (e.g., src/api/CLAUDE.md) |
| 9 | Update regularly | As the project evolves, keep CLAUDE.md current. Stale rules are worse than no rules |
| 10 | Use .claude/rules/ for conditional loading |
In large projects, use globs to load rules by file type instead of cramming everything in one file |
Agent & Subagent (10)
| # | Tip | Details |
|---|---|---|
| 1 | Split subagents by feature | Create a "payment module agent" — not a generic "backend engineer" |
| 2 | Adversarial testing | One agent writes code, another (with independent context) hunts for bugs |
| 3 | Write skill descriptions for the model | Write "trigger when the user wants to do X" — not a human-friendly summary |
| 4 | Add gotchas to skills | Record mistakes Claude has made inside skill files. Highest signal-to-noise content you can write |
| 5 | context: fork for isolation |
Run a skill in an isolated subagent; the main context only sees the final result |
| 6 | One agent, one clear task | A single agent with one task succeeds far more often than one agent juggling five |
| 7 | Pass files between agents, not messages | Have agent A write output to a file; agent B reads the file. More reliable than verbal handoffs |
| 8 | Use worktrees for experiments | Run subagents in git worktrees for experimental changes. Discard if unhappy |
| 9 | Extend capabilities with MCP | Connect databases, call APIs, query docs — MCP makes agents 10x more capable |
| 10 | Custom commands for repetitive tasks | Wrap frequent operations into /command shortcuts for one-click execution |
Hooks (8)
| # | Tip | Details |
|---|---|---|
| 1 | PostToolUse auto-format | Auto-run prettier/eslint --fix after Claude writes code to prevent formatting issues |
| 2 | PostToolUse auto-test | Auto-run related tests after every file modification to catch issues early |
| 3 | PreToolUse block dangerous ops | Check commands before Bash tool execution; block rm -rf and similar |
| 4 | Notification hook for alerts | Auto-send Slack/webhook notifications when long tasks complete |
| 5 | Stop hook for forced verification | Remind Claude to verify its own output at the end of each turn |
| 6 | Exit 1 in hooks to block execution | A non-zero exit from a hook script blocks the tool call — use this to enforce rules |
| 7 | Hook stdout as context | Claude sees the hook's stdout, so you can pass extra information through it |
| 8 | Match tool names precisely | Matcher supports Write|Edit, Bash, etc. Don't use * to match everything |
Workflow (12)
| # | Tip | Details |
|---|---|---|
| 1 | Manually /compact at 50% context |
Don't wait for auto-compaction. Proactive compaction keeps AI quality high |
| 2 | Esc Esc to revert to checkpoint | Gone off track? Roll back via checkpoint instead of trying to fix in a polluted context |
| 3 | Keep PRs small and focused | Aim for a median of ~120 lines per PR. Split large changes into multiple PRs |
| 4 | Finish migrations before new features | A half-migrated codebase makes the AI pick wrong patterns. Keep the codebase clean |
| 5 | New conversation for new tasks | Start fresh for each independent task. Stale context from old conversations degrades quality |
| 6 | Start with plan mode | For complex tasks, enter plan mode (/plan) first. Confirm the plan, then execute |
| 7 | Fast iterations > one perfect shot | Ship an MVP, verify it works, then refine. Don't expect perfection from a single prompt |
| 8 | Let Claude run tests itself | Don't run them for it. Let it run, read output, and fix. That's an agent's sweet spot |
| 9 | Use --resume to continue |
Interrupted? Use claude --resume to restore context and keep going |
| 10 | Use --print for non-interactive tasks |
In CI/CD: claude --print "check code style" for automation |
| 11 | Headless mode for batch tasks | claude -p "task" --output-format json is ideal for scripted invocations |
| 12 | Parallel worktrees for throughput | Run multiple Claude instances in separate worktrees to process modules in parallel |
Git & PRs (8)
| # | Tip | Details |
|---|---|---|
| 1 | Let Claude write PR descriptions | "Read the git diff and write a PR description explaining what changed and why" |
| 2 | Squash merge for clean history | AI's intermediate commits are noisy. Squash to keep only the final result |
| 3 | Isolate with feature branches | One branch per task. Claude's changes never touch main directly |
| 4 | Use Claude for code review | "Read this PR's diff and review it for security, performance, and maintainability" |
| 5 | Self-check before committing | "Pre-commit check: any leftover console.log, TODO, or hardcoded values?" |
| 6 | Don't amend the previous commit | Claude sometimes uses --amend and overwrites your prior commit. Explicitly say "create a new commit" |
| 7 | Use git stash to protect your work | Have Claude git stash before making changes. Unhappy? git stash pop to restore |
| 8 | Let Claude resolve merge conflicts | "Look at the conflicting files, resolve by business logic, and preserve valid changes from both sides" |
Debugging (10)
| # | Tip | Details |
|---|---|---|
| 1 | Let it run commands and read output | "Run pnpm test and show me the failure output" is 10x better than "tests are broken, fix them" |
| 2 | Narrow scope before asking | "Look only at auth.ts lines 45-80" beats "this module has a bug" |
| 3 | Use git log to compare | "Check recent changes, compare before and after, find which commit introduced the bug" |
| 4 | Reproduce before fixing | "Write a test case that reproduces this bug first, then fix it and confirm the test goes from red to green" |
| 5 | Binary search with bisect | "Use git bisect to find the commit that introduced this bug" |
| 6 | Read logs, don't guess | "Check the last 50 lines of logs/error.log and analyze the error" |
| 7 | Add temporary logging | "Add console.log at key points to print variable values, run once, and review the output" |
| 8 | Compare working vs. broken | "User A works fine, user B doesn't. Compare the two requests for differences" |
| 9 | Check environment differences | "Works locally but not in production? Compare env vars, dependency versions, and Node version" |
| 10 | Don't fix blindly | "Give me 3 possible causes with investigation steps. I'll confirm before you change any code" |
Cost & Performance (6)
| # | Tip | Details |
|---|---|---|
| 1 | Use Haiku for simple tasks | claude --model haiku for straightforward work — 10x cheaper |
| 2 | Use headless mode for batch jobs | Scripted batch calls consume fewer tokens than interactive mode |
| 3 | A precise CLAUDE.md saves tokens | The more precise your context, the fewer files the AI needs to read, and the lower the cost |
| 4 | Avoid repeatedly reading large files | Tell Claude the exact line range instead of having it read the entire file every time |
| 5 | Use /compact to free context |
Compress long conversations promptly to reduce per-turn token consumption |
| 6 | Monitor usage | Check API usage regularly and set budget caps to avoid overspending |
For more tips, see claude-code-best-practice.
Common Pitfalls
| Pitfall | Description | Solution |
|---|---|---|
| Context overflow | Conversations get too long, AI gets worse | Start new conversations regularly; pass context via CLAUDE.md |
| Hallucinated APIs | AI invents APIs that don't exist | Have it check docs or grep to confirm first |
| Over-refactoring | You asked to fix a bug, it rewrites the whole file | Explicitly say "only fix this one thing, don't refactor" |
| Tests not run | AI says "done" without verifying | Use a verification skill or hook to force validation |
| Missing error handling | Quick implementation with no edge case handling | Explicitly require error handling in your prompt |
👉 Deep dive: Claude Code Pitfalls — 8 real-world traps, each with Symptom / Cause / Recovery / Prevention
Configuration Templates
Copy these directly into your project:
| Template | Purpose |
|---|---|
| CLAUDE.md | Project configuration file template — copy to project root and customize |
| settings.json | Permission configuration template — copy to .claude/settings.json |
Further Reading
- Claude Code Official Docs
- superpowers-zh — 20 AI coding skills
- agency-agents-zh — 211 AI expert personas
File: claude-code/README.md
Claude Code 最佳实践
Claude Code 是 Anthropic 官方的 CLI AI 编程工具。它不只是一个代码补全工具,而是一个能理解整个项目、执行复杂任务的 Agent。
核心概念
在深入技巧之前,先搞清楚 Claude Code 的几个核心概念:
| 概念 | 说明 | 用途 |
|---|---|---|
| Subagent | 子进程 Agent,独立执行任务 | 并行处理、隔离上下文 |
| Command | / 开头的快捷命令 |
快速执行常用操作 |
| Skill | .claude/skills/ 下的方法论文件 |
教 AI 怎么做事 |
| Hook | 工具调用前后的钩子脚本 | 自动化校验、通知 |
| MCP Server | Model Context Protocol 服务 | 扩展 AI 能力(数据库、API 等) |
| Memory | 持久化记忆 | 跨对话保留上下文 |
| Checkpoint | 自动保存点 | 安全回滚 |
快速上手
安装
# npm 全局安装
npm install @anthropic-ai/claude-code
# 或者直接用 npx
npx @anthropic-ai/claude-code第一次使用
cd /your/project
claude进入交互模式后,试试这几个命令:
# 了解项目
> 这个项目是做什么的?帮我梳理一下架构
# 做一个小任务
> 给 utils/string.ts 加一个 truncate 函数,超过指定长度截断并加省略号
# 做大任务(直接描述,Claude Code 会自动规划执行)
> 重构 src/api/ 下所有接口,统一错误处理格式CLAUDE.md — 项目配置文件
在项目根目录创建 CLAUDE.md,Claude Code 每次启动都会读取:
# 项目说明
这是一个 Next.js 14 + TypeScript 的电商后台管理系统。
# 代码规范
- 使用 TypeScript strict mode
- 组件用 PascalCase 命名
- API 路由放在 src/app/api/ 下
- 测试用 Vitest,放在 __tests__/ 下
# 常用命令
- 启动开发:pnpm dev
- 跑测试:pnpm test
- 类型检查:pnpm typecheck
- Lint:pnpm lint
# 注意事项
- 不要修改 src/legacy/ 下的代码,那是旧版本兼容层
- 数据库 migration 必须通过 drizzle-kit 生成,不要手写 SQL提示词技巧
1. 给足上下文,一次说清楚
❌ 差:加个登录功能
✅ 好:给 src/app/api/ 加一个 JWT 登录接口。用 bcrypt 验证密码,
token 过期时间 7 天,错误返回统一的 { code, message } 格式。
参考 src/app/api/register/route.ts 的风格。2. 指定参考文件
参考 src/components/UserTable.tsx 的风格,
给 src/components/ 新建一个 OrderTable.tsx,
支持分页、排序、搜索,用 TanStack Table。3. 先让它分析,再让它动手
先读 src/services/payment.ts 和 src/services/order.ts,
分析一下现在的支付流程有什么问题,
给出改进方案,确认后再改。4. 限制范围
只改 src/utils/date.ts 这一个文件。
不要动其他文件,不要加新依赖。5. 用否定句划红线
实现缓存功能。
不要用 Redis,用内存缓存。
不要引入新依赖,用 Map 实现。
不要修改现有接口的签名。进阶技巧
Agent 能力
Claude Code 本身就是 Agent——直接描述任务,它会自主规划和执行:
> 给整个项目加上单元测试,覆盖率目标 80%Claude Code 会自己:读代码 → 制定计划 → 写测试 → 跑测试 → 修复失败 → 验证通过
提示:不需要特殊命令或 flag。直接描述你想要的结果,Claude Code 会自动决定是否需要多步骤执行。
Subagent 并行
大任务可以拆成多个 Subagent 并行执行:
同时做这三件事:
1. 给 src/api/users.ts 加分页参数
2. 给 src/api/orders.ts 加日期筛选
3. 给 src/api/products.ts 加搜索功能
用 subagent 并行执行,每个独立完成。Skill 文件
Skill 是最强大的功能之一。在 .claude/skills/ 下放方法论文件,AI 会自动加载:
.claude/skills/
├── brainstorming.md # 需求分析流程
├── debugging.md # 调试方法论
├── code-review.md # 代码审查规范
└── verification.md # 完成前验证快速安装 superpowers-zh(20 个经过实战验证的 skill):
cd /your/project
npx superpowers-zh
# 自动检测项目类型,安装到 .claude/skills/
# 也支持 Cursor、Gemini CLI 等工具安装后 Claude Code 会自动加载这些 skill,你可以用 / 命令调用,比如 /brainstorming 做需求分析、/debugging 做系统化调试。详见 superpowers-zh。
需要专业角色? 用 agency-agents-zh 的 211 个 AI 专家角色:
# 把角色文件复制到 .claude/skills/ 即可使用
# 比如数据库优化师、安全工程师、代码审查员等在 CLAUDE.md 里引用角色:
# 角色
当我说"用安全专家审查"时,按 .claude/skills/security-engineer.md 的角色行事。Hook 自动化
Hook 在工具调用前后自动执行脚本:
// .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "echo 'About to run a command'" }
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{ "type": "command", "command": "pnpm lint --fix" }
]
}
]
}
}Hook 的触发点有
PreToolUse、PostToolUse、Notification等,每个触发点下用matcher匹配工具名。详见 官方文档。
用途:
- 每次修改文件后自动跑相关测试
- 每次提交前自动 lint
- 每次创建文件后自动加版权头
Git Worktree 隔离开发
做实验性改动时,用 worktree 隔离,不影响主分支:
在 git worktree 里做这个重构。
如果效果好就合并,不好就丢弃。Memory 跨对话记忆
Claude Code 可以在 ~/.claude/ 下存储记忆,跨对话使用:
记住:这个项目的部署用的是 Vercel,
CI 用 GitHub Actions,数据库是 Supabase PostgreSQL。
以后做部署相关的任务都要考虑这些。多智能体编排
当任务复杂到需要多个 AI 角色协作时(比如架构师设计 → 开发者实现 → 审查员审查),可以用 agency-orchestrator 做 YAML 编排:
# workflow.yaml
name: 新功能开发
steps:
- agent: 软件架构师
task: 分析需求,输出技术方案
output: design.md
- agent: 后端开发者
task: 按 design.md 实现代码
input: design.md
- agent: 代码审查员
task: 审查代码质量和安全性适合场景:团队级复杂任务、需要多轮审查的交付、标准化开发流程。
调试技巧
1. 让它看日志,不要让它猜
❌ 差:测试挂了,帮我修
✅ 好:跑 pnpm test src/api/users.test.ts,
把失败的测试输出贴出来,分析根因后再修。2. 缩小范围
只看 src/services/auth.ts 第 45-80 行的逻辑,
用户反馈说"刷新 token 后还是提示过期"。
先分析可能的原因,不要直接改。3. 对比分析
git log 看看 src/api/payment.ts 最近的改动,
对比改动前后的逻辑,找出哪次改动引入了这个 bug。技巧速查表(60+)
按场景分类,一行一个技巧。收藏这一页就够了。
提示词(12)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | 先分析再动手 | 让 Claude 先读代码、给方案,确认后再改。避免一上来就重写 |
| 2 | 推翻重来 | 不满意?说"扔掉这个方案,用你现在了解到的信息重新设计一个优雅的实现" |
| 3 | 考考我 | "帮我审查这个改动,问我问题,直到你确认我理解了再提 PR" |
| 4 | 限定范围 | "只改这一个文件,不要动其他文件,不要加新依赖" |
| 5 | 指定参考文件 | "参考 src/api/users.ts 的风格写 orders.ts",比空描述好 10 倍 |
| 6 | 用否定句划红线 | "不要用 Redis,不要引入新依赖,不要改接口签名" |
| 7 | 给出 2-3 个方案让我选 | "给出 2 个方案,分析优缺点,我选了再做" |
| 8 | 分步确认 | "每步做完暂停等我确认,不要一口气做完" |
| 9 | 明确完成标准 | "完成标准:所有测试通过 + TypeScript 无报错 + lint 通过" |
| 10 | 用 ultrathink 深度思考 | 在提示词开头加"ultrathink"或"think really hard"触发扩展思考 |
| 11 | 让它写 commit message | "帮我写 commit message,描述这次改动的 why 而不是 what" |
| 12 | 英文提示词更精确 | 复杂技术任务用英文描述更精确,简单任务中文即可 |
CLAUDE.md(10)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | 控制在 200 行以内 | 太长 AI 会忽略后面的内容。大项目拆到 .claude/rules/ |
| 2 | "跑测试"测试法 | 任何人打开 Claude Code 说"跑测试"就能成功 → CLAUDE.md 写够了 |
| 3 | settings.json 代替"不要" | "不要修改 x 文件"写在 CLAUDE.md 容易被忽略,权限控制更可靠 |
| 4 | 加 `` 标签 | 关键规则用 `` 包裹,模型会更重视 |
| 5 | 写常用命令 | dev、test、build、lint、deploy 命令都写上,AI 不用猜 |
| 6 | 写禁止事项 | 明确列出不能动的文件、不能用的方法、不能引入的依赖 |
| 7 | 写目录结构 | 关键目录说明,让 AI 知道代码在哪里 |
| 8 | 分层 CLAUDE.md | 根目录放全局规则,子目录放模块规则(如 src/api/CLAUDE.md) |
| 9 | 定期更新 | 项目演进了 CLAUDE.md 也要跟着更新,过时的规则比没有规则更糟 |
| 10 | 用 .claude/rules/ 按条件加载 |
大项目用 globs 按文件类型加载规则,避免一次全塞进去 |
Agent 与 Subagent(10)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | 按功能拆 subagent | 创建"支付模块专用 agent"而不是泛泛的"后端工程师" |
| 2 | 对抗式测试 | 一个 agent 写代码,另一个(独立上下文)找 bug |
| 3 | Skill description 写给模型看 | 写"当用户要做 X 时触发"而不是人类摘要 |
| 4 | Skill 里加 gotchas | 把 Claude 犯过的错记在 skill 里,最高信噪比的内容 |
| 5 | context: fork 隔离 |
Skill 在独立 subagent 跑,主上下文只看最终结果 |
| 6 | 不要让 agent 做太多事 | 一个 agent 一个明确任务,比一个 agent 做 5 件事成功率高 |
| 7 | agent 之间传文件而不是传消息 | 让 agent A 的输出写到文件,agent B 读文件。比口头传递可靠 |
| 8 | 用 worktree 做实验 | 让 subagent 在 git worktree 里做实验性改动,不满意就丢弃 |
| 9 | 用 MCP 扩展能力 | 连数据库、调 API、查文档 — MCP 让 agent 能做的事多 10 倍 |
| 10 | Custom command 做常用操作 | 把重复性高的操作封装成 /command,一键触发 |
Hook(8)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | PostToolUse 自动格式化 | Claude 写代码后自动跑 prettier/eslint --fix,避免格式问题 |
| 2 | PostToolUse 自动跑测试 | 每次修改文件后自动跑相关测试,及时发现问题 |
| 3 | PreToolUse 拦截危险操作 | 在 Bash 工具执行前检查命令,拦截 rm -rf 等危险操作 |
| 4 | Notification hook 发通知 | 长任务完成后自动发 Slack/钉钉通知 |
| 5 | Stop hook 强制验证 | 在每轮结束时提醒 Claude 检查自己的输出 |
| 6 | hook 里用 exit 1 阻止执行 | hook 脚本返回非 0 就会阻止工具调用,用于强制规则 |
| 7 | hook 输出作为上下文 | hook 的 stdout 会被 Claude 看到,可以传递额外信息 |
| 8 | 按工具名精确匹配 | matcher 支持 Write|Edit、Bash 等,不要用 * 匹配所有 |
工作流(12)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | 上下文 50% 时手动 /compact |
不要等自动压缩,主动压缩能保持 AI 质量 |
| 2 | Esc Esc 回退 checkpoint | 跑偏了用 checkpoint 回滚,不要在错误的上下文里继续修 |
| 3 | PR 保持小而聚焦 | 理想 PR 中位数约 120 行。大改动拆成多个 PR |
| 4 | 先合并迁移再做新功能 | 半迁移的代码库让 AI 选错模式。保持代码库干净 |
| 5 | 新对话做新任务 | 每个独立任务开新对话。旧对话的上下文污染会降低质量 |
| 6 | 用 plan mode 开始 | 复杂任务先进 plan mode(/plan),确认方案后再执行 |
| 7 | 多次快速迭代 > 一次完美 | 先出 MVP,跑通后再优化。不要一次提示就期望完美 |
| 8 | 让 Claude 自己跑测试 | 不要替它跑,让它自己跑、看输出、修复。这是 agent 的强项 |
| 9 | 用 --resume 继续上次对话 |
中断后用 claude --resume 恢复上下文继续工作 |
| 10 | 用 --print 做非交互任务 |
CI/CD 里用 claude --print "检查代码风格" 做自动化 |
| 11 | headless 模式跑批量任务 | claude -p "任务" --output-format json 适合脚本调用 |
| 12 | 并行 worktree 提效 | 多个 worktree 跑多个 Claude 实例,并行处理不同模块 |
Git 与 PR(8)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | 让 Claude 写 PR 描述 | "读 git diff,写 PR 描述,说清楚改了什么、为什么改" |
| 2 | squash merge 保持历史干净 | AI 的中间 commit 很乱,squash 后只保留最终结果 |
| 3 | feature 分支隔离 | 每个任务一个分支,Claude 的改动不影响 main |
| 4 | 用 Claude 做 code review | "读这个 PR 的 diff,按安全性、性能、可维护性三个维度审查" |
| 5 | commit 前让它自查 | "提交前检查:有没有遗留的 console.log、TODO、硬编码?" |
| 6 | 不要 amend 上一个 commit | Claude 有时会 --amend 覆盖你之前的提交,明确说"新建 commit" |
| 7 | 用 git stash 保护现场 | 让 Claude 改东西前先 git stash,不满意就 git stash pop 恢复 |
| 8 | 让 Claude 解决合并冲突 | "看看冲突文件,按业务逻辑解决冲突,保留两边的有效改动" |
调试(10)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | 让它跑命令看输出 | "跑 pnpm test 把失败的输出贴出来分析"比"测试挂了帮我修"好 10 倍 |
| 2 | 缩小范围再开问 | "只看 auth.ts 第 45-80 行"比"这个模块有 bug"好 |
| 3 | 用 git log 对比 | "看最近改动,对比改动前后,找哪次引入了 bug" |
| 4 | 先复现再修复 | "先写一个能复现这个 bug 的测试用例,再修复,确保测试从红变绿" |
| 5 | 二分法定位 | "用 git bisect 找到引入 bug 的 commit" |
| 6 | 看日志不要猜 | "查看 logs/error.log 最近 50 行,分析报错原因" |
| 7 | 加临时日志 | "在关键路径加 console.log 打印变量值,跑一次看输出" |
| 8 | 对比正常和异常 | "用户 A 正常、用户 B 异常,对比两个请求的差异" |
| 9 | 检查环境差异 | "本地能跑线上不行?对比环境变量、依赖版本、Node 版本" |
| 10 | 不要盲目修复 | "先给出 3 个可能的原因和排查方法,我确认后再改代码" |
性能与成本(6)
| # | 技巧 | 说明 |
|---|---|---|
| 1 | 简单任务用 haiku | claude --model haiku 做简单任务,便宜 10 倍 |
| 2 | 批量任务用 headless | 脚本批量调用比交互模式省 token |
| 3 | 精准的 CLAUDE.md 省 token | 上下文越精准,AI 需要读的文件越少,成本越低 |
| 4 | 避免反复读大文件 | 告诉 Claude 具体行号范围,不要每次都读整个文件 |
| 5 | 用 /compact 释放上下文 |
长对话及时压缩,减少每轮的 token 消耗 |
| 6 | 监控用量 | 定期检查 API 用量,设置预算上限避免超支 |
更多技巧参考 claude-code-best-practice。
常见陷阱
| 陷阱 | 说明 | 解决 |
|---|---|---|
| 上下文溢出 | 对话太长 AI 变笨 | 定期开新对话,用 CLAUDE.md 传递上下文 |
| 幻觉 API | AI 编造不存在的 API | 让它先查文档或 grep 确认 |
| 过度重构 | 你说修个 bug 它把整个文件重写了 | 明确说"只改这一处,不要重构" |
| 测试没跑 | AI 说"完成了"但没验证 | 用 verification skill 或 hook 强制验证 |
| 忽略错误处理 | 快速实现但没考虑异常 | 在提示词里明确要求错误处理 |
👉 深度展开版:Claude Code 陷阱合集 — 8 个真实踩坑场景,每个带症状 / 根因 / 出坑 / 预防
配置模板
直接复制到你的项目里用:
| 模板 | 用途 |
|---|---|
| CLAUDE.md | 项目配置文件模板,复制到项目根目录后按需修改 |
| settings.json | 权限配置模板,复制到 .claude/settings.json |
延伸阅读
- Claude Code 官方文档
- superpowers-zh — 20 个 AI 编程 skills
- agency-agents-zh — 211 个 AI 专家角色
File: codex/README.en.md
简体中文 | English
OpenAI Codex CLI Best Practices
Codex CLI is OpenAI's open-source terminal coding agent, written in Rust — sitting alongside Claude Code and Gemini CLI as the "big three" terminal agents. This guide is verified against the official docs (developers.openai.com/codex) and the openai/codex repo at v0.125.0 (April 2026).
⚠️ Note: this is the new Codex CLI released in 2025 (open-source, terminal agent), not the original Codex model that was deprecated in 2023. The product family also includes Codex App (desktop) and Codex Web (cloud agent at
chatgpt.com/codex); this doc covers the CLI only.
Core Concepts
| Concept | Description | Use Case |
|---|---|---|
| AGENTS.md | Project/global instruction file | Like Claude Code's CLAUDE.md; auto-loaded on launch |
| Approval Mode | When does Codex pause to ask | untrusted / on-request / never |
| Sandbox Mode | What files/network it can touch | read-only / workspace-write / danger-full-access |
| Profile | Named bundle of config | --profile work to swap model/permissions |
| Subagent | Child agent for bounded tasks | TOML-defined, can have its own model/sandbox |
| Skill | Reusable workflow (SKILL.md) | Package a recurring task as a named capability |
| MCP Server | External tool integration | STDIO or HTTP/OAuth |
| Plan Mode | Plan before acting | /plan or Shift+Tab |
Getting Started
Installation
# npm (recommended)
npm install @openai/codex
# or Homebrew (macOS)
brew install --cask codex
# or download a GitHub Release binary (macOS arm64/x64, Linux x64/arm64)
# https://github.com/openai/codex/releases/latestSystem requirements (from official install docs): macOS 12+, Ubuntu 20.04+ / Debian 10+, Windows 11 (WSL2), 4 GB RAM (8 GB recommended), optional Git 2.23+.
Authentication
codex # On first launch, choose "Sign in with ChatGPT"Two options:
- ChatGPT account login (officially recommended) — uses your ChatGPT Plus / Pro / Business / Edu / Enterprise quota; opens a browser for OAuth.
- API key — for CI, corporate proxies, or precise per-token billing; needs extra setup (see
developers.openai.com/codex/auth).
Your First Run
cd /your/project
codexInside the TUI, try these (from the official quickstart):
> Tell me about this project
> Find and fix bugs in my codebase with minimal, high-confidence changes
> Build a classic Snake game in this repo💡 Official advice:
git commitor create a checkpoint before any non-trivial task. If Codex's changes aren't what you want, you can roll back instantly.
AGENTS.md — Project Instruction File
Drop an AGENTS.md at your repo root (or run /init to scaffold one):
# Project
Next.js 14 + TypeScript admin dashboard.
# Layout
- src/app/api/ route handlers
- src/components/ UI components (PascalCase)
- src/lib/db/ Drizzle data access layer
# Build / Test / Lint
- Dev: pnpm dev
- Test: pnpm test (Vitest — must pass after every change)
- Types: pnpm typecheck
- Lint: pnpm lint --fix
# Conventions
- TS strict mode
- All DB access through Drizzle, no raw SQL
- Don't bypass husky pre-commit hooks
# Don't
- Don't touch src/legacy/
- Don't add runtime deps without askingDiscovery order (important):
~/.codex/AGENTS.override.md ← temp global override
~/.codex/AGENTS.md ← personal global
<git root>/AGENTS.md ← team-shared
<subdir>/AGENTS.md ← module-local (overrides parents)Files are concatenated from shallow to deep; closer-to-cwd files win. Default 32 KiB cap per file, tunable via project_doc_max_bytes.
Prompting Tips
OpenAI's recommended four-element prompt template (from developers.openai.com/codex/learn/best-practices):
Goal: what to change or build
Context: which files, docs, errors matter
Constraints: standards, architecture, safety rules
Done when: the completion bar1. Be precise, not verbose
❌ optimize the login flow
✅ Goal: switch src/app/api/login/route.ts from bcrypt.compareSync to async compare
Context: called by src/components/LoginForm.tsx; error shape { code, message } must stay
Constraints: don't touch the schema, don't add deps
Done when: pnpm test passes; 100 concurrent logins show no event-loop blocking warnings2. Reference files with `@`, don't paste
@src/services/payment.ts @src/services/order.ts
Read both, analyze the retry logic in the failure path, propose a fix, wait for my OK before editing.Letting Codex pull files itself saves tokens and avoids accidental truncation.
3. Tune reasoning effort
Push harder for hard problems, dial back for easy ones:
- low — small edits, formatting
- medium / high — most refactors and bugfixes
- xhigh — architectural, multi-file, deeply coupled
Switch in the TUI via shortcut, or set the default in config.toml.
4. Plan first, act second
/plan
Walk src/api/, unify all routes onto the new error-handling middlewareOr hit Shift+Tab to enter Plan Mode. Codex lays out the plan and asks clarifying questions before writing code — strongly recommended for multi-file work.
5. Make it test and self-review
After your changes:
1) Run pnpm test, paste any failing output
2) Run pnpm typecheck, confirm no new type errors
3) Use /review to self-audit the diff and flag risksQuoting the official guide verbatim: Don't stop at asking Codex to make a change. Ask it to create tests when needed, run checks, confirm results, and review work before accepting.
Approval & Sandbox (the two big safety knobs)
Codex's distinguishing design — two independent dimensions.
Sandbox (what it can touch)
| Mode | Behavior |
|---|---|
read-only |
Read only; any write/exec/network needs approval |
workspace-write ⭐ default |
Read + edit inside workspace + run routine commands; out-of-workspace writes or network need approval |
danger-full-access |
No restrictions — not recommended |
Enforcement (verified against codex-rs/cli/src/debug_sandbox.rs):
- macOS — Seatbelt (built-in)
- Linux / WSL2 — Landlock kernel LSM + seccomp filtering (requires Linux 5.13+ with Landlock enabled)
- Windows — Restricted-token sandbox (active in PowerShell)
Tip:
codex sandbox seatbelt|landlock|windows -- <cmd>is the debug subcommand to verify whether a single command would survive the sandbox.
Approval (when it asks)
| Mode | Behavior |
|---|---|
untrusted |
Only known-safe read ops auto-run; everything else asks |
on-request ⭐ default |
Auto-runs inside sandbox; only asks when going outside |
never |
Never asks (CI / scripts — pair with a tight sandbox) |
Common Combos
# Local dev — just run `codex` (defaults are already workspace-write + on-request)
codex
# Explicit form (equivalent to the above)
codex --sandbox workspace-write
# Just look around, don't edit
codex --sandbox read-only
# Add a few writable dirs outside the workspace (without going full-open)
codex --add-dir ../sibling-repo --add-dir /tmp/scratch
# Non-interactive in CI / scripts
codex exec --sandbox workspace-write --ask-for-approval never "run tests and fix failures"
# Open the sandbox fully (you understand the consequences)
codex --sandbox danger-full-access --ask-for-approval never
# Full YOLO: skip approvals AND drop the sandbox (only when externally sandboxed, e.g. Docker)
codex --yolo
# equivalent to: codex --dangerously-bypass-approvals-and-sandbox⚠️
--full-autois deprecated and removed (v0.125.0 still keeps it insidecodex execonly to print a migration warning). Use--sandbox workspace-write— that's the official replacement; approval defaults toon-requestalready.🚨 CI gotcha: the default approval mode is interactive — CI will hang on the prompt and time out.
codex exec+--ask-for-approval neveris the canonical CI shape.
Advanced
1. config.toml — Persistent Preferences
~/.codex/config.toml (user) / .codex/config.toml (project):
model = "gpt-5.5"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
[features]
web_search = "cached" # cached by default; --search switches to live
multi_agent = true
[profiles.review]
model = "gpt-5.5"
approval_policy = "untrusted"
sandbox_mode = "read-only"
[profiles.ci]
approval_policy = "never"
sandbox_mode = "workspace-write"
[mcp_servers.github]
command = "npx @modelcontextprotocol/server-github"
enabled = trueSwitch profiles:
codex --profile review # read-only review pass
codex exec --profile ci "..." # CI / scripted run2. Slash Commands Cheat Sheet
| Command | Use |
|---|---|
/init |
Scaffold an AGENTS.md in the repo |
/model |
Switch model |
/plan |
Enter Plan Mode |
/review |
Have Codex review the current diff / branch / commit |
/compact |
Compress conversation history; free up tokens |
/agent |
Switch between active subagent threads (/multi-agents alias) |
/side |
Open a side conversation in an ephemeral fork — won't pollute main thread |
/permissions /approvals |
Adjust approval mode on the fly |
/resume /fork |
Resume / branch from a prior thread |
/new /clear |
Start a new conversation in the same session / clear and restart |
/rename |
Rename the current thread |
/diff |
Show git diff (including untracked files) |
/mention |
Attach a file to the conversation |
/skills |
List / use skills |
/memories |
View / generate / reset long-term memory |
/mcp |
Inspect MCP server status (/mcp verbose for details) |
/plugins /apps |
Browse plugins / apps |
/status |
Session details and token usage |
/goal |
Set / view goal for a long-running task |
/fast |
Toggle Fast mode (on/off/status) |
/debug-config |
Print config layers and requirements diagnostics (use this when config.toml edits don't take effect) |
/feedback |
Send logs to OpenAI maintainers |
Complete list (46 commands) lives in source
codex-rs/tui/src/slash_command.rs::SlashCommand. Just press/in the TUI for autocomplete.
3. Non-interactive Execution (`exec`)
Treat Codex as a script tool:
# Single prompt
codex exec "replace all console.log with logger.debug"
# Pipe in
git diff main..HEAD | codex exec "review this diff for bugs"
# Pin model + skip approvals
codex exec -m gpt-5.5 --ask-for-approval never "add unit tests for new files"
# Stream events as JSONL (one JSON object per line)
codex exec --json "..." | jq -c .
# Capture only the final message to a file (handy for scripting)
codex exec -o /tmp/answer.txt "..."4. Subagents — Parallel Subtasks
.codex/agents/explorer.toml:
name = "explorer"
description = "Read-only codebase explorer; gathers evidence before any change."
model = "gpt-5.3-codex"
sandbox_mode = "read-only"
developer_instructions = """
Stay in exploration mode.
Trace execution paths, cite files and symbols with file:line.
Never propose changes — just report findings.
"""Invoke from the main thread:
Spawn an explorer subagent and have it map all auth logic under src/api/, then report back.Each subagent runs in its own sandbox + model and returns its summary to the main thread. Great for "explore + execute" splits on complex changes.
5. MCP — External Tools
codex mcp add github --command "npx @modelcontextprotocol/server-github"
codex mcp listSTDIO and HTTP/OAuth servers supported. Common picks: GitHub, Linear, Slack, databases (Postgres / Supabase). Rule of thumb: only add tools that remove a real manual loop — don't pad the list.
6. Skills — Reusable Workflows (note: a folder, not a single file)
Package recurring tasks as a Skill directory. Codex reads the description to decide when to fire and only loads the body on demand ("progressive disclosure"):
~/.agents/skills/release-notes/ ← personal (canonical)
.codex/skills/release-notes/ ← project, Codex-only
.agents/skills/release-notes/ ← project, cross-tool (Claude Code/Codex)
└── SKILL.md # required: name + description + steps
└── references/ # optional: long docs, specs, schemas
└── scripts/ # optional: helper scripts
└── examples/ # optional: I/O examples
└── agents/openai.yaml # optional: Codex-specific metadataNote:
~/.codex/skills/still works but is deprecated; new installs should use~/.agents/skills/.
How to invoke (from shanraisshan battle-tested patterns):
$skill-creator # explicit trigger with $ prefix
/skills # list all available skills
> draft this week's release notes # description match auto-fires; no $ neededSkill writing rules (consensus across high-star community repos):
- The description field is a trigger, not a summary — write "when should I fire?" not "what is this?"
- A skill is for the model, not human readers — skip filler
- Give goals + constraints, don't railroad the model with prescriptive steps
- Add a
## Gotchassection per skill with Codex's failure modes in this domain — highest-signal content
Ready-made skill libraries: ComposioHQ/awesome-codex-skills, VoltAgent/awesome-agent-skills (cross-tool).
7. Hooks — Inject Custom Scripts into the Agent Loop (beta)
Enable [features] codex_hooks = true and Codex will invoke your shell scripts at 6 event points:
| Event | When | Typical Use |
|---|---|---|
PreToolUse |
Before any tool call | Block dangerous commands, validate args |
PermissionRequest |
When asking to escalate | Auto approve/deny by rule |
PostToolUse |
After a tool call | Auto lint / format / test |
SessionStart |
Session boot | Inject project-specific context |
UserPromptSubmit |
User submits prompt | Insert disclaimer, run safety scan |
Stop |
Session ends | Upload logs, clean tmp files |
💡 The hooks JSON schema reuses Claude Code's
hooks.jsonformat directly (the source engine is literally namedClaudeHooksEngine), so migrating from Claude Code is zero-change.
Config goes in .codex/hooks.json. Reference impl: shanraisshan/codex-cli-hooks.
The two highest-leverage uses:
- PostToolUse → run prettier / ruff / clang-format — Codex edits, hook formats, CI stays green
- PreToolUse → intercept
rm -rf/git push --force/ DB DROP — belt-and-suspenders safety
8. Memories — Cross-Session Long-Term Memory (beta)
Enable [features] memories = true and Codex carries facts you've confirmed across sessions ("this project uses pnpm — don't suggest npm").
/memories # TUI: view / generate / resetStored under ~/.codex/memories/ — per-user, not per-project. Safety toggles (from the source MemoriesToml struct):
[memories]
disable_on_external_context = true # mark thread "polluted" when external data is touched (MCP / web search) — prevents leaking
# (legacy alias `no_memories_if_mcp_or_web_search` still works)
generate_memories = true # default true; set to false to stop generating memories from new threads
use_memories = true # default true; set to false to skip injecting memories into promptsIf a session touches untrusted content (parsed an unfamiliar PDF, ran an unaudited MCP), run /memories → Reset immediately.
9. Plugins / Marketplace — Distribution (v0.121.0+)
Bundle skills + apps + MCP servers as a distributable plugin (.codex-plugin/plugin.json):
codex plugin marketplace add user/repo # GitHub shorthand
codex plugin marketplace add ./local-marketplace # local dir works too
codex plugin marketplace upgrade
codex plugin marketplace remove <name>
# In the TUI
/plugins # browse installed / available pluginsCommunity marketplace index: hashgraph-online/awesome-codex-plugins.
10. Fast Mode — 1.5× speed, 2× credits (gpt-5.4 only)
/fast on # enable
/fast status # current
/fast off # disableBest when "I know roughly what to change, I just need a fast typist." Pro subscribers can also use gpt-5.3-codex-spark for near-realtime micro-iteration.
11. Web Search
On by default in cached mode (OpenAI's pre-indexed snapshot). For real-time, add --search:
codex --search "Latest React 19 useActionState best practices"12. Image Input
codex -i screenshot.png "match this design in src/components/Pricing.tsx"PNG / JPEG; you can also paste screenshots directly into the TUI composer. Combined with Chrome DevTools / Playwright MCP, Codex can read browser console output itself:
codex mcp add chrome-devtools --command "npx chrome-devtools-mcp"
codex mcp add playwright --command "npx @playwright/mcp"13. Local Open-Source Models (`--oss`)
Source utils/oss/src/lib.rs confirms Codex natively supports two local providers:
# Ollama route
codex --oss --local-provider ollama -m qwen2.5-coder
codex --oss --local-provider ollama -m deepseek-coder-v2
# LM Studio route
codex --oss --local-provider lmstudioFully offline, zero API cost. Trade-off: local models are noticeably weaker than GPT-5.5. Best for: sensitive on-premise data, no-network environments, bulk low-complexity tasks.
Model IDs follow Ollama / LM Studio naming (run
ollama listto see what's local). Codex doesn't maintain a separate catalog.
14. CI Integration (Official GitHub Action)
openai/codex-action is the official Apache-2.0 action with a built-in restricted sandbox proxy. The canonical PR auto-review workflow:
# .github/workflows/codex-review.yml
name: Codex PR review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v5
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- run: git fetch --no-tags origin "${{ github.event.pull_request.base.ref }}"
- id: codex
uses: openai/codex-action@v1
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
prompt: |
Review only the changes in PR #${{ github.event.pull_request.number }}:
git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}
Be concise. Flag bugs, missing tests, and security risks.
- if: steps.codex.outputs.final-message != ''
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{ steps.codex.outputs.final-message }}`
})⚠️ The sandbox blocks network by default — if your review prompt needs to run tests or install deps, do npm ci in a step before invoking codex-action.
15. Codex as an MCP Server (Reverse Integration)
codex mcp-server # expose Codex as an MCP serverSource confirms this exposes codex() and codex-reply() MCP tools. Use case: let Claude Code, Cursor, or any other agent call Codex as "a colleague" for parallel work or cross-verification.
16. Rules / Execpolicy (Advanced Safety)
Starlark DSL defining command allow/prompt/forbid lists (prefix_rule() + host_executable()). Drop rule files into .codex/rules/*.rules, validate with codex execpolicy check:
prefix_rule(
pattern = ["git", ["push", "force-with-lease"]],
decision = "prompt",
justification = "force pushes need a human eyeball",
)
prefix_rule(
pattern = ["rm", "-rf", "/"],
decision = "forbidden",
justification = "absolutely not",
)codex execpolicy check --rules .codex/rules/safety.rules git push --force
# {"matchedRules":[{...}],"decision":"prompt"}Best for enterprise / team setups — finer-grained than approval modes. See codex-rs/execpolicy/README.md.
High-Signal Prompting & Workflow Patterns
Distilled from high-star community guides (shanraisshan/codex-cli-best-practice etc.):
Prompting
✅ "Prove to me this works" — make Codex run the tests + git diff main..HEAD itself
✅ "Knowing everything you know now, scrap this and implement the elegant solution"
(use after a mediocre fix; pushes Codex past local minima)
✅ Codex debugs well by itself — paste the error, say "fix", don't micromanagePlanning
✅ /plan for explicit planning on multi-step tasks (Codex auto-plans too, but explicit is more controllable)
✅ Phase-gated plans, each phase has tests — never let it touch 30 files in one shot
✅ Spin up another Codex (or Claude Code) as a "staff engineer" to review your plan
✅ Write detailed specs, kill ambiguity — better input → better outputAGENTS.md
✅ Heuristic: a fresh dev should be able to launch codex → "run the tests" → it works first try
If not, your AGENTS.md is missing build/setup/test commands
✅ Aim for ~150 lines (hard limit is 32 KiB byte-wise) — longer ≠ better
✅ Behavior rules (approval / sandbox / model) belong in config.toml, NOT AGENTS.md
✅ AGENTS.override.md for personal preferences — keeps team's AGENTS.md cleanMulti-Agent & Parallelism
✅ Multi-agent = throw more compute at the problem; offload chores to subagents
✅ Test-time compute: one agent writes, another finds bugs — separate context windows help
✅ Use git worktrees for parallel agents to avoid clobbering each otherDebugging
✅ Have Codex run the service whose logs you want to watch as a background task
✅ Stuck? Screenshot the issue and feed it in (image input is the most underrated capability)
✅ Agentic search (glob + grep) beats RAG — code drifts faster than indexes refreshCommon Pitfalls
| Symptom | Root Cause | Fix |
|---|---|---|
| Browser pops up demanding login | Token expired | Re-run codex (or codex login) and complete OAuth |
429 Too Many Requests |
Rate-limited | Wait for quota; for scripts, switch to API key + throttle |
| CI job hangs and times out | Default approval is interactive | codex exec --ask-for-approval never |
config.toml edits don't take effect |
Wrong path / config layering overrides yours | Run /debug-config in the TUI to see the resolved config stack and requirements |
npm i -g fails with EACCES |
Global dir owned by root | Install Node via nvm/fnm; never sudo npm |
which -a codex shows multiple paths |
npm + brew + binary all installed | Remove dupes; hash -r your shell |
| Codex "can't see" your edits | Outside workspace / wrong root | codex --cd to set the root |
| Long thread getting slow / pricey | Context bloat | /compact or /fork to trim |
| Two agents clobber the same file | Main + subagent both writing | Give the subagent a git worktree |
| Linux sandbox refuses to start | Kernel < 5.13 or Landlock not enabled | Update the kernel (check uname -r); on older distros fall back to --sandbox read-only |
Codex CLI vs Claude Code
These two are the closest analogs, but they optimize differently:
| Dimension | Codex CLI | Claude Code |
|---|---|---|
| Vendor | OpenAI | Anthropic |
| Open-source | ✅ Apache-2.0 (Rust) | ❌ Closed-source CLI |
| Sandbox | OS-kernel level (Seatbelt / Landlock) | App-layer + 26 hook events |
| Default account | ChatGPT subscription | Claude API / Pro |
| Config files | AGENTS.md + config.toml |
CLAUDE.md + settings.json |
| Plan mode | /plan or Shift+Tab |
/plan |
| Subagents | TOML files | Markdown files |
| MCP | ✅ | ✅ |
| Strong suit | Terminal tasks, CI, token efficiency | Big refactors, cross-file dependency reasoning, code style |
Community rule of thumb (echoed across builder.io / datacamp / multiple comparison posts):
Codex for keystrokes, Claude Code for commits.
Codex shines at "fast iterations + sandboxed execution"; Claude Code shines when one change touches 12 files and the dependency graph matters.
Already paying for ChatGPT and budget-sensitive → Codex comes practically free. Doing a big refactor where code quality is paramount → Claude Code is still the pick. Many teams use both.
Templates
The templates/ directory provides:
AGENTS.md— generic project instruction templateconfig.toml— user-level config with profilesagent-explorer.toml— read-only exploration subagentSKILL.md— Skill template (with Gotchas + trigger-style description)
References
Official
- Repo: openai/codex (Apache-2.0, Rust)
- Docs: developers.openai.com/codex
- Install guide: docs/install.md
- Best practices: Best practices
- Sandboxing internals: Sandboxing
- Slash commands: Slash commands
- Official GitHub Action (CI integration): openai/codex-action
- Official skills catalog: openai/skills
High-quality community indexes (verified high-star)
- RoggeOhta/awesome-codex-cli — 280+ resources (subagents, skills, plugins, MCP, IDE integrations, CI), categorized
- shanraisshan/codex-cli-best-practice — 50 battle-tested prompting tips + complete
.codex/reference impl (aligned with v0.125.0) - ComposioHQ/awesome-codex-skills — 38 commonly-used skills (dev tools, data analysis, Composio 1000+ SaaS integrations)
- VoltAgent/awesome-codex-subagents — 136+ subagents across 10 domains
- hashgraph-online/awesome-codex-plugins — first Plugin marketplace index
- agents.md — cross-tool AGENTS.md standard (60k+ adopting projects; works in Codex / Claude Code / Gemini CLI)
Mainstream workflow frameworks
| Framework | Stars | Flow |
|---|---|---|
| Superpowers | 171k | Brainstorm → write plan → subagent-driven dev → TDD → review → ship branch |
| Spec Kit | 92k | /speckit.constitution → specify → plan → tasks → implement |
| oh-my-codex | 27k | $deep-interview → $ralplan → $ralph |
| Compound Engineering | 16k | /ce-ideate → brainstorm → plan → work → review → compound |
Compared to Claude Code
In this repo: workflows/tool-selection.en.md
Verified through: 2026-04-30 (codex CLI v0.125.0). Every CLI flag, subcommand, slash command, and config field in this guide was cross-checked against the
codex-rssource code; models and pricing change quickly — the OpenAI docs are always the source of truth.
File: codex/README.md
OpenAI Codex CLI 最佳实践
简体中文 | English
Codex CLI 是 OpenAI 官方的开源终端编程 Agent,用 Rust 写成,与 Claude Code、Gemini CLI 同属"终端 Agent 三巨头"。本文基于官方文档(developers.openai.com/codex)和仓库 openai/codex 的 v0.125.0(2026-04)核实整理。
⚠️ 注意:这里讲的是 2025 年发布的新 Codex CLI(开源、终端 Agent),不是 2023 年退役的旧 Codex 模型。同名产品系列还包括 Codex App(桌面端)和 Codex Web(云端 Agent,
chatgpt.com/codex),本文只覆盖 CLI。
核心概念
| 概念 | 说明 | 用途 |
|---|---|---|
| AGENTS.md | 项目/全局指令文件 | 类似 Claude Code 的 CLAUDE.md,启动时自动加载 |
| Approval Mode | 何时需要人来批 | untrusted / on-request / never |
| Sandbox Mode | 能动什么文件、能不能联网 | read-only / workspace-write / danger-full-access |
| Profile | 一组 config 的命名预设 | --profile work 一键切换模型/权限 |
| Subagent | 子 Agent,独立任务 | TOML 定义,可设置不同模型/权限 |
| Skill | 可复用工作流(SKILL.md) | 把重复任务封装成命名能力 |
| MCP Server | 外部工具接入 | STDIO 或 HTTP/OAuth |
| Plan Mode | 先规划再动手 | /plan 或 Shift+Tab 切换 |
快速上手
安装
# npm(推荐)
npm install @openai/codex
# 或 Homebrew (macOS)
brew install --cask codex
# 或下载 GitHub Release 二进制(macOS arm64/x64、Linux x64/arm64)
# https://github.com/openai/codex/releases/latest系统要求(来自官方 install 文档):macOS 12+、Ubuntu 20.04+/Debian 10+、Windows 11(WSL2),4 GB 内存(建议 8 GB),可选 Git 2.23+。
认证
codex # 第一次启动,按提示选 "Sign in with ChatGPT"两种方式:
- ChatGPT 账号登录(官方推荐)—— 走 ChatGPT Plus / Pro / Business / Edu / Enterprise 订阅额度,开浏览器走 OAuth。
- API Key —— 适合 CI、企业代理或想精确按量计费的场景,需要额外设置(详见
developers.openai.com/codex/auth)。
第一次跑
cd /your/project
codex进入 TUI 后试这几条(来自官方 quickstart):
> Tell me about this project
> Find and fix bugs in my codebase with minimal, high-confidence changes
> Build a classic Snake game in this repo💡 官方建议:执行任务前先
git commit或建 checkpoint,Codex 改完不满意可以一键回滚。
AGENTS.md — 项目指令文件
在项目根目录建 AGENTS.md(或运行 /init 让 Codex 自动 scaffold):
# 项目说明
Next.js 14 + TypeScript 电商后台。
# 目录约定
- src/app/api/ 接口路由
- src/components/ UI 组件(PascalCase)
- src/lib/db/ Drizzle 数据访问层
# 构建 / 测试 / Lint
- 启动:pnpm dev
- 测试:pnpm test (Vitest,必须在改完后跑)
- 类型:pnpm typecheck
- Lint:pnpm lint --fix
# 工程约束
- TS strict mode
- DB 操作只走 Drizzle,禁止裸 SQL
- 提交前自动 lint,不要绕过 husky
# 不要做的事
- 不要修改 src/legacy/
- 不要新增运行时依赖前不询问加载顺序(重要):
~/.codex/AGENTS.override.md ← 临时全局覆盖
~/.codex/AGENTS.md ← 个人全局
项目 git root/AGENTS.md ← 团队共享
子目录/AGENTS.md ← 模块级局部规则(覆盖父级)文件按目录从浅到深拼接,越靠近当前目录的越优先生效。默认每个文件最多 32 KiB,可通过 project_doc_max_bytes 调。
提示词技巧
Codex 官方推荐"四元素"提示模板(来源:developers.openai.com/codex/learn/best-practices):
Goal: 要做什么?要改什么?
Context: 涉及哪些文件、文档、错误信息?
Constraints: 约束有哪些?规范、架构、安全要求?
Done when: 完成判定条件是什么?1. 精确而不啰嗦
❌ 优化下登录功能
✅ Goal: 把 src/app/api/login/route.ts 的密码比对从 bcrypt.compareSync 换成异步 compare
Context: 该接口被 src/components/LoginForm.tsx 调用,错误返回需保持 { code, message } 结构
Constraints: 不动 schema、不加新依赖
Done when: pnpm test 全绿,且并发 100 次登录无 event loop 阻塞警告2. 用 `@` 引文件而不是粘贴
@src/services/payment.ts @src/services/order.ts
读完这两个文件,分析支付流程的失败重试有什么漏洞,先给方案,确认后再改。让 Codex 自己拉文件比你粘进 prompt 更省 token,也避免"截断到一半"。
3. 推理强度按需调
复杂问题让 Codex "think harder",简单任务用低推理省钱:
- low — 简单改动、风格调整
- medium / high — 大多数日常重构、Bug 修复
- xhigh — 架构级、多文件复杂逻辑
可在 TUI 里通过快捷键切换,或在 config.toml 里设默认。
4. 先 Plan 后 Act
/plan
分析 src/api/ 下所有路由,统一改成新的错误处理中间件或者按 Shift+Tab 切到 Plan Mode。Codex 会先列计划、问澄清问题,确认后才写代码——多文件任务强烈建议用。
5. 让它跑测试 + 自查
做完改动后:
1) 跑 pnpm test,把失败用例的输出贴给我
2) 跑 pnpm typecheck,确认没有新增类型错误
3) 用 /review 自查 diff,列出风险点官方原话:Don't stop at asking Codex to make a change. Ask it to create tests when needed, run checks, confirm results, and review work before accepting.
Approval & Sandbox(最重要的两个安全旋钮)
这是 Codex 最有特色的设计。两个维度独立配置:
Sandbox(能动什么)
| 模式 | 行为 |
|---|---|
read-only |
只读,任何写/执行/联网都要批 |
workspace-write ⭐ 默认 |
可读、可改 workspace 内文件、可跑常规命令;写 workspace 外或联网要批 |
danger-full-access |
完全放开,不推荐 |
技术实现(核实自 codex-rs/cli/src/debug_sandbox.rs 源码):
- macOS — Seatbelt(系统自带)
- Linux / WSL2 — Landlock 内核 LSM + seccomp 过滤(需要 Linux 5.13+ 且 Landlock 已启用)
- Windows — Restricted token sandbox(PowerShell 下生效)
提示:可以用
codex sandbox seatbelt|landlock|windows -- <cmd>这组调试子命令,单独验证某条命令在沙箱里能不能跑。
Approval(什么时候问你)
| 模式 | 行为 |
|---|---|
untrusted |
只有官方判定为安全的只读操作自动跑,其他都要批 |
on-request ⭐ 默认 |
在 sandbox 内自动跑,越界(写外、联网)才问 |
never |
永不询问(用于 CI / 脚本,配 sandbox 用) |
常用组合
# 本地开发:直接 `codex` 即可(默认就是 workspace-write + on-request)
codex
# 显式指定(与上面等价)
codex --sandbox workspace-write
# 只想让它探一下、不要动手
codex --sandbox read-only
# 加几个 workspace 外的可写目录(不需要全开)
codex --add-dir ../sibling-repo --add-dir /tmp/scratch
# 在 CI / 脚本里非交互执行
codex exec --sandbox workspace-write --ask-for-approval never "跑测试并修复失败用例"
# 临时完全放开沙箱(明白后果再用)
codex --sandbox danger-full-access --ask-for-approval never
# 完全 YOLO:连询问都跳过、不沙箱(仅在外部已隔离环境下用,例如 Docker)
codex --yolo
# 等价于:codex --dangerously-bypass-approvals-and-sandbox⚠️
--full-auto已废弃移除(v0.125.0 仍在codex exec里保留作迁移提示)。直接--sandbox workspace-write就是同义;approval 默认本就是on-request。🚨 CI 踩坑:默认 approval 是交互式的,CI 里会卡死等输入超时。
codex exec+--ask-for-approval never是 CI 的标准姿势。
进阶用法
1. config.toml — 持久化偏好
~/.codex/config.toml(用户级)/ .codex/config.toml(项目级):
model = "gpt-5.5"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
[features]
web_search = "cached" # 默认走缓存;--search 切 live
multi_agent = true
[profiles.review]
model = "gpt-5.5"
approval_policy = "untrusted"
sandbox_mode = "read-only"
[profiles.ci]
approval_policy = "never"
sandbox_mode = "workspace-write"
[mcp_servers.github]
command = "npx @modelcontextprotocol/server-github"
enabled = true切换 profile:
codex --profile review # 只读模式跑代码审查
codex exec --profile ci "..." # CI 用脚本模式2. Slash 命令速查
TUI 内常用:
| 命令 | 作用 |
|---|---|
/init |
在仓库 scaffold 一份 AGENTS.md |
/model |
切换模型 |
/plan |
进入 Plan Mode |
/review |
让 Codex 审查当前 diff / 分支 / 指定 commit |
/compact |
压缩对话历史,释放 token |
/agent |
在多个 subagent thread 间切换(/multi-agents 别名) |
/side |
在临时 fork 里开支线对话,问完不污染主线 |
/permissions /approvals |
临时调权限 |
/resume /fork |
恢复 / 从某个时刻分叉对话 |
/new /clear |
同 session 内开新对话 / 清屏重开 |
/rename |
给当前 thread 改名 |
/diff |
看 git diff(含未跟踪文件) |
/mention |
把文件挂到对话里 |
/skills |
列出 / 使用 Skill |
/memories |
查看 / 生成 / 重置长期记忆 |
/mcp |
检查 MCP server 状态(/mcp verbose 看详情) |
/plugins /apps |
浏览插件 / 应用 |
/status |
当前 session 详情、token 使用 |
/goal |
设定 / 查看长任务的目标 |
/fast |
切 Fast mode(on/off/status) |
/debug-config |
打印配置层级与 requirements 诊断(改 config.toml 不生效时用这个) |
/feedback |
给 OpenAI 发日志反馈 |
完整表(46 个)见源码
codex-rs/tui/src/slash_command.rs::SlashCommand枚举。在 TUI 里按/也会弹自动补全。
3. 非交互执行(exec)
把 Codex 当脚本工具用:
# 单 prompt
codex exec "把所有 console.log 改成 logger.debug"
# 管道
git diff main..HEAD | codex exec "审查这份 diff,找出潜在 bug"
# 指定模型 + 不询问
codex exec -m gpt-5.5 --ask-for-approval never "为新文件补单测"
# 输出 JSONL(每行一个事件)给后续程序处理
codex exec --json "..." | jq -c .
# 把最后一条 message 单独写到文件(便于脚本提取最终结果)
codex exec -o /tmp/answer.txt "..."4. Subagent — 并行子任务
.codex/agents/explorer.toml:
name = "explorer"
description = "Read-only codebase explorer; gathers evidence before any change."
model = "gpt-5.3-codex"
sandbox_mode = "read-only"
developer_instructions = """
Stay in exploration mode.
Trace execution paths, cite files and symbols with file:line.
Never propose changes — just report findings.
"""主 Agent 调用:
派一个 explorer subagent 把 src/api/ 所有路由的鉴权逻辑梳理一遍,回来汇总。子 Agent 独立 sandbox + 模型,跑完返回主 thread。适合"探索 + 实施"分离的复杂改动。
5. MCP — 外部工具
# CLI 直接添加
codex mcp add github --command "npx @modelcontextprotocol/server-github"
codex mcp list支持 STDIO 和 HTTP/OAuth 两类 server。常用:GitHub、Linear、Slack、数据库(Postgres / Supabase)。原则:只接能消除手工动作的工具,不要凑数。
6. Skill — 可复用方法论(注意:是文件夹,不是单文件)
把重复任务封装成一个 Skill 目录,Codex 看 description 决定何时触发,只在需要时才载入正文("渐进披露"):
~/.agents/skills/release-notes/ ← 个人(canonical 路径)
.codex/skills/release-notes/ ← 项目 Codex 专属
.agents/skills/release-notes/ ← 项目跨工具(Claude Code / Codex 等共享)
└── SKILL.md # 必须:name + description + 主体步骤
└── references/ # 可选:长文档、规范、API schema
└── scripts/ # 可选:辅助脚本(lint / parser / generator)
└── examples/ # 可选:示范输入/输出
└── agents/openai.yaml # 可选:Codex 专属元数据(如限制权限)注:
~/.codex/skills/也能用但已废弃(向后兼容),新装统一放~/.agents/skills/。
调用方式(来自 shanraisshan 实战经验):
$skill-creator # 用 $ 前缀显式触发某个技能
/skills # 列出所有可用技能
> 给我做这周 release notes # 描述匹配会自动触发,无需 $写 Skill 的要点(社区高 star 项目共识):
- description 是触发器,不是摘要——写"什么时候应该 fire"而不是"这是什么"
- Skill 是给模型看的指引,不是给人看的文档——别罗列废话
- 给目标和约束,别 railroad(强制每一步怎么做),让模型自己决策路径
- 加一个
## Gotchas段,把 Codex 在这个领域常踩的坑记下来——这是最高信号的内容
现成 Skill 库可以直接抄:ComposioHQ/awesome-codex-skills、VoltAgent/awesome-agent-skills(跨工具)
7. Hooks — 在 Agent 循环里挂自定义脚本(beta)
启用 [features] codex_hooks = true 后,Codex 在 6 个事件点会调用你定义的 shell 脚本:
| 事件 | 触发时机 | 典型用途 |
|---|---|---|
PreToolUse |
工具调用前 | 危险命令拦截、参数校验 |
PermissionRequest |
申请越界权限时 | 自动批/拒,根据规则 |
PostToolUse |
工具调用后 | 自动 lint / format / 测试 |
SessionStart |
session 启动 | 加载项目特定上下文 |
UserPromptSubmit |
用户提交 prompt 时 | 注入企业 disclaimer / 安全扫描 |
Stop |
session 结束 | 上传日志 / 清理临时文件 |
💡 hook schema 直接复用 Claude Code 的
hooks.json格式(源码引擎名ClaudeHooksEngine),所以从 Claude Code 迁移过来零改动。
配置文件 .codex/hooks.json,参考实现:shanraisshan/codex-cli-hooks。
最常见的两个 use case:
- PostToolUse 跑 prettier/ruff — Codex 改完代码自动格式化,避免 CI 红
- PreToolUse 拦截
rm -rf/git push --force/ 数据库 DROP — 双保险
8. Memories — 跨 session 的长期记忆(beta)
启用 [features] memories = true,Codex 会在 session 之间保留你确认过的事实("这个项目用 pnpm,不要建议 npm")。
/memories # TUI 里查看 / 生成 / 重置存在 ~/.codex/memories/(per-user,不是 per-project)。安全开关(来自源码 MemoriesToml 结构):
[memories]
disable_on_external_context = true # 触发外部数据(MCP / web 搜索)时把当前 thread 标"polluted",防记忆泄漏
# (旧别名 no_memories_if_mcp_or_web_search 仍可用)
generate_memories = true # 默认就是 true;置 false 则不再为新 thread 生成记忆
use_memories = true # 默认 true;置 false 跳过把记忆注入提示如果某个 session 接触了不可信内容(解析了陌生 PDF、跑了未审计的 MCP),跑 /memories → Reset 立即清掉。
9. Plugins / Marketplace — 插件分发(v0.121.0+)
把 skills + apps + MCP servers 打包成可分发的 plugin(.codex-plugin/plugin.json):
codex plugin marketplace add user/repo # GitHub shorthand
codex plugin marketplace add ./local-marketplace # 本地目录也行
codex plugin marketplace upgrade
codex plugin marketplace remove <name>
# 在 TUI 里
/plugins # 浏览已装 / 可装的 plugin社区 marketplace 索引:hashgraph-online/awesome-codex-plugins。
10. Fast Mode — 1.5× 速度,2× 额度(gpt-5.4 限定)
/fast on # 开启
/fast status # 看当前
/fast off # 关适合"知道大致怎么改、就缺打字员"的场景。Pro 订阅还能用 gpt-5.3-codex-spark 做近实时的小改动迭代。
11. Web 搜索
默认开启,cached 模式(OpenAI 预索引)。需要实时结果加 --search:
codex --search "React 19 useActionState 的最新最佳实践"12. 图片输入
codex -i screenshot.png "按这张设计稿改 src/components/Pricing.tsx"PNG / JPEG,可在 TUI 里直接粘贴截图。配 Chrome DevTools / Playwright MCP,让 Codex 自己看浏览器控制台日志:
codex mcp add chrome-devtools --command "npx chrome-devtools-mcp"
codex mcp add playwright --command "npx @playwright/mcp"13. 本地开源模型(`--oss`)
源码 utils/oss/src/lib.rs 确认 Codex 原生支持两个本地 provider:
# Ollama 路线
codex --oss --local-provider ollama -m qwen2.5-coder
codex --oss --local-provider ollama -m deepseek-coder-v2
# LM Studio 路线
codex --oss --local-provider lmstudio完全离线、零 API 成本。代价是模型能力比 GPT-5.5 弱不少,适合:本地敏感数据 / 没网环境 / 跑批量低复杂度任务。
模型 ID 跟着 Ollama / LM Studio 自己的命名(
ollama list看本地有什么),Codex 不维护独立清单。
14. CI 集成(官方 GitHub Action)
openai/codex-action 是官方 Apache-2.0 Action,自带受限沙箱代理。最常用的 PR 自动 review 工作流:
# .github/workflows/codex-review.yml
name: Codex PR review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v5
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- run: git fetch --no-tags origin "${{ github.event.pull_request.base.ref }}"
- id: codex
uses: openai/codex-action@v1
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
prompt: |
Review only the changes in PR #${{ github.event.pull_request.number }}:
git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}
Be concise. Flag bugs, missing tests, and security risks.
- if: steps.codex.outputs.final-message != ''
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{ steps.codex.outputs.final-message }}`
})⚠️ 沙箱默认禁网——如果你的 review prompt 需要跑测试 / 装依赖,先在 Action 步骤里 npm ci 再调 codex-action。
15. Codex 作为 MCP server(反向接入)
codex mcp-server # 把 Codex 暴露成 MCP server源码确认这会 expose codex() 和 codex-reply() 两个 MCP 工具。用法:让 Claude Code、Cursor 等其他 Agent 把 Codex 当成"我的同事"调用,做并行任务或交叉验证。
16. Rules / Execpolicy(高级安全)
Starlark DSL 定义命令白/灰/黑名单(prefix_rule() + host_executable())。规则文件放 .codex/rules/*.rules,可用 codex execpolicy check 离线验证:
prefix_rule(
pattern = ["git", ["push", "force-with-lease"]],
decision = "prompt",
justification = "force pushes need a human eyeball",
)
prefix_rule(
pattern = ["rm", "-rf", "/"],
decision = "forbidden",
justification = "absolutely not",
)codex execpolicy check --rules .codex/rules/safety.rules git push --force
# {"matchedRules":[{...}],"decision":"prompt"}适合企业 / 团队场景,比单纯 approval 更细粒度。详见 codex-rs/execpolicy/README.md。
高质量提示词与工作模式
来自 GitHub 高 star 实战教程(shanraisshan/codex-cli-best-practice 等)的高信号技巧:
提示词层面
✅ "证明给我看这能用" — 让 Codex 自己跑测试 + git diff main..HEAD 验证
✅ "用你现在掌握的所有信息,重新审视这个方案,给出更优雅的实现"
(在一次平庸修复后用,能逼出更好的设计)
✅ Codex 自己调试能力强 — 把报错日志贴进去说"修",别微管理过程Plan 层面
✅ /plan 多文件任务先列计划 — Codex 也会自动 plan,但显式触发更可控
✅ 分阶段 + 每阶段 gated test —— 别让它一次改 30 个文件
✅ 让另一个 Codex(或 Claude Code)以 staff engineer 视角审查计划
✅ 写规格、降歧义 —— 越具体的输入越能给出可用的输出AGENTS.md 层面
✅ 经验法则:随便一个新人能跑 codex → "run the tests" → 一次过
不行就说明 AGENTS.md 漏了 build/test/setup 命令
✅ 控制在 150 行附近(硬上限是 32 KiB)—— 长 ≠ 好
✅ 行为约束(approval / sandbox / model)写 config.toml,不要写 AGENTS.md
✅ AGENTS.override.md 放个人偏好,别污染团队共享的 AGENTS.md多 Agent 与并行
✅ 用 multi-agent 给问题扔更多算力 —— 把杂活外包给 subagent,主 thread 保持干净
✅ Test-time compute:一个 agent 写代码,另一个 agent 找 bug —— 独立 context 效果更好
✅ 长开发用 git worktree 给每个 agent 一个隔离的 working tree,避免互相覆盖调试
✅ 让 Codex 在后台跑你想看日志的服务(codex 的 PTY exec 会正确处理)
✅ 卡住就截图扔给它(图片输入是最被低估的能力)
✅ Agentic search(glob + grep)打 RAG —— 代码漂移得太快,索引永远不准常见踩坑(社区高频)
| 症状 | 根因 | 出坑 |
|---|---|---|
| 启动直接弹浏览器要求登录 | token 过期 | 重跑 codex 走 OAuth;或 codex login |
429 Too Many Requests |
触发速率限制 | 等额度恢复;脚本场景考虑切 API key + 限速 |
| CI 任务挂起超时 | 默认 approval 是交互式 | codex exec --ask-for-approval never |
| 改了 config.toml 不生效 | 文件路径错 / 配置层叠被覆盖 | TUI 里跑 /debug-config 看实际生效的配置层级和 requirements |
npm i -g 报 EACCES |
全局目录归 root | 用 nvm/fnm 装 Node,不要 sudo npm |
which -a codex 返回多行 |
装重了(npm + brew + binary) | 删多余的,shell rehash |
| 改完文件 Codex 不"看见" | 没在 git workspace 里 / 路径越界 | codex --cd 指定根目录 |
| 长 thread 越来越慢 / 涨钱 | 上下文累积 | /compact 压缩;或 /fork 重开 |
| 多 agent 并行改同一文件冲突 | 主线 + subagent 同时改 | 给 subagent 用 git worktree |
| Linux 沙箱起不来 | 内核 < 5.13 或 Landlock 未启用 | 升级内核(uname -r 确认);旧发行版临时用 --sandbox read-only 绕过 |
Codex 与 Claude Code 怎么选
两者最像,但定位不同:
| 维度 | Codex CLI | Claude Code |
|---|---|---|
| 厂商 | OpenAI | Anthropic |
| 开源 | ✅ Apache-2.0(Rust) | ❌ 闭源 CLI |
| 沙箱 | OS 内核级(Seatbelt / Landlock) | 应用层 + 26 个 Hook |
| 默认账号 | ChatGPT 订阅 | Claude API / Pro |
| 配置文件 | AGENTS.md + config.toml |
CLAUDE.md + settings.json |
| Plan 模式 | /plan 或 Shift+Tab |
/plan |
| Subagent | TOML 文件 | Markdown 文件 |
| MCP | ✅ | ✅ |
| 国内访问 | 需要 ChatGPT Pro / API key | 需要 Claude API |
| 强项场景 | 终端任务、CI 集成、token 效率 | 大型重构、跨文件依赖、代码风格 |
经验法则(社区共识,参考 builder.io / datacamp 等多篇对比):
Codex for keystrokes, Claude Code for commits.
Codex 适合"快速迭代 + 沙箱执行",Claude Code 适合"一次改 12 个文件且依赖图复杂"的精修。
预算敏感且已订阅 ChatGPT → Codex 就是顺手白送的;做大重构、要最强代码质感 → Claude Code 仍是首选。两者并用也很常见。
模板与配置
templates/ 目录提供:
AGENTS.md— 通用项目指令模板config.toml— 用户级配置模板(含 profiles)agent-explorer.toml— 只读探索 subagent 模板SKILL.md— Skill 模板(含 Gotchas / 触发器写法范本)
参考资料
官方
- 仓库:openai/codex(Apache-2.0,Rust)
- 文档:developers.openai.com/codex
- 安装详解:docs/install.md
- 最佳实践:Best practices
- 沙箱原理:Sandboxing
- Slash 命令:Slash commands
- 官方 GitHub Action(CI 集成):openai/codex-action
- 官方 Skills 目录:openai/skills
社区高质量索引(高 star,每条都核实过)
- RoggeOhta/awesome-codex-cli — 280+ 资源大全(Subagent / Skill / Plugin / MCP / IDE 集成 / CI),按类别整理
- shanraisshan/codex-cli-best-practice — 50 条战场验证的提示词技巧 + 完整 .codex/ 实现样例(已对齐 v0.125.0)
- ComposioHQ/awesome-codex-skills — 38 个常用 Skill(开发工具 / 数据分析 / Composio 1000+ SaaS 集成)
- VoltAgent/awesome-codex-subagents — 136+ subagent 跨 10 个领域(开发 / 安全 / 基建 / 数据 / DX)
- hashgraph-online/awesome-codex-plugins — 第一个 Plugin marketplace 索引
- agents.md — 跨工具 AGENTS.md 标准(已被 60k+ 项目采用,Codex / Claude Code / Gemini CLI 通用)
主流 Workflow 框架
| 框架 | star | 流程 |
|---|---|---|
| Superpowers | 171k | 头脑风暴 → 写计划 → subagent 驱动 → TDD → review → 合分支 |
| Spec Kit | 92k | /speckit.constitution → specify → plan → tasks → implement |
| oh-my-codex | 27k | $deep-interview → $ralplan → $ralph |
| Compound Engineering | 16k | /ce-ideate → brainstorm → plan → work → review → compound |
与 Claude Code 对比
本项目内:workflows/tool-selection.md
信息核实截止:2026-04-30(codex CLI v0.125.0)。本教程的每条 CLI flag、子命令、slash 命令、config 字段都对照
codex-rs源码核实过;模型能力和定价变化快,最终以 OpenAI 官方文档为准。
File: copilot/README.en.md
简体中文 | English
GitHub Copilot Best Practices
GitHub Copilot is the built-in AI coding assistant for VS Code and JetBrains IDEs. Its core strength is seamless integration — no tool switching needed, just write code in your editor and get completions and suggestions naturally. Copilot Agent mode evolves it from a completion tool into an autonomous agent that can tackle tasks independently.
Core Concepts
| Concept | Description | Use Case |
|---|---|---|
| Code Completion | Inline gray suggestions | Daily coding, press Tab to accept |
| Chat | Sidebar conversation Cmd+Shift+I |
Q&A, code explanations |
| Agent Mode | Autonomously completes multi-step tasks | Complex tasks, cross-file changes |
| Copilot Instructions | .github/copilot-instructions.md |
Project-level configuration |
| Chat Modes | Custom conversation roles | Security auditor, testing expert, etc. |
| MCP Server | Extends Copilot's tool capabilities | Connect to databases, APIs, etc. |
| # References | #file #selection #terminal |
Pinpoint context precisely |
Getting Started
Copilot Instructions — Project Configuration
Create .github/copilot-instructions.md in your project root:
# Project Guidelines
## Tech Stack
- Python 3.12 + FastAPI + SQLAlchemy 2.0
- Database: PostgreSQL
- Cache: Redis
- Testing: pytest
## Code Standards
- Type annotations must be complete, using Python 3.10+ syntax
- Prefix all async functions with `async_`
- All endpoints must use Pydantic models for input validation
- Use custom exception classes for errors, never bare Exception
## Directory Conventions
- src/api/ — FastAPI routes
- src/models/ — SQLAlchemy models
- src/schemas/ — Pydantic models
- src/services/ — Business logic
- tests/ — Tests (mirrors src structure)# Reference Tips
# Reference a file
#file:src/models/user.py Write a user registration endpoint based on this model
# Reference selected code
#selection What performance issues does this code have?
# Reference terminal output
#terminal Check the error and help me fix it
# Reference VS Code problems panel
#problems Fix these type errors for meAgent Mode
Copilot Agent was the biggest update of 2025. Enter a task in the chat, and Agent will:
- Analyze requirements -> 2. Search relevant files -> 3. Create a plan -> 4. Execute step by step -> 5. Run tests to verify
Using Agent Mode
Select Agent mode in Chat (or just describe a complex task):
@workspace Add rate limiting to all endpoints under src/api/,
using Redis as the counter. Max 60 requests per user per minute.
Requirements:
1. A reusable rate_limit decorator
2. Redis connection config
3. Return 429 status when limit exceeded
4. Add tests for each endpointAgent + MCP for Extended Capabilities
Use MCP Servers to give Agent access to external tools:
// .vscode/settings.json
{
"github.copilot.chat.mcpServers": {
"postgres": {
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres", "postgresql://..."]
}
}
}Then you can say:
Look up the structure of the users table in the database,
then generate a SQLAlchemy model and Pydantic schema based on the actual columns.Prompting Tips
1. Write Good Comments for Better Completions
# Completion quality depends on context. A single comment tells Copilot what you need:
# Count the number of business days between two dates, excluding weekends and public holidays
def count_business_days(start: date, end: date) -> int:
# Copilot will auto-complete the full implementation2. Custom Agents for Specialized Reviews
Create .github/agents/security-reviewer.agent.md:
---
name: Security Reviewer
---
You are a security review expert. When reviewing code:
1. Check against each item in the OWASP Top 10
2. Focus on SQL injection, XSS, CSRF, and authorization bypass
3. Check for sensitive data stored in plaintext or leaked in logs
4. Label risk levels: 🔴 Critical / 🟡 Medium / 🟢 LowInvoke this role in Chat with @security-reviewer.
3. Leverage Workspace for Global Understanding
@workspace Are there any hardcoded secrets or sensitive values in the project?
Find them all and refactor to use environment variables.Advanced Tips
Custom Instruction Files
Copilot supports instruction files to fine-tune behavior:
.github/copilot-instructions.md— Global project instructions.github/chatModes/— Custom Chat roles (e.g., security reviewer, testing expert)
If you use superpowers-zh, you can also write methodology in skill files under .claude/skills/ — Copilot Agent's @workspace command reads markdown files in the project.
VS Code Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Tab |
Accept completion |
Esc |
Reject completion |
Cmd+Shift+I |
Open Copilot Chat |
Cmd+I |
Inline edit |
Alt+] / Alt+[ |
Cycle through completion suggestions |
Completion Optimization
Tips for more accurate Copilot completions:
- Keep related files open — Copilot reads open tabs as context
- Write thorough type annotations — More complete types = more accurate completions
- Write function signatures first — Define the name, parameters, and return type, then let Copilot complete the body
- Keep files short — Large files add context noise, causing Copilot to drift
Common Pitfalls
| Pitfall | Description | Solution |
|---|---|---|
| Outdated API completions | Copilot suggests deprecated library APIs | Open the library source or docs as a tab for context |
| Agent edits wrong files | Multi-file changes touch things they shouldn't | Use #file to limit scope |
| Ignores .gitignore | Copilot may read node_modules | Check exclude settings in configuration |
| Instructions too long | Exceeds model context window | Trim to essential rules, move details into Chat Modes |
👉 Deep dive: Copilot Pitfalls — 8 real-world traps (Agent reads .env / MCP silent fail / free tier throttling and more), each with Symptom / Cause / Recovery / Prevention
Configuration Templates
Copy directly into your project:
| Template | Purpose |
|---|---|
| copilot-instructions.md | Project guidelines template, copy to .github/copilot-instructions.md |
| security-reviewer.agent.md | Security reviewer role, copy to .github/agents/ |
Further Reading
- Copilot Official Docs
- awesome-copilot — Official resource collection (27k+ stars)
- superpowers-zh — Skills methodology (also supports VS Code Copilot)
File: copilot/README.md
GitHub Copilot 最佳实践
GitHub Copilot 是 VS Code / JetBrains 内置的 AI 编程助手。它的核心优势是无缝集成 — 不需要切换工具,在编辑器里自然地写代码就有补全和建议。Copilot Agent 模式让它从补全工具进化成了能独立完成任务的 Agent。
核心概念
| 概念 | 说明 | 用途 |
|---|---|---|
| 代码补全 | 行内灰色建议 | 日常编码,按 Tab 接受 |
| Chat | 侧边栏对话 Cmd+Shift+I |
问答、解释代码 |
| Agent 模式 | 自主完成多步骤任务 | 复杂任务、跨文件修改 |
| Copilot Instructions | .github/copilot-instructions.md |
项目级配置 |
| Chat Modes | 自定义对话角色 | 安全审查、测试专家等 |
| MCP Server | 扩展 Copilot 的工具能力 | 连接数据库、API 等 |
| #引用 | #file #selection #terminal |
精确指定上下文 |
快速上手
Copilot Instructions — 项目配置
在项目根目录创建 .github/copilot-instructions.md:
# 项目指引
## 技术栈
- Python 3.12 + FastAPI + SQLAlchemy 2.0
- 数据库:PostgreSQL
- 缓存:Redis
- 测试:pytest
## 代码规范
- 类型注解必须完整,使用 Python 3.10+ 语法
- async 函数统一加 `async_` 前缀
- 所有接口必须有 Pydantic 模型做入参校验
- 错误用自定义异常类,不要用裸 Exception
## 目录约定
- src/api/ — FastAPI 路由
- src/models/ — SQLAlchemy 模型
- src/schemas/ — Pydantic 模型
- src/services/ — 业务逻辑
- tests/ — 测试(镜像 src 结构)# 引用技巧
# 引用文件
#file:src/models/user.py 基于这个模型写一个用户注册接口
# 引用选中代码
#selection 这段代码有什么性能问题?
# 引用终端输出
#terminal 看看报错信息帮我修
# 引用 VS Code 问题面板
#problems 帮我修复这些类型错误Agent 模式
Copilot Agent 是 2025 年最大的更新。从对话框输入任务,Agent 会:
- 分析需求 → 2. 搜索相关文件 → 3. 制定计划 → 4. 逐步执行 → 5. 运行测试验证
使用 Agent 模式
在 Chat 中选择 Agent 模式(或直接描述复杂任务):
@workspace 给 src/api/ 下所有接口加上 rate limiting,
使用 Redis 做计数器,每个用户每分钟最多 60 次请求。
需要:
1. 一个可复用的 rate_limit 装饰器
2. Redis 连接配置
3. 超限时返回 429 状态码
4. 给每个接口加上测试Agent + MCP 扩展能力
通过 MCP Server 让 Agent 访问外部工具:
// .vscode/settings.json
{
"github.copilot.chat.mcpServers": {
"postgres": {
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres", "postgresql://..."]
}
}
}然后你可以说:
查一下数据库里 users 表的结构,
然后根据实际字段生成 SQLAlchemy 模型和 Pydantic schema。提示词技巧
1. 写好注释让补全更准
# 补全质量取决于上下文。写一行注释,补全就知道你要什么:
# 计算两个日期之间的工作日天数,排除周末和中国法定节假日
def count_business_days(start: date, end: date) -> int:
# Copilot 会自动补全完整实现2. 用自定义 Agent 做专项审查
创建 .github/agents/security-reviewer.agent.md:
---
name: 安全审查员
---
你是一名安全审查专家。审查代码时:
1. 按 OWASP Top 10 逐项检查
2. 关注 SQL 注入、XSS、CSRF、权限绕过
3. 检查敏感数据是否明文存储或日志泄露
4. 标注风险等级:🔴 严重 / 🟡 中等 / 🟢 低在 Chat 中用 @security-reviewer 调用这个角色。
3. 利用 Workspace 全局理解
@workspace 项目里有没有硬编码的密钥或敏感信息?
帮我全部找出来,改成环境变量。进阶技巧
自定义指令文件
Copilot 支持通过指令文件细化行为:
.github/copilot-instructions.md— 全局项目指令.github/chatModes/— 自定义 Chat 角色(如安全审查员、测试专家)
如果你用 superpowers-zh,也可以在 .claude/skills/ 下的 skill 文件里写方法论,Copilot Agent 的 @workspace 命令会读取项目中的 markdown 文件。
VS Code 快捷键
| 快捷键 | 功能 |
|---|---|
Tab |
接受补全 |
Esc |
拒绝补全 |
Cmd+Shift+I |
打开 Copilot Chat |
Cmd+I |
行内编辑 |
Alt+] / Alt+[ |
切换不同补全建议 |
补全优化
让 Copilot 补全更准确的几个技巧:
- 打开相关文件 — Copilot 会读取当前打开的 tab 作为上下文
- 写好类型注解 — 类型越完整,补全越准
- 函数签名先写好 — 先写好函数名、参数、返回类型,再让它补全函数体
- 保持文件简短 — 大文件上下文噪音多,Copilot 容易跑偏
常见陷阱
| 陷阱 | 说明 | 解决 |
|---|---|---|
| 补全过时 API | Copilot 用了过期的库 API | 打开库的源码或文档作为 tab 上下文 |
| Agent 改错文件 | 多文件修改时动了不该动的 | 用 #file 限定范围 |
| 忽略 .gitignore | Copilot 可能读取 node_modules | 检查设置里的 exclude 配置 |
| Instructions 太长 | 超过模型上下文窗口 | 精简到关键规则,详细规则拆到 Chat Modes |
👉 深度展开版:Copilot 陷阱合集 — 8 个真实踩坑场景(Agent 读 .env / MCP 失效 / 免费限流 等),每个带症状 / 根因 / 出坑 / 预防
配置模板
直接复制到你的项目里用:
| 模板 | 用途 |
|---|---|
| copilot-instructions.md | 项目指引模板,复制到 .github/copilot-instructions.md |
| security-reviewer.agent.md | 安全审查角色,复制到 .github/agents/ |
延伸阅读
- Copilot 官方文档
- awesome-copilot — 官方资源集合(27k+ star)
- superpowers-zh — Skills 方法论(也支持 VS Code Copilot)