runesleo/claude-code-workflow

GitHub: runesleo/claude-code-workflow

Stars: 263 | Forks: 37

# Claude Code 工作流 一个久经考验的 Claude Code 工作流模板 —— 源自跨越多个项目、为期三个月的日常使用经验,涵盖记忆管理、上下文工程和任务路由。 **这并非教程,也不是玩具配置,而是一个真正能交付产品的生产级工作流。** ## 为什么会有这个项目 Claude Code 开箱即用虽然强大,但缺乏结构化时,它会变成一个在会话间遗忘一切的“聪明助手”。本模板将其转变为一个**持久化、自我进化的开发伙伴**,它能够: - 记住过去的错误并自动应用经验教训 - 在长会话中管理上下文,避免偏离目标 - 将任务路由到合适的模型层级 (Opus/Sonnet/Haiku/Codex/Local) - 强制在声称完成前进行验证(告别“现在应该能用了”) - 自动保存进度,关闭窗口也不会丢失工作 ## 架构:三层体系 ``` ┌─────────────────────────────────────────────────────────┐ │ Layer 0: Auto-loaded Rules (always in context) │ │ ┌─────────────┐ ┌────────────┐ ┌───────────────┐ │ │ │ behaviors.md │ │skill- │ │memory-flush.md│ │ │ │ │ │triggers.md │ │ │ │ │ └─────────────┘ └────────────┘ └───────────────┘ │ ├─────────────────────────────────────────────────────────┤ │ Layer 1: On-demand Docs (loaded when needed) │ │ agents.md · content-safety.md · task-routing.md │ │ behaviors-extended.md · scaffolding-checkpoint.md ... │ ├─────────────────────────────────────────────────────────┤ │ Layer 2: Hot Data (your working memory) │ │ today.md · projects.md · goals.md · active-tasks.json │ └─────────────────────────────────────────────────────────┘ ``` **为什么要分三层?** 上下文窗口非常昂贵。加载所有内容既浪费 token 又会降低质量。本系统始终加载规则(约 2K token),仅在相关时加载文档(每个约 1-3K token),并保持你的日常状态处于热加载状态以便即时调用。 ## 包含内容 ``` claude-code-workflow/ ├── CLAUDE.md # Entry point — Claude reads this first ├── README.md # You are here │ ├── rules/ # Layer 0: Always loaded │ ├── behaviors.md # Core behavior rules (debugging, commits, routing) │ ├── skill-triggers.md # When to auto-invoke which skill │ └── memory-flush.md # Auto-save triggers (never lose progress) │ ├── docs/ # Layer 1: On-demand reference │ ├── agents.md # Multi-model collaboration framework │ ├── behaviors-extended.md # Extended rules (knowledge base, associations) │ ├── behaviors-reference.md # Detailed operation guides │ ├── content-safety.md # AI hallucination prevention system │ ├── scaffolding-checkpoint.md # "Do you really need to self-host?" checklist │ └── task-routing.md # Model tier routing + cost comparison │ ├── memory/ # Layer 2: Your working state (templates) │ ├── today.md # Daily session log │ ├── projects.md # Cross-project status overview │ ├── goals.md # Week/month/quarter goals │ └── active-tasks.json # Cross-session task registry │ ├── skills/ # Reusable skill definitions │ ├── session-end/SKILL.md # Auto wrap-up: save progress + commit + record │ ├── verification-before-completion/SKILL.md # "Run the test. Read the output. THEN claim." │ ├── systematic-debugging/SKILL.md # 5-phase debugging (recall → root cause → fix) │ ├── planning-with-files/SKILL.md # File-based planning for complex tasks │ └── experience-evolution/SKILL.md # Auto-accumulate project knowledge │ ├── agents/ # Custom agent definitions │ ├── pr-reviewer.md # Code review agent │ ├── security-reviewer.md # OWASP security scanning agent │ └── performance-analyzer.md # Performance bottleneck analysis agent │ └── commands/ # Custom slash commands ├── debug.md # /debug — Start systematic debugging ├── deploy.md # /deploy — Pre-deployment checklist ├── exploration.md # /exploration — CTO challenge before coding └── review.md # /review — Prepare code review ``` ## 快速开始 ### 1. 复制到你的 Claude Code 配置目录 ``` # 克隆模板 git clone https://github.com/runesleo/claude-code-workflow.git # 复制到您的 Claude Code 配置目录 cp -r claude-code-workflow/* ~/.claude/ # 或者如果您想将其保留为 git 仓库,可以使用 symlink ln -sf ~/claude-code-workflow/rules ~/.claude/rules ln -sf ~/claude-code-workflow/docs ~/.claude/docs # ... 等 ``` ### 2. 自定义 CLAUDE.md 打开 `~/.claude/CLAUDE.md` 并填写: - **User Info**:你的名字、项目目录、社交账号 - **Sub-project Memory Routes**:将你的项目映射到记忆路径 - **SSOT Ownership Table**:定义各类信息的存放位置 - **On-demand Loading Index**:根据需要调整文档路径 ### 3. 启动会话 ``` claude ``` Claude 将自动加载你的规则并开始遵循该工作流。请尝试: - 开始编码并留意 **任务路由**("🔀 Route: bug fix → Sonnet") - 遇到 bug 时观察 **系统性调试** 如何启动 - 说 "that's all for now" 并观察 **会话结束** 时的自动保存 - 明天回来时在 `today.md` 中找到你保留的上下文 ## 核心概念 ### SSOT (单一事实来源) 每一条信息都有且仅有一个规范的位置。CLAUDE.md 中的 SSOT 表格将信息类型映射到文件。Claude 经过训练,会在写入前检查 SSOT,从而避免“同一信息存放在 5 个地方,全部过时”的问题。 ### 记忆清除 (Memory Flush) Claude 会在每次任务完成、每次提交以及每次退出信号时自动保存进度。你可以话说到一半直接关闭窗口,任何内容都不会丢失。不再有“我忘了保存上下文”。 ### 完成前验证 (Verification Before Completion) 这是影响最大的规则:Claude 不得在运行验证命令并读取输出之前声称工作已完成。这消除了 AI 编码的头号失败模式 —— 实际上并未检查就说“应该可以了”。 ### 三层任务路由 并非每个任务都需要 Opus。路由系统会自动将任务复杂度与模型层级匹配: - **Opus**:关键逻辑、安全敏感、复杂推理 - **Sonnet**:日常开发、分析、大多数编码任务 - **Haiku**:简单查询、子代理任务、快速查找 - **Codex**:交叉验证、代码审查、第二意见 - **Local**:提交信息、格式化、离线工作 ### 周日规则 (Sunday Rule) 系统优化发生在周日。在其他日子,如果你试图调整工作流而不是交付产品,Claude 会拦截并提醒你专注于产出。可根据你偏好的节奏进行配置。 ## 自定义指南 ### 添加新项目 1. 添加到 `memory/projects.md` 2. 在 CLAUDE.md 的 "Sub-project Memory Routes" 中添加记忆路由 3. 在项目根目录创建 `PROJECT_CONTEXT.md` ### 添加新技能 创建 `skills/your-skill/SKILL.md`,内容如下: ``` --- name: your-skill description: What it does allowed-tools: - Read - Write - Bash --- # 您的 Skill [Instructions for Claude when this skill is invoked] ``` ### 添加新代理 创建 `agents/your-agent.md`,内容如下: ``` --- name: your-agent description: What it does tools: Read, Grep, Glob, Bash --- # 您的 Agent [Agent personality, review dimensions, output format] ``` ### 调整模型路由 编辑 `rules/behaviors.md` → "Task Routing" 部分,以及 `docs/task-routing.md` 中的详细层级定义。 ## 设计理念 本模板编码了从日常 AI 辅助开发中学到的几项原则: 1. **结构 > 提示**:组织良好的配置文件每次都能胜过巧妙的一次性提示。 2. **记忆 > 智能**:一个记得你过去错误的 AI,比每个会话都重新开始的更聪明的 AI 更有价值。 3. **验证 > 自信**:运行 `npm test` 的成本总是低于发布错误构建的成本。 4. **分层加载 > 扁平配置**:不要把所有东西都塞进上下文。始终加载规则,按需加载文档,需要时再加载数据。 5. **自动保存 > 手动保存**:如果需要用户记住某事,那它终究会被遗忘。要让其自动化。 ## 系统要求 - [Claude Code](https://docs.anthropic.com/en/docs/claude-code) CLI (Claude Max 或 API 订阅) - 可选:Codex CLI,用于交叉验证 - 可选:Ollama,用于本地模型后备 ## 前身与致谢 本模板汲取了以下来源的灵感: - [Manus](https://manus.im/) 基于文件的规划方法 - OWASP Top 10,用于安全审查模式 - 构建 [x-reader](https://github.com/runesleo/x-reader)(650+ stars)和其他开源项目的实战经验 ## 许可证 MIT —— 随意使用、分叉、据为己有。 由 [@runes_leo](https://x.com/runes_leo) 构建 —— 更多 AI 工具请访问 [leolabs.me](https://leolabs.me) —— [Telegram 社区](https://t.me/runesgang)
标签:Agent架构, AI编程助手, AI风险缓解, Anthropic, CIS基准, Claude Code, DLL 劫持, 上下文工程, 上下文窗口, 任务路由, 多模型调度, 大语言模型, 工作流模板, 开发提效, 最佳实践, 生产环境, 网络安全研究, 自动化规则, 自改进系统, 记忆管理, 配置模板, 防御加固