但這顯然是「字面 vs 精神」的縫。Anthropic 拆這條政策的精神,就是要擋「沒人盯每一回合的大量自動化」 — 第三方分析給出的啟發式是:「if a Claude session runs without a human watching each turn, it is almost certainly moving to the new credit pool」。從這個精神判讀,大規模並行 Agent Team + 自動 cycle 精神上根本就是 programmatic,只是技術上沒被點名。
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
想提升 Claude Code 工作效率?本文分享從台北 Claude 社群聚會的重要洞察,揭示如何從簡單的對話式協作升級到完全自動化的 AI 代理團隊。核心秘訣:從 CLAUDE.md 開始記錄規則,逐步升級到 Hooks、Skills 和自訂 Agents。一個月 10-30 個 PR、每行程式碼由 AI 撰寫的高效工作流,就從這裡開始。
在台北舉辦的 Claude 社群聚會中,軟體工程師 David Chu(前 ENS 團隊成員)分享了一個有趣的對比故事。他已經能同時跑著 3-5 個 Claude Code 實例,100% 的程式碼由 Claude 生成,每天合併 2-4 個 PR。但這套流程有個關鍵問題:每天下班時都精神疲憊,因為他得不斷切換終端機、審查輸出、重新下提示。
相比之下,Claude Code 創作者 Boris Cherny 每天能合併 10-30 個 PR,一個月內完成 259 個 PR,每一行程式碼都由 Claude 撰寫。他的秘訣很簡單:「每次 Claude 做錯了什麼,就把它加進 CLAUDE.md,讓它永遠不再重蹈覆轍。」他的 CLAUDE.md 約有 2500 個 token,由整個團隊持續疊代。
關鍵洞察來自 David 的觀察:開始時用 Boris 的方式(密集的 CLAUDE.md),培養習慣後,再逐步將成熟的規則從 CLAUDE.md 中「畢業」出去,升級為 Hooks、Skills 或自訂 Agents。
// 文件:~/.claude/skills/wordpress-blog-publisher.md
---
name: wordpress-blog-publisher
description: Publish SEO and AEO optimized articles to WordPress via REST API
tags: [wordpress, blogging, content-management, seo, aeo]
trigger_patterns:
- "post to blog"
- "write blog article"
- "publish to wordpress"
---
# WordPress Blog Publisher Skill
## Overview
Publish SEO-optimized and AEO (Answer Engine Optimization)-ready articles to WordPress via REST API.
## Workflow
### Step 1: Verify API Access
Load WordPress credentials from ~/.claude/projects/-home-tom/wordpress-config.env
Test access with: `curl -s -o /dev/null -w "%{http_code}" -u "USER:PASS" "SITE/wp-json/wp/v2/posts?per_page=1"`
Expected response: 200
### Step 2: Discover Resources
- List categories: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/categories"`
- List tags: `curl -s -u "USER:PASS" "SITE/wp-json/wp/v2/tags"`
- Match user's content to appropriate categories
### Step 3: SEO Optimization Checklist
- Title: Under 60 chars, primary keyword near front
- Slug: Short, keyword-rich, no stop words
- Excerpt: 120-155 chars, includes primary keyword
- H2 headings: 4-8 per article, each with secondary keywords
- First 100 words: Must contain primary keyword naturally
- Internal links: Link to 2-3 related posts
- Word count: 1,500-3,000 words
### Step 4: AEO (Answer Engine Optimization)
Add FAQ Schema and Article Schema JSON-LD:
\`\`\`html
\`\`\`
### Step 5: Create JSON Payload
All content must use WordPress Gutenberg block format ( etc.)
Template:
\`\`\`json
{
"title": "SEO Title (under 60 chars)",
"slug": "keyword-rich-slug",
"excerpt": "Meta description 120-155 chars with primary keyword",
"content": "\n
Content here
",
"status": "draft",
"categories": [ID],
"tags": [ID1, ID2]
}
\`\`\`
### Step 6: Publish to WordPress
\`\`\`bash
curl -X POST \
-u "USER:PASS" \
-H "Content-Type: application/json" \
-d @payload.json \
"SITE/wp-json/wp/v2/posts"
\`\`\`
### Step 7: Report URL to User
Extract post ID from response, construct final URL:
https://blog.domain.com/YYYY/MM/DD/slug/
## Important Notes
- Always publish as "draft" first, never directly to "publish"
- Validate JSON before submitting
- Include both FAQ and Article schemas
- Use proper WordPress block format
// 文件:~/.claude/agents/code-reviewer.json
{
"name": "code-reviewer",
"description": "Senior code reviewer - checks style, security, performance, and tests",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer with 10+ years of experience. Your job is to:
1. **Style & Standards**: Check code follows project conventions (naming, formatting, structure)
2. **Security**: Identify potential vulnerabilities (SQL injection, XSS, unsafe crypto, privilege escalation)
3. **Performance**: Flag inefficient algorithms, N+1 queries, unnecessary iterations
4. **Testing**: Verify adequate test coverage and that edge cases are tested
5. **Architecture**: Ensure changes align with system design and don't introduce tight coupling
## Your Review Process:
- Read the entire context (files, previous PRs, architecture docs)
- Ask clarifying questions before criticizing
- Explain the "why" not just the "what"
- Suggest concrete improvements with code examples
- Rate severity: Critical (security/data loss) vs Major vs Minor
## Key Rules:
- Be constructive and respectful in tone
- Acknowledge good practices when you see them
- Never approve without understanding the change
- Flag assumptions and ask for validation
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch"],
"denied": ["Write", "Edit", "Bash", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-memory/",
"categories": [
"security-patterns",
"performance-antipatterns",
"project-conventions",
"past-mistakes"
]
},
"permissions": {
"canAccessRemoteRepos": true,
"canViewPullRequests": true,
"requiresApprovalFor": ["suggesting-major-refactors"]
}
}
步驟 3:啟動並指派任務給 Custom Agent
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// ~/.claude/agents/code-reviewer-tom-projects.json
{
"name": "code-reviewer-tom",
"description": "Dedicated code reviewer for Tom's iDempiere and Analytics projects",
"model": "claude-opus-4-6",
"systemPrompt": `You are a senior code reviewer for Tom's open-source projects (iDempiere modules, Analytics, Stock-Verify).
## Your Standards:
1. **Security** (CRITICAL): Check for SQL injection, XSS, credential leaks, unsafe deserialization, privilege escalation
2. **Performance**: Flag N+1 queries, unnecessary iterations, inefficient algorithms. Target: O(n) not O(n²)
3. **Tests**: Require 80%+ code coverage. Check for edge cases and error handling.
4. **Style**: Follow project conventions:
- Java: iDempiere package patterns, no static abuse
- Python: PEP8, type hints for complex functions
- SQL: Use prepared statements, clear table aliases
5. **Architecture**: Ensure changes don't break service boundaries or introduce tight coupling
## Tone:
- Be encouraging ("Good approach here because...")
- Ask "Why?" before criticizing
- Suggest concrete improvements with code examples
- Severity levels: 🔴 Critical (fix before merge) | 🟡 Major (should fix) | 🔵 Minor (nice to have)
## Tom's Specific Rules (from his projects):
- iDempiere: No hardcoded reference IDs, use AD_Column lookups
- WordPress: Never modify .env, use config injection
- Analytics: Data pipelines must be idempotent, validate after each stage
`,
"tools": {
"allowed": ["Read", "Grep", "LSP", "WebFetch", "Bash"],
"denied": ["Write", "Edit", "Agent"]
},
"memory": {
"enabled": true,
"location": "~/.claude/agents/code-reviewer-tom-memory/",
"trackingCategories": {
"security-findings": "Past security issues found and how they were fixed",
"performance-patterns": "Common performance issues in Tom's codebase",
"architectural-decisions": "Why certain patterns were chosen, anti-patterns to avoid",
"project-conventions": "Specific style and architecture rules for each project"
}
},
"approvalRules": {
"requiresUserApprovalBefore": ["suggesting major refactors", "marking as 🔴 Critical"],
"canAutoApproveFor": ["minor formatting", "documentation improvements"]
}
}
使用方式:
// 在 PR 中
@code-reviewer-tom Please review this PR for my Analytics data pipeline module.
Focus on: data validation, idempotency, and test coverage.
// Agent 會自動:
// 1. 使用獨立的 opus 模型(更強大)
// 2. 參考記憶庫中過往的安全發現和架構決策
// 3. 應用 Tom 的具體規則(例如 iDempiere pattern)
// 4. 提供一致、高質量的反饋
// 5. 學習新的模式並更新記憶庫
// 在 Claude Code 中
// 啟動代碼審查員 Agent
/spawn agent=code-reviewer
// 指派審查任務
@code-reviewer Please review the PR for my database migration module.
Check for: SQL injection risks, performance (this handles 10k+ records),
test coverage, and alignment with our ORM patterns.
// Agent 會自動:
// 1. 讀取相關文件
// 2. 查閱過往審查記錄(記憶庫)
// 3. 進行深度分析
// 4. 提供詳細反饋
步驟 4:驗收標準
✅ Agent 在其專業領域內提供一致、高質量的反饋
✅ 記憶庫能夠記住過往決策和模式
✅ 即使跨多個 PR 或項目,Agent 的風格和標準保持一致
✅ 團隊成員可以信任 Agent 的專業判斷
第三部分:真實案例深入剖析
案例 1:Tom 的 iDempiere 專案 - 從 Hook 中拯救敏感數據
背景:Tom 正在開發 iDempiere ERP 系統的增強模塊。他的開發環境配置了多個 API 憑證(WordPress、iDempiere REST API、數據庫密碼),都存儲在 ~/.claude/projects/-home-tom/wordpress-config.env。
問題:Claude 很有幫助,但有時會主動建議「讓我檢查 .env 文件確保格式正確」,然後就會讀取並回顯敏感信息。即使 Tom 多次在 CLAUDE.md 中寫「不要讀取 .env」,問題仍然偶爾發生。
解決方案:PreToolUse Hook
// settings.json 中的 Hook 配置
{
"hooks": {
"preToolUse": [
{
"id": "protect-env-files",
"description": "Block reading any .env, secrets, or credential files",
"toolName": "Read",
"condition": "filename.endsWith('.env') || filename.includes('secrets') || filename.includes('credentials') || filename.includes('config.env')",
"action": "block",
"message": "❌ Cannot read .env files or sensitive configuration. These contain API keys and passwords.\n\nIf you need to use an API, ask the user for the specific value you need, or use the 'source' command to load it into the environment.",
"logToFile": "~/.claude/logs/security-blocks.log"
}
]
}
}