qualia-framework 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/README.md +50 -0
  2. package/bin/cli.js +519 -0
  3. package/framework/agents/architecture-strategist.md +53 -0
  4. package/framework/agents/backend-agent.md +150 -0
  5. package/framework/agents/code-simplicity-reviewer.md +86 -0
  6. package/framework/agents/frontend-agent.md +111 -0
  7. package/framework/agents/kieran-typescript-reviewer.md +96 -0
  8. package/framework/agents/performance-oracle.md +111 -0
  9. package/framework/agents/qualia-codebase-mapper.md +760 -0
  10. package/framework/agents/qualia-debugger.md +1203 -0
  11. package/framework/agents/qualia-executor.md +881 -0
  12. package/framework/agents/qualia-integration-checker.md +423 -0
  13. package/framework/agents/qualia-phase-researcher.md +453 -0
  14. package/framework/agents/qualia-plan-checker.md +699 -0
  15. package/framework/agents/qualia-planner.md +1241 -0
  16. package/framework/agents/qualia-project-researcher.md +602 -0
  17. package/framework/agents/qualia-research-synthesizer.md +236 -0
  18. package/framework/agents/qualia-roadmapper.md +605 -0
  19. package/framework/agents/qualia-verifier.md +685 -0
  20. package/framework/agents/team-orchestrator.md +228 -0
  21. package/framework/agents/teams/full-stack-team.md +48 -0
  22. package/framework/agents/teams/optimize-team.md +53 -0
  23. package/framework/agents/teams/review-team.md +62 -0
  24. package/framework/agents/teams/ship-team.md +86 -0
  25. package/framework/agents/test-agent.md +182 -0
  26. package/framework/askpass.sh +2 -0
  27. package/framework/commands/design.md +53 -0
  28. package/framework/commands/quick-db.md +22 -0
  29. package/framework/config/retention.json +35 -0
  30. package/framework/core/PRINCIPLES.md +77 -0
  31. package/framework/hooks/auto-format.sh +45 -0
  32. package/framework/hooks/block-env-edit.sh +42 -0
  33. package/framework/hooks/branch-guard.sh +46 -0
  34. package/framework/hooks/confirm-delete.sh +56 -0
  35. package/framework/hooks/migration-validate.sh +68 -0
  36. package/framework/hooks/notification-speak.sh +15 -0
  37. package/framework/hooks/pre-commit.sh +80 -0
  38. package/framework/hooks/pre-compact.sh +55 -0
  39. package/framework/hooks/pre-deploy-gate.sh +151 -0
  40. package/framework/hooks/qualia-colors.sh +32 -0
  41. package/framework/hooks/retention-cleanup.sh +43 -0
  42. package/framework/hooks/save-session-state.sh +153 -0
  43. package/framework/hooks/session-context-loader.sh +28 -0
  44. package/framework/hooks/session-learn.sh +30 -0
  45. package/framework/knowledge/claudecode-bible.md +1384 -0
  46. package/framework/knowledge/client-prefs.md +22 -0
  47. package/framework/knowledge/common-fixes.md +25 -0
  48. package/framework/knowledge/deployment-map.md +35 -0
  49. package/framework/knowledge/email-signature.html +1 -0
  50. package/framework/knowledge/employees.md +8 -0
  51. package/framework/knowledge/learned-patterns.md +51 -0
  52. package/framework/knowledge/optimization-research-2026.md +137 -0
  53. package/framework/knowledge/qualia-context.md +67 -0
  54. package/framework/knowledge/supabase-patterns.md +50 -0
  55. package/framework/knowledge/voice-agent-patterns.md +46 -0
  56. package/framework/qualia-engine/VERSION +1 -0
  57. package/framework/qualia-engine/bin/qualia-tools.js +2160 -0
  58. package/framework/qualia-engine/bin/qualia-tools.test.js +1054 -0
  59. package/framework/qualia-engine/references/checkpoints.md +775 -0
  60. package/framework/qualia-engine/references/continuation-format.md +249 -0
  61. package/framework/qualia-engine/references/decimal-phase-calculation.md +65 -0
  62. package/framework/qualia-engine/references/design-quality.md +56 -0
  63. package/framework/qualia-engine/references/git-integration.md +254 -0
  64. package/framework/qualia-engine/references/git-planning-commit.md +50 -0
  65. package/framework/qualia-engine/references/model-profile-resolution.md +32 -0
  66. package/framework/qualia-engine/references/model-profiles.md +73 -0
  67. package/framework/qualia-engine/references/phase-argument-parsing.md +61 -0
  68. package/framework/qualia-engine/references/planning-config.md +195 -0
  69. package/framework/qualia-engine/references/questioning.md +141 -0
  70. package/framework/qualia-engine/references/tdd.md +263 -0
  71. package/framework/qualia-engine/references/ui-brand.md +160 -0
  72. package/framework/qualia-engine/references/verification-patterns.md +612 -0
  73. package/framework/qualia-engine/templates/DEBUG.md +159 -0
  74. package/framework/qualia-engine/templates/DESIGN.md +81 -0
  75. package/framework/qualia-engine/templates/UAT.md +247 -0
  76. package/framework/qualia-engine/templates/codebase/architecture.md +255 -0
  77. package/framework/qualia-engine/templates/codebase/concerns.md +310 -0
  78. package/framework/qualia-engine/templates/codebase/conventions.md +307 -0
  79. package/framework/qualia-engine/templates/codebase/integrations.md +280 -0
  80. package/framework/qualia-engine/templates/codebase/stack.md +186 -0
  81. package/framework/qualia-engine/templates/codebase/structure.md +285 -0
  82. package/framework/qualia-engine/templates/codebase/testing.md +480 -0
  83. package/framework/qualia-engine/templates/config.json +35 -0
  84. package/framework/qualia-engine/templates/context.md +283 -0
  85. package/framework/qualia-engine/templates/continue-here.md +78 -0
  86. package/framework/qualia-engine/templates/debug-subagent-prompt.md +91 -0
  87. package/framework/qualia-engine/templates/discovery.md +146 -0
  88. package/framework/qualia-engine/templates/milestone-archive.md +123 -0
  89. package/framework/qualia-engine/templates/milestone.md +115 -0
  90. package/framework/qualia-engine/templates/phase-prompt.md +567 -0
  91. package/framework/qualia-engine/templates/planner-subagent-prompt.md +117 -0
  92. package/framework/qualia-engine/templates/project.md +184 -0
  93. package/framework/qualia-engine/templates/projects/ai-agent.md +156 -0
  94. package/framework/qualia-engine/templates/projects/mobile-app.md +181 -0
  95. package/framework/qualia-engine/templates/projects/voice-agent.md +134 -0
  96. package/framework/qualia-engine/templates/projects/website.md +137 -0
  97. package/framework/qualia-engine/templates/requirements.md +231 -0
  98. package/framework/qualia-engine/templates/research-project/ARCHITECTURE.md +204 -0
  99. package/framework/qualia-engine/templates/research-project/FEATURES.md +147 -0
  100. package/framework/qualia-engine/templates/research-project/PITFALLS.md +200 -0
  101. package/framework/qualia-engine/templates/research-project/STACK.md +120 -0
  102. package/framework/qualia-engine/templates/research-project/SUMMARY.md +170 -0
  103. package/framework/qualia-engine/templates/research.md +552 -0
  104. package/framework/qualia-engine/templates/roadmap.md +202 -0
  105. package/framework/qualia-engine/templates/state.md +176 -0
  106. package/framework/qualia-engine/templates/summary-complex.md +59 -0
  107. package/framework/qualia-engine/templates/summary-minimal.md +41 -0
  108. package/framework/qualia-engine/templates/summary-standard.md +48 -0
  109. package/framework/qualia-engine/templates/summary.md +246 -0
  110. package/framework/qualia-engine/templates/user-setup.md +311 -0
  111. package/framework/qualia-engine/templates/verification-report.md +322 -0
  112. package/framework/qualia-engine/workflows/add-phase.md +179 -0
  113. package/framework/qualia-engine/workflows/add-todo.md +157 -0
  114. package/framework/qualia-engine/workflows/audit-milestone.md +241 -0
  115. package/framework/qualia-engine/workflows/check-todos.md +176 -0
  116. package/framework/qualia-engine/workflows/complete-milestone.md +858 -0
  117. package/framework/qualia-engine/workflows/diagnose-issues.md +219 -0
  118. package/framework/qualia-engine/workflows/discovery-phase.md +289 -0
  119. package/framework/qualia-engine/workflows/discuss-phase.md +534 -0
  120. package/framework/qualia-engine/workflows/execute-phase.md +559 -0
  121. package/framework/qualia-engine/workflows/execute-plan.md +438 -0
  122. package/framework/qualia-engine/workflows/help.md +470 -0
  123. package/framework/qualia-engine/workflows/insert-phase.md +220 -0
  124. package/framework/qualia-engine/workflows/list-phase-assumptions.md +178 -0
  125. package/framework/qualia-engine/workflows/map-codebase.md +327 -0
  126. package/framework/qualia-engine/workflows/new-milestone.md +363 -0
  127. package/framework/qualia-engine/workflows/new-project.md +1037 -0
  128. package/framework/qualia-engine/workflows/pause-work.md +122 -0
  129. package/framework/qualia-engine/workflows/plan-milestone-gaps.md +256 -0
  130. package/framework/qualia-engine/workflows/plan-phase.md +422 -0
  131. package/framework/qualia-engine/workflows/progress.md +354 -0
  132. package/framework/qualia-engine/workflows/quick.md +252 -0
  133. package/framework/qualia-engine/workflows/remove-phase.md +326 -0
  134. package/framework/qualia-engine/workflows/research-phase.md +74 -0
  135. package/framework/qualia-engine/workflows/resume-project.md +306 -0
  136. package/framework/qualia-engine/workflows/set-profile.md +80 -0
  137. package/framework/qualia-engine/workflows/settings.md +145 -0
  138. package/framework/qualia-engine/workflows/transition.md +556 -0
  139. package/framework/qualia-engine/workflows/update.md +197 -0
  140. package/framework/qualia-engine/workflows/verify-phase.md +195 -0
  141. package/framework/qualia-engine/workflows/verify-work.md +625 -0
  142. package/framework/rules/context7.md +11 -0
  143. package/framework/rules/deployment.md +29 -0
  144. package/framework/rules/frontend.md +33 -0
  145. package/framework/rules/security.md +12 -0
  146. package/framework/rules/speed.md +20 -0
  147. package/framework/scripts/__pycache__/say.cpython-314.pyc +0 -0
  148. package/framework/scripts/apply-retention.sh +120 -0
  149. package/framework/scripts/bootstrap-pop-os.sh +354 -0
  150. package/framework/scripts/claude-voice +13 -0
  151. package/framework/scripts/cleanup.sh +131 -0
  152. package/framework/scripts/cowork-mode.sh +141 -0
  153. package/framework/scripts/generate-project-claude-md.sh +153 -0
  154. package/framework/scripts/load-test-webhook.js +172 -0
  155. package/framework/scripts/say.py +236 -0
  156. package/framework/scripts/showcase-video-recorder/ffmpeg-builder.js +167 -0
  157. package/framework/scripts/showcase-video-recorder/playwright-helpers.js +216 -0
  158. package/framework/scripts/speak.py +55 -0
  159. package/framework/scripts/speak.sh +18 -0
  160. package/framework/scripts/status.sh +138 -0
  161. package/framework/scripts/sync-to-framework.sh +65 -0
  162. package/framework/scripts/voice-hotkey.py +227 -0
  163. package/framework/scripts/voice-input.sh +51 -0
  164. package/framework/skills/animate/SKILL.md +202 -0
  165. package/framework/skills/bolder/SKILL.md +144 -0
  166. package/framework/skills/browser-qa/SKILL.md +536 -0
  167. package/framework/skills/clarify/SKILL.md +179 -0
  168. package/framework/skills/colorize/SKILL.md +170 -0
  169. package/framework/skills/critique/SKILL.md +126 -0
  170. package/framework/skills/deep-research/SKILL.md +271 -0
  171. package/framework/skills/delight/SKILL.md +329 -0
  172. package/framework/skills/deploy/SKILL.md +261 -0
  173. package/framework/skills/deploy-verify/SKILL.md +377 -0
  174. package/framework/skills/deploy-verify/scripts/canary-check.sh +206 -0
  175. package/framework/skills/deploy-verify/scripts/check-console-errors.js +147 -0
  176. package/framework/skills/deploy-verify/scripts/check-cwv.js +139 -0
  177. package/framework/skills/deploy-verify/scripts/project-detect.sh +84 -0
  178. package/framework/skills/deploy-verify/scripts/verify.sh +548 -0
  179. package/framework/skills/design-quieter/SKILL.md +130 -0
  180. package/framework/skills/distill/SKILL.md +149 -0
  181. package/framework/skills/docs-lookup/SKILL.md +78 -0
  182. package/framework/skills/fcm-notifications/SKILL.md +125 -0
  183. package/framework/skills/financial-ledger/SKILL.md +1039 -0
  184. package/framework/skills/frontend-master/NOTICE.md +4 -0
  185. package/framework/skills/frontend-master/SKILL.md +127 -0
  186. package/framework/skills/frontend-master/reference/color-and-contrast.md +132 -0
  187. package/framework/skills/frontend-master/reference/interaction-design.md +123 -0
  188. package/framework/skills/frontend-master/reference/motion-design.md +99 -0
  189. package/framework/skills/frontend-master/reference/responsive-design.md +114 -0
  190. package/framework/skills/frontend-master/reference/spatial-design.md +100 -0
  191. package/framework/skills/frontend-master/reference/typography.md +131 -0
  192. package/framework/skills/frontend-master/reference/ux-writing.md +107 -0
  193. package/framework/skills/harden/SKILL.md +357 -0
  194. package/framework/skills/i18n-rtl/SKILL.md +752 -0
  195. package/framework/skills/learn/SKILL.md +71 -0
  196. package/framework/skills/memory/SKILL.md +50 -0
  197. package/framework/skills/mobile-expo/SKILL.md +864 -0
  198. package/framework/skills/mobile-expo/references/store-checklist.md +550 -0
  199. package/framework/skills/nestjs-backend/README.md +73 -0
  200. package/framework/skills/nestjs-backend/SKILL.md +446 -0
  201. package/framework/skills/nestjs-backend/references/templates.md +1173 -0
  202. package/framework/skills/normalize/SKILL.md +79 -0
  203. package/framework/skills/onboard/SKILL.md +242 -0
  204. package/framework/skills/polish/SKILL.md +209 -0
  205. package/framework/skills/pr/SKILL.md +66 -0
  206. package/framework/skills/qualia/SKILL.md +153 -0
  207. package/framework/skills/qualia-add-todo/SKILL.md +68 -0
  208. package/framework/skills/qualia-audit-milestone/SKILL.md +92 -0
  209. package/framework/skills/qualia-check-todos/SKILL.md +55 -0
  210. package/framework/skills/qualia-complete-milestone/SKILL.md +108 -0
  211. package/framework/skills/qualia-debug/SKILL.md +149 -0
  212. package/framework/skills/qualia-design/SKILL.md +203 -0
  213. package/framework/skills/qualia-discuss-phase/SKILL.md +72 -0
  214. package/framework/skills/qualia-execute-phase/SKILL.md +86 -0
  215. package/framework/skills/qualia-help/SKILL.md +67 -0
  216. package/framework/skills/qualia-idk/SKILL.md +352 -0
  217. package/framework/skills/qualia-list-phase-assumptions/SKILL.md +67 -0
  218. package/framework/skills/qualia-new-milestone/SKILL.md +72 -0
  219. package/framework/skills/qualia-new-project/SKILL.md +92 -0
  220. package/framework/skills/qualia-optimize/SKILL.md +417 -0
  221. package/framework/skills/qualia-pause-work/SKILL.md +96 -0
  222. package/framework/skills/qualia-plan-milestone-gaps/SKILL.md +57 -0
  223. package/framework/skills/qualia-plan-phase/SKILL.md +101 -0
  224. package/framework/skills/qualia-progress/SKILL.md +53 -0
  225. package/framework/skills/qualia-quick/SKILL.md +89 -0
  226. package/framework/skills/qualia-research-phase/SKILL.md +88 -0
  227. package/framework/skills/qualia-resume-work/SKILL.md +62 -0
  228. package/framework/skills/qualia-review/SKILL.md +263 -0
  229. package/framework/skills/qualia-start/SKILL.md +182 -0
  230. package/framework/skills/qualia-verify-work/SKILL.md +105 -0
  231. package/framework/skills/qualia-workflow/SKILL.md +130 -0
  232. package/framework/skills/rag/SKILL.md +750 -0
  233. package/framework/skills/responsive/SKILL.md +231 -0
  234. package/framework/skills/retro/SKILL.md +284 -0
  235. package/framework/skills/sakani-conventions/SKILL.md +136 -0
  236. package/framework/skills/sakani-conventions/evals/evals.json +23 -0
  237. package/framework/skills/sakani-conventions/references/entities.md +365 -0
  238. package/framework/skills/sakani-conventions/references/error-codes.md +95 -0
  239. package/framework/skills/seo-master/SKILL.md +490 -0
  240. package/framework/skills/seo-master/references/checklist.md +199 -0
  241. package/framework/skills/seo-master/references/structured-data.md +609 -0
  242. package/framework/skills/ship/SKILL.md +202 -0
  243. package/framework/skills/stack-researcher/SKILL.md +215 -0
  244. package/framework/skills/status/SKILL.md +154 -0
  245. package/framework/skills/status/scripts/health-check.sh +562 -0
  246. package/framework/skills/subscription-payments/SKILL.md +250 -0
  247. package/framework/skills/supabase/SKILL.md +973 -0
  248. package/framework/skills/supabase/references/templates.md +159 -0
  249. package/framework/skills/team/SKILL.md +67 -0
  250. package/framework/skills/test-runner/SKILL.md +202 -0
  251. package/framework/skills/voice-agent/SKILL.md +407 -0
  252. package/framework/skills/zoho-workflow/SKILL.md +51 -0
  253. package/framework/statusline-command.sh +117 -0
  254. package/package.json +24 -0
  255. package/profiles/fawzi.json +16 -0
  256. package/profiles/hasan.json +16 -0
  257. package/profiles/moayad.json +16 -0
  258. package/templates/CLAUDE-owner.md +52 -0
  259. package/templates/CLAUDE.md.hbs +58 -0
  260. package/templates/env.claude.template +12 -0
  261. package/templates/settings.json +141 -0
@@ -0,0 +1,1384 @@
1
+ # The Claude Code Bible
2
+
3
+ > Comprehensive reference distilled from [luongnv89/claude-howto](https://github.com/luongnv89/claude-howto) (2.9k stars, v2.2.0, March 2026). Every file studied. Every pattern extracted.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Architecture Overview](#architecture-overview)
10
+ 2. [Slash Commands](#1-slash-commands)
11
+ 3. [Memory System](#2-memory-system)
12
+ 4. [Skills](#3-skills)
13
+ 5. [Subagents](#4-subagents)
14
+ 6. [MCP Protocol](#5-mcp-protocol)
15
+ 7. [Hooks](#6-hooks)
16
+ 8. [Plugins](#7-plugins)
17
+ 9. [Checkpoints](#8-checkpoints)
18
+ 10. [Advanced Features](#9-advanced-features)
19
+ 11. [CLI Reference](#10-cli-reference)
20
+ 12. [Feature Selection Guide](#feature-selection-guide)
21
+ 13. [Configuration Examples](#configuration-examples)
22
+ 14. [Clean Code Rules](#clean-code-rules)
23
+ 15. [Qualia Gap Analysis](#qualia-gap-analysis)
24
+
25
+ ---
26
+
27
+ ## Architecture Overview
28
+
29
+ Claude Code has 7 extension mechanisms, each serving a distinct role:
30
+
31
+ | Feature | Invocation | Persistence | Scope | Best For |
32
+ |---------|-----------|------------|-------|----------|
33
+ | **Slash Commands** | Manual (`/cmd`) | Session only | Single task | Quick shortcuts |
34
+ | **Memory** | Auto-loaded | Cross-session | User/team context | Persistent standards |
35
+ | **Skills** | Auto-invoked | Filesystem | Reusable expertise | Automated workflows |
36
+ | **Subagents** | Auto-delegated | Isolated context | Specialized tasks | Task distribution |
37
+ | **MCP** | Auto-queried | Real-time | External data | Live integrations |
38
+ | **Hooks** | Event-triggered | Settings-based | Automation | Quality gates |
39
+ | **Plugins** | One-command install | Bundled | All-in-one | Team distribution |
40
+
41
+ ### Session Lifecycle
42
+
43
+ ```
44
+ Session Start
45
+ -> Load Memory (7 tiers, highest priority first)
46
+ -> Discover Skills (metadata only, ~100 tokens each)
47
+ -> Register Slash Commands
48
+ -> Connect MCP Servers
49
+ -> Ready for User Interaction
50
+ -> /cmd triggers Slash Command
51
+ -> Request triggers Skill auto-invoke
52
+ -> Query triggers MCP data fetch
53
+ -> Complex task triggers Subagent delegation
54
+ -> Tool use triggers Hook events
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 1. Slash Commands
60
+
61
+ ### What They Are
62
+ Markdown files in `.claude/commands/` (project) or `~/.claude/commands/` (user) that define reusable prompt templates. Invoked with `/command-name`.
63
+
64
+ > **Note:** Custom commands are being migrated to Skills (`.claude/skills/`). Commands still work but Skills are recommended.
65
+
66
+ ### File Structure
67
+
68
+ ```yaml
69
+ ---
70
+ description: What this command does (required for auto-discovery)
71
+ allowed-tools: Bash(git add:*), Bash(npm test:*) # Optional tool whitelist
72
+ argument-hint: [message] # Optional autocomplete hint
73
+ name: Human-readable name # Optional
74
+ tags: testing, coverage # Optional categorization
75
+ ---
76
+
77
+ # Command Title
78
+
79
+ Instructions for Claude as markdown...
80
+
81
+ Dynamic context: !`git status` # Shell output injected before prompt
82
+ Arguments: $ARGUMENTS or $0, $1 # User-provided args
83
+ File refs: @path/to/file # Include file contents
84
+ ```
85
+
86
+ ### Key Patterns from the Repo
87
+
88
+ **Minimal command** (analysis only):
89
+ ```markdown
90
+ ---
91
+ description: Analyze code for performance issues
92
+ ---
93
+ # Code Optimization
94
+ Review for: 1. O(n^2) ops 2. Memory leaks 3. Algorithm improvements
95
+ Format: Severity | Location | Explanation | Fix with code
96
+ ```
97
+
98
+ **Rich command** (with dynamic context + tools):
99
+ ```markdown
100
+ ---
101
+ allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*), Bash(git diff:*)
102
+ argument-hint: [message]
103
+ description: Create a git commit with context
104
+ ---
105
+ ## Context
106
+ - Current git status: !`git status`
107
+ - Current git diff: !`git diff HEAD`
108
+ - Current branch: !`git branch --show-current`
109
+
110
+ ## Task
111
+ If message provided: $ARGUMENTS
112
+ Otherwise: analyze changes and create conventional commit
113
+ ```
114
+
115
+ **Safety-gated command** (confirmation required):
116
+ ```markdown
117
+ ---
118
+ description: Stage all, commit, push (use with caution)
119
+ allowed-tools: Bash(git add:*), Bash(git push:*), ...
120
+ ---
121
+ # Safety Checks
122
+ - Scan for secrets (.env, *.key, *.pem, AKIA patterns)
123
+ - Check for large files (>10MB)
124
+ - Warn if on main/master
125
+ - Present summary and WAIT for explicit "yes"
126
+ ```
127
+
128
+ ### 55+ Built-in Commands
129
+
130
+ Key ones: `/help`, `/clear`, `/compact`, `/config`, `/cost`, `/diff`, `/doctor`, `/export`, `/model`, `/plan`, `/rewind`, `/resume`, `/rename`, `/fork`, `/fast`, `/vim`, `/voice`, `/chrome`, `/tasks`, `/todo`, `/mcp`, `/skills`, `/agents`, `/hooks`, `/plugin`, `/permissions`, `/sandbox`, `/remote-control`, `/desktop`, `/teleport`, `/keybindings`, `/statusline`, `/theme`, `/upgrade`
131
+
132
+ ### 5 Bundled Skills (Act Like Commands)
133
+
134
+ | Skill | Command | Purpose |
135
+ |-------|---------|---------|
136
+ | Simplify | `/simplify` | Review code for quality and simplification |
137
+ | Batch | `/batch` | Run prompts on multiple files |
138
+ | Debug | `/debug` | Systematic debugging with root cause analysis |
139
+ | Loop | `/loop` | Schedule recurring tasks on a timer |
140
+ | Claude API | `/claude-api` | Build apps with the Anthropic API |
141
+
142
+ ---
143
+
144
+ ## 2. Memory System
145
+
146
+ ### 8-Tier Hierarchy (Highest to Lowest Priority)
147
+
148
+ | Tier | Scope | Location | Shared? | Best For |
149
+ |------|-------|----------|---------|----------|
150
+ | 1 | Managed Policy | `/etc/claude-code/CLAUDE.md` (Linux) | Organization | Compliance, security |
151
+ | 1.5 | Managed Drop-ins | `managed-settings.d/` alongside policy | Organization | Modular org policies |
152
+ | 2 | Project Memory | `./CLAUDE.md` or `./.claude/CLAUDE.md` | Team (git) | Team standards, architecture |
153
+ | 3 | Project Rules | `.claude/rules/*.md` | Team (git) | Modular project conventions |
154
+ | 4 | User Memory | `~/.claude/CLAUDE.md` | Individual | Personal preferences |
155
+ | 5 | User Rules | `~/.claude/rules/*.md` | Individual | Personal rule modules |
156
+ | 6 | Local Memory | `./CLAUDE.local.md` | Individual (gitignored) | Machine-specific overrides |
157
+ | 7 | Auto Memory | `~/.claude/projects/<project>/memory/` | Individual | Learned preferences |
158
+
159
+ ### Memory Commands
160
+
161
+ | Command | Purpose |
162
+ |---------|---------|
163
+ | `/init` | Create CLAUDE.md template |
164
+ | `/memory` | Open memory files in editor |
165
+ | `#` prefix | Quick single-line memory addition |
166
+ | `@path/to/file` | Import external content |
167
+
168
+ ### Project Memory Template (./CLAUDE.md)
169
+
170
+ ```markdown
171
+ # Project Configuration
172
+
173
+ ## Overview
174
+ - **Name**: Project Name
175
+ - **Stack**: Next.js, TypeScript, Supabase
176
+ - **Team**: 3 developers
177
+
178
+ ## Architecture
179
+ @docs/architecture.md
180
+ @docs/api-standards.md
181
+
182
+ ## Standards
183
+ ### Naming: Files=kebab-case, Classes=PascalCase, Functions=camelCase, DB=snake_case
184
+ ### Git: feature/description branches, conventional commits, PR required
185
+ ### Testing: 80% coverage minimum, Jest for unit, Cypress for E2E
186
+
187
+ ## Common Commands
188
+ | Command | Purpose |
189
+ |---------|---------|
190
+ | `npm run dev` | Dev server |
191
+ | `npm test` | Test suite |
192
+
193
+ ## Known Issues
194
+ - Issue description + workaround
195
+ ```
196
+
197
+ ### Directory-Specific Memory
198
+
199
+ Place `CLAUDE.md` inside subdirectories for module-specific rules:
200
+
201
+ ```markdown
202
+ # ./src/api/CLAUDE.md
203
+ # API Module Standards (overrides root CLAUDE.md for /src/api/)
204
+
205
+ ### Request Validation: Use Zod, return 400 with field-level errors
206
+ ### Auth: JWT in Authorization header, 24h expiry, refresh tokens
207
+ ### Response Format: { success, data, timestamp, version }
208
+ ### Pagination: Cursor-based (not offset), max 100, default 20
209
+ ### Rate Limiting: 1000/hr authenticated, 100/hr public, 429 + retry-after
210
+ ```
211
+
212
+ ### Project Rules with Path Scoping
213
+
214
+ ```yaml
215
+ # .claude/rules/api-standards.md
216
+ ---
217
+ paths: src/api/**/*.ts
218
+ ---
219
+ Use Zod for all request validation.
220
+ Return structured error responses with error codes.
221
+ ```
222
+
223
+ ### Key Settings
224
+
225
+ - `claudeMdExcludes`: Skip irrelevant CLAUDE.md files in monorepos (glob patterns)
226
+ - `autoMemoryDirectory`: Custom auto-memory location (v2.1.74+)
227
+ - `CLAUDE_CODE_DISABLE_AUTO_MEMORY`: Disable auto-memory
228
+ - `--add-dir`: Load CLAUDE.md from additional directories
229
+
230
+ ### Best Practices
231
+
232
+ - Be specific: "Use 2-space indentation" not "follow best practices"
233
+ - Use `@imports` to reference docs instead of duplicating
234
+ - Keep files under 500 lines
235
+ - NEVER store secrets, API keys, or PII
236
+ - Review periodically — stale memory causes confusion
237
+ - Right level for the right concern (security at managed, team at project, personal at user)
238
+
239
+ ---
240
+
241
+ ## 3. Skills
242
+
243
+ ### What They Are
244
+ Auto-invoked capabilities packaged as folders with instructions, scripts, and templates. Claude detects and uses relevant skills automatically based on the `description` field.
245
+
246
+ ### Progressive Disclosure (3 Levels)
247
+
248
+ | Level | What Loads | When | Token Cost |
249
+ |-------|-----------|------|------------|
250
+ | L1: Metadata | `name` + `description` from frontmatter | Always at startup | ~100 tokens/skill |
251
+ | L2: Instructions | SKILL.md body | When triggered | <5k tokens |
252
+ | L3: Resources | Scripts, templates, references | Executed via bash on demand | 0 (not in context) |
253
+
254
+ ### SKILL.md Format
255
+
256
+ ```yaml
257
+ ---
258
+ name: skill-name # Required, lowercase-hyphenated
259
+ description: What + When to use # Required, triggers auto-invocation
260
+ argument-hint: [args] # Optional autocomplete
261
+ allowed-tools: Read, Grep, Bash # Optional tool restriction
262
+ model: sonnet # Optional model override
263
+ effort: high # Optional: low/medium/high/max
264
+ shell: bash # Optional: bash/powershell
265
+ context: fork # Optional: run in isolated subagent
266
+ agent: Explore # Optional: subagent type
267
+ disable-model-invocation: true # Optional: only user can invoke
268
+ user-invocable: false # Optional: only Claude can invoke
269
+ hooks: # Optional: skill-scoped hooks
270
+ PreToolUse:
271
+ - matcher: Bash
272
+ command: validate.sh
273
+ ---
274
+
275
+ # Skill Title
276
+
277
+ ## Instructions (structured guidance)
278
+ ## Templates/Examples (inline or referenced)
279
+ ## References to supporting files
280
+ ```
281
+
282
+ ### Invocation Control
283
+
284
+ | Config | User Can Invoke | Claude Can Invoke |
285
+ |--------|----------------|-------------------|
286
+ | (default) | Yes | Yes |
287
+ | `disable-model-invocation: true` | Yes | No |
288
+ | `user-invocable: false` | No | Yes |
289
+
290
+ ### Directory Structure
291
+
292
+ ```
293
+ my-skill/
294
+ ├── SKILL.md # Instructions (required, <500 lines)
295
+ ├── scripts/ # Python/bash helpers (Level 3, executed not loaded)
296
+ ├── templates/ # Output templates Claude fills in
297
+ ├── references/ # Domain knowledge docs
298
+ └── examples/ # Example outputs
299
+ ```
300
+
301
+ ### Skill Locations
302
+
303
+ | Type | Location | Scope |
304
+ |------|----------|-------|
305
+ | Enterprise | Managed settings | All org users |
306
+ | Personal | `~/.claude/skills/<name>/SKILL.md` | Individual |
307
+ | Project | `.claude/skills/<name>/SKILL.md` | Team (git) |
308
+ | Plugin | `<plugin>/skills/<name>/SKILL.md` | Where enabled |
309
+
310
+ ### String Substitutions
311
+
312
+ - `$ARGUMENTS` — all user arguments
313
+ - `$ARGUMENTS[0]`, `$0`, `$1` — positional args
314
+ - `${CLAUDE_SESSION_ID}` — current session
315
+ - `${CLAUDE_SKILL_DIR}` — skill directory path
316
+ - `` !`command` `` — shell output injected before prompt
317
+
318
+ ### Example Skills from the Repo
319
+
320
+ **Code Review Skill** — 4 review dimensions (Security, Performance, Quality, Maintainability), Python scripts for cyclomatic/cognitive complexity and maintainability index, checklists and finding templates.
321
+
322
+ **Brand Voice Skill** (`user-invocable: false`) — Background knowledge Claude applies silently when generating public content. Tone guidelines, approved/banned terms, writing rules.
323
+
324
+ **Refactor Skill** — 6-phase Martin Fowler methodology. Safety rules: never refactor without tests, never combine changes, never mix refactoring with feature development.
325
+
326
+ **Claude-MD Skill** — Golden rules: <300 lines, universal applicability, never auto-generate, craft manually. Target ~150-200 instructions.
327
+
328
+ ### Script Integration Pattern
329
+
330
+ Scripts are Level 3 resources — never loaded into context, executed via bash:
331
+
332
+ ```python
333
+ # scripts/analyze-complexity.py
334
+ # Supports Python, JavaScript, TypeScript
335
+ # Modes: single file, before/after comparison, directory scan
336
+ # Outputs: cyclomatic complexity, cognitive complexity, maintainability index
337
+ # CLI: python analyze-complexity.py file.py --verbose --json
338
+ ```
339
+
340
+ ```python
341
+ # scripts/detect-smells.py
342
+ # Detects 14 smell types: Long Method, Long Parameters, Duplicate Code,
343
+ # Large Class, Dead Code, Complex Conditionals, Magic Numbers, Feature Envy,
344
+ # Excessive Comments, Deep Nesting, Primitive Obsession, Data Clumps,
345
+ # Switch Statements, Message Chains
346
+ # CLI: python detect-smells.py src/ --dir --verbose
347
+ ```
348
+
349
+ ---
350
+
351
+ ## 4. Subagents
352
+
353
+ ### What They Are
354
+ Specialized AI assistants with isolated context windows, customized system prompts, and controlled tool access. Claude auto-delegates to them for specialized tasks.
355
+
356
+ ### Agent Definition Format
357
+
358
+ ```yaml
359
+ # .claude/agents/agent-name.md
360
+ ---
361
+ name: agent-name # Required, unique identifier
362
+ description: What + when to use # Required. Add "Use PROACTIVELY" for auto-trigger
363
+ tools: Read, Grep, Glob, Bash # Optional (omit = inherit all)
364
+ disallowedTools: Write, Edit # Optional explicit blocks
365
+ model: inherit # Optional: sonnet/opus/haiku/inherit
366
+ permissionMode: default # Optional: default/acceptEdits/dontAsk/plan
367
+ maxTurns: 20 # Optional turn limit
368
+ effort: high # Optional: low/medium/high/max
369
+ isolation: worktree # Optional: git worktree isolation
370
+ background: true # Optional: run as background task
371
+ memory: project # Optional: user/project/local
372
+ skills: [code-review] # Optional: preload specific skills
373
+ mcpServers: [github] # Optional: available MCP servers
374
+ initialPrompt: "Start by..." # Optional: auto-submitted first turn
375
+ hooks: # Optional: agent-scoped hooks
376
+ PreToolUse: [...]
377
+ ---
378
+
379
+ # Agent System Prompt
380
+
381
+ Role declaration, invocation steps, domain knowledge, output format, examples.
382
+ ```
383
+
384
+ ### Agent Locations (Priority Order)
385
+
386
+ 1. CLI-defined (`--agents` flag, JSON, session-scoped)
387
+ 2. Project-level (`.claude/agents/`)
388
+ 3. User-level (`~/.claude/agents/`)
389
+ 4. Plugin-level (plugin `agents/` directory)
390
+
391
+ ### 6 Built-in Subagents
392
+
393
+ | Agent | Model | Tools | Purpose |
394
+ |-------|-------|-------|---------|
395
+ | general-purpose | Inherits | All | Multi-step tasks, research |
396
+ | Plan | Inherits | Read, Glob, Grep, Bash | Architecture planning |
397
+ | Explore | Haiku 4.5 | Read, Glob, Grep | Quick codebase searches |
398
+ | Bash | Inherits | Bash | Git operations, terminal tasks |
399
+ | statusline-setup | Sonnet 4.6 | Bash, Read, Write | Status line config |
400
+ | Claude Code Guide | Haiku 4.5 | Read, Glob, Grep | Help and documentation |
401
+
402
+ ### Principle of Least Privilege (Tool Access)
403
+
404
+ | Agent Type | Tools | Rationale |
405
+ |------------|-------|-----------|
406
+ | Security reviewer | Read, Grep | Read-only — can't break anything |
407
+ | Documentation writer | Read, Write, Grep | Write docs, not execute code |
408
+ | Test engineer | Read, Write, Bash, Grep | Write tests AND run them |
409
+ | Code reviewer | Read, Grep, Glob, Bash | Search broadly, run git diff |
410
+ | Debugger | Read, Edit, Bash, Grep, Glob | Needs Edit to fix bugs |
411
+ | Implementation agent | Read, Write, Edit, Bash, Grep, Glob | Full access for feature work |
412
+
413
+ ### Auto-Delegation Keywords
414
+
415
+ Include "Use PROACTIVELY" in `description` to auto-trigger:
416
+ - `code-reviewer`: "after writing or modifying code"
417
+ - `test-engineer`: "when new features are implemented"
418
+ - `debugger`: "when encountering any issues"
419
+ - `clean-code-reviewer`: "after writing code"
420
+ - `data-scientist`: "for data analysis tasks"
421
+
422
+ ### System Prompt Template
423
+
424
+ 1. **Role declaration** — "You are a [role] specializing in [domain]"
425
+ 2. **Invocation steps** — numbered list of what to do (3-6 steps)
426
+ 3. **Domain knowledge** — priorities, checklists, best practices
427
+ 4. **Output format** — structured fields per finding (Severity, Category, Location, Description, Fix)
428
+ 5. **Example** — concrete example of expected output
429
+
430
+ ### Context Management
431
+
432
+ ```
433
+ Main Agent Context (full window)
434
+ ├─> Subagent 1 (clean slate, isolated)
435
+ ├─> Subagent 2 (clean slate, isolated)
436
+ └─> Subagent 3 (clean slate, isolated)
437
+ Results only flow back to main agent.
438
+ ```
439
+
440
+ ### When to Use Subagents
441
+
442
+ | Scenario | Use Subagent? | Why |
443
+ |----------|--------------|-----|
444
+ | Complex multi-step feature | Yes | Separate concerns, prevent context pollution |
445
+ | Parallel task execution | Yes | Each gets own context |
446
+ | Specialized expertise | Yes | Custom system prompts |
447
+ | Long-running analysis | Yes | Prevents main context exhaustion |
448
+ | Quick code review | No | Unnecessary overhead |
449
+ | Single simple task | No | Adds latency |
450
+
451
+ ### Advanced Features
452
+
453
+ - **Agent Teams** (experimental): 3-5 teammates with shared task list + mailbox
454
+ - **Resumable agents**: Continue via `SendMessage(to: agent_id)`
455
+ - **Background agents**: `Ctrl+B` to background, `Ctrl+F` to kill
456
+ - **Worktree isolation**: `isolation: worktree` for safe parallel branch work
457
+ - **Persistent memory**: Agents can read MEMORY.md via `memory:` frontmatter
458
+ - **Transcripts**: Stored at `~/.claude/projects/{project}/{session}/subagents/agent-{id}.jsonl`
459
+
460
+ ---
461
+
462
+ ## 5. MCP Protocol
463
+
464
+ ### What It Is
465
+ Model Context Protocol — standardized way for Claude to access external tools, APIs, and real-time data. Unlike Memory (static), MCP provides live data access.
466
+
467
+ ### Configuration
468
+
469
+ **Project scope** (`.mcp.json`):
470
+ ```json
471
+ {
472
+ "mcpServers": {
473
+ "github": {
474
+ "command": "npx",
475
+ "args": ["-y", "@modelcontextprotocol/server-github"],
476
+ "env": {
477
+ "GITHUB_TOKEN": "${GITHUB_TOKEN}"
478
+ }
479
+ }
480
+ }
481
+ }
482
+ ```
483
+
484
+ **User scope** (`~/.claude.json`): Same format, applies to all projects.
485
+
486
+ ### Common MCP Servers
487
+
488
+ | Server | Command | Auth |
489
+ |--------|---------|------|
490
+ | GitHub | `npx @modelcontextprotocol/server-github` | `${GITHUB_TOKEN}` |
491
+ | PostgreSQL | `npx @modelcontextprotocol/server-postgres` | `${DATABASE_URL}` |
492
+ | Filesystem | `npx @modelcontextprotocol/server-filesystem /path` | OS permissions |
493
+ | Slack | `npx @modelcontextprotocol/server-slack` | `${SLACK_TOKEN}` |
494
+ | Context7 | Built-in | None |
495
+
496
+ ### Multi-Server Config
497
+
498
+ ```json
499
+ {
500
+ "mcpServers": {
501
+ "github": { "command": "npx", "args": ["@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" } },
502
+ "database": { "command": "npx", "args": ["@modelcontextprotocol/server-database"], "env": { "DATABASE_URL": "${DATABASE_URL}" } },
503
+ "slack": { "command": "npx", "args": ["@modelcontextprotocol/server-slack"], "env": { "SLACK_TOKEN": "${SLACK_TOKEN}" } },
504
+ "filesystem": { "command": "npx", "args": ["@modelcontextprotocol/server-filesystem", "/home/user/projects"] }
505
+ }
506
+ }
507
+ ```
508
+
509
+ ### Transport Protocols
510
+
511
+ | Transport | Use Case |
512
+ |-----------|----------|
513
+ | HTTP | Recommended for remote servers |
514
+ | Stdio | Local via `npx` (most examples) |
515
+ | WebSocket | Persistent bidirectional connections |
516
+ | SSE | Deprecated |
517
+
518
+ ### CLI Commands
519
+
520
+ ```bash
521
+ claude mcp add github -- npx -y @modelcontextprotocol/server-github
522
+ claude mcp list
523
+ claude mcp remove github
524
+ claude mcp reset-project-choices
525
+ claude mcp serve # Run Claude Code itself as MCP server
526
+ ```
527
+
528
+ ### Key Limits
529
+
530
+ - Tool descriptions: 2KB per server
531
+ - Output warning: 10,000 tokens
532
+ - Output max: 25,000 tokens (configurable via `MAX_MCP_OUTPUT_TOKENS`)
533
+ - Disk persistence: 50,000 chars
534
+ - Auto tool search when definitions exceed 10% of context (requires Sonnet 4+ or Opus 4+)
535
+
536
+ ### MCP Resources and Prompts
537
+
538
+ - Resources: `@server-name:protocol://resource/path` — access MCP resources
539
+ - Prompts: `/mcp__<server>__<prompt>` — invoke MCP prompt templates
540
+ - MCPorter: Compose MCP tools into higher-level operations
541
+
542
+ ### Security Best Practices
543
+
544
+ - ALWAYS use `${VAR}` interpolation for secrets — never hardcode
545
+ - Scope filesystem access to specific directories
546
+ - Rotate tokens monthly
547
+ - Grant minimum permissions
548
+ - Keep `.mcp.json` in version control (safe with interpolation)
549
+ - Monitor all MCP requests
550
+
551
+ ### MCP vs Memory Decision
552
+
553
+ ```
554
+ Need external data? -> No -> Use Memory
555
+ -> Yes -> Changes frequently? -> No -> Use Memory
556
+ -> Yes -> Use MCP
557
+ ```
558
+
559
+ ---
560
+
561
+ ## 6. Hooks
562
+
563
+ ### What They Are
564
+ Event-driven automation that executes shell commands, HTTP requests, prompts, or subagents in response to Claude Code events. Configured in settings.json.
565
+
566
+ ### 25 Hook Events (4 Categories)
567
+
568
+ **Tool Hooks:**
569
+ | Event | Trigger | Common Use |
570
+ |-------|---------|-----------|
571
+ | PreToolUse | Before any tool runs | Validation, approval gates |
572
+ | PostToolUse | After tool succeeds | Formatting, notifications |
573
+ | PostToolUseFailure | Tool execution fails | Error handling, logging |
574
+ | PermissionRequest | Permission dialog shown | Auto-approve/deny |
575
+
576
+ **Session Hooks:**
577
+ | Event | Trigger | Common Use |
578
+ |-------|---------|-----------|
579
+ | SessionStart | Session begins/resumes | Environment setup |
580
+ | SessionEnd | Session terminates | Cleanup, save state |
581
+ | Stop | Claude finishes responding | Summary generation |
582
+ | StopFailure | API error ends turn | Error recovery |
583
+ | SubagentStart | Subagent spawned | Context injection |
584
+ | SubagentStop | Subagent finishes | Result validation |
585
+ | InstructionsLoaded | CLAUDE.md loaded | Custom handling |
586
+
587
+ **Task Hooks:**
588
+ | Event | Trigger | Common Use |
589
+ |-------|---------|-----------|
590
+ | UserPromptSubmit | User sends message | Input validation |
591
+ | TaskCompleted | Task marked complete | Post-task processing |
592
+ | TaskCreated | Task created | Task tracking |
593
+ | TeammateIdle | Agent teammate idle | Work distribution |
594
+
595
+ **Lifecycle Hooks:**
596
+ | Event | Trigger | Common Use |
597
+ |-------|---------|-----------|
598
+ | ConfigChange | Settings modified | Validation |
599
+ | CwdChanged | Directory changed | Directory-specific setup |
600
+ | FileChanged | Watched file changes | Rebuild triggers |
601
+ | PreCompact | Before compaction | State preservation |
602
+ | PostCompact | After compaction | Post-compact actions |
603
+ | WorktreeCreate | Worktree created | Environment setup |
604
+ | WorktreeRemove | Worktree removed | Cleanup |
605
+ | Elicitation | MCP requests input | Input validation |
606
+ | ElicitationResult | User responds | Response processing |
607
+ | Notification | Notification sent | External alerts |
608
+
609
+ ### 4 Hook Types
610
+
611
+ | Type | How It Works | Best For |
612
+ |------|-------------|----------|
613
+ | **Command** | Shell command, JSON via stdin | Deterministic checks |
614
+ | **HTTP** | POST JSON to webhook URL | External integrations |
615
+ | **Prompt** | LLM-evaluated prompt | Intelligent decisions (Stop/SubagentStop) |
616
+ | **Agent** | Spawn subagent with tools | Multi-step verification |
617
+
618
+ ### Hook Configuration
619
+
620
+ ```json
621
+ // ~/.claude/settings.json or .claude/settings.json
622
+ {
623
+ "hooks": {
624
+ "PreToolUse": [
625
+ {
626
+ "matcher": "Bash",
627
+ "hooks": [
628
+ {
629
+ "type": "command",
630
+ "command": "~/.claude/hooks/validate-bash.sh"
631
+ }
632
+ ]
633
+ }
634
+ ],
635
+ "PostToolUse": [
636
+ {
637
+ "matcher": "Write",
638
+ "hooks": [
639
+ {
640
+ "type": "command",
641
+ "command": "prettier --write $CLAUDE_FILE_PATH"
642
+ }
643
+ ]
644
+ }
645
+ ]
646
+ }
647
+ }
648
+ ```
649
+
650
+ ### Hook Input/Output Contract
651
+
652
+ **Input (stdin JSON):**
653
+ ```json
654
+ {
655
+ "session_id": "...",
656
+ "transcript_path": "...",
657
+ "cwd": "...",
658
+ "permission_mode": "default",
659
+ "hook_event_name": "PreToolUse",
660
+ "tool_name": "Bash",
661
+ "tool_input": { "command": "git commit -m 'fix'" },
662
+ "tool_use_id": "...",
663
+ "agent_id": "...",
664
+ "agent_type": "..."
665
+ }
666
+ ```
667
+
668
+ **Output (stdout JSON):**
669
+ ```json
670
+ {
671
+ "continue": true,
672
+ "stopReason": "blocked by policy",
673
+ "suppressOutput": false,
674
+ "systemMessage": "Additional context for Claude",
675
+ "hookSpecificOutput": {
676
+ "permissionDecision": "allow",
677
+ "updatedInput": { "command": "modified command" },
678
+ "additionalContext": "extra info"
679
+ }
680
+ }
681
+ ```
682
+
683
+ **Exit Codes:**
684
+ | Code | Meaning | Behavior |
685
+ |------|---------|----------|
686
+ | 0 | Success | Continue, parse stdout JSON |
687
+ | 2 | Blocking error | Block operation, show stderr as error |
688
+ | Other | Non-blocking error | Continue, show stderr in verbose |
689
+
690
+ ### Example Hook Scripts
691
+
692
+ **Auto-format on write** (PostToolUse:Write):
693
+ ```bash
694
+ #!/bin/bash
695
+ FILE=$1
696
+ case "$FILE" in
697
+ *.js|*.jsx|*.ts|*.tsx) command -v prettier &>/dev/null && prettier --write "$FILE" ;;
698
+ *.py) command -v black &>/dev/null && black "$FILE" ;;
699
+ *.go) command -v gofmt &>/dev/null && gofmt -w "$FILE" ;;
700
+ esac
701
+ exit 0
702
+ ```
703
+
704
+ **Security scan on write** (PostToolUse:Write):
705
+ ```bash
706
+ #!/bin/bash
707
+ FILE=$1
708
+ # Check for hardcoded passwords, API keys, private keys, AWS keys
709
+ grep -qE "(password|passwd|pwd)\s*=\s*['\"][^'\"]+['\"]" "$FILE" && echo "WARNING: Hardcoded password"
710
+ grep -qE "AKIA[0-9A-Z]{16}" "$FILE" && echo "WARNING: AWS access key"
711
+ grep -q "BEGIN.*PRIVATE KEY" "$FILE" && echo "WARNING: Private key"
712
+ exit 0 # Warn only, don't block
713
+ ```
714
+
715
+ **Pre-commit test runner** (PreToolUse:Bash):
716
+ ```bash
717
+ #!/bin/bash
718
+ # Auto-detect project type and run tests
719
+ [ -f "package.json" ] && npm test || true
720
+ [ -f "pytest.ini" ] && pytest || true
721
+ [ -f "go.mod" ] && go test ./... || true
722
+ ```
723
+
724
+ **Context tracker** (UserPromptSubmit + Stop — dual-hook pair):
725
+ ```python
726
+ #!/usr/bin/env python3
727
+ # Snapshots token count on UserPromptSubmit, calculates delta on Stop
728
+ # Uses tiktoken with p50k_base for ~90-95% accuracy
729
+ # Reports to stderr: "Context (tiktoken): ~45,000 tokens (35.2% used)"
730
+ ```
731
+
732
+ **Prompt validator** (UserPromptSubmit):
733
+ ```bash
734
+ #!/bin/bash
735
+ PROMPT=$(cat)
736
+ # Block dangerous patterns: rm -rf /, drop database, format disk
737
+ # Gate production deploys behind .deployment-approved file
738
+ ```
739
+
740
+ ### Best Practices
741
+
742
+ - Keep hooks fast (<1 second)
743
+ - Use exit code 2 for blocking, 0 for success
744
+ - Output diagnostics to stderr (stdout reserved for JSON)
745
+ - Use `command -v` to check optional tool availability
746
+ - Never hardcode credentials — use env vars
747
+ - Test independently: `echo '{"tool_name":"Bash"}' | python3 hook.py`
748
+ - Hook pairs (UserPromptSubmit + Stop) enable before/after measurements
749
+
750
+ ---
751
+
752
+ ## 7. Plugins
753
+
754
+ ### What They Are
755
+ Bundled collections of slash commands, subagents, skills, MCP servers, hooks, LSP configs, and settings that install with a single command. The highest-level extension mechanism.
756
+
757
+ ### Plugin Structure
758
+
759
+ ```
760
+ my-plugin/
761
+ ├── .claude-plugin/
762
+ │ └── plugin.json # Manifest (required)
763
+ ├── commands/ # Slash commands as .md
764
+ ├── agents/ # Subagent definitions as .md
765
+ ├── skills/ # SKILL.md files
766
+ ├── hooks/ # hooks.json or JS files
767
+ ├── .mcp.json # MCP server configs
768
+ ├── .lsp.json # LSP server configs
769
+ ├── settings.json # Default settings
770
+ ├── templates/ # Reusable templates
771
+ ├── scripts/ # Shell/Python helpers
772
+ ├── docs/ # Documentation
773
+ └── tests/ # Plugin tests
774
+ ```
775
+
776
+ ### Plugin Manifest (plugin.json)
777
+
778
+ ```json
779
+ {
780
+ "name": "pr-review",
781
+ "version": "1.0.0",
782
+ "description": "Complete PR review workflow with security, testing, and docs",
783
+ "author": { "name": "Anthropic" },
784
+ "license": "MIT"
785
+ }
786
+ ```
787
+
788
+ Components are auto-discovered by directory convention — no explicit registration needed.
789
+
790
+ ### Plugin CLI Commands
791
+
792
+ ```bash
793
+ claude plugin install <name>@<marketplace>
794
+ claude plugin uninstall <name>
795
+ claude plugin list
796
+ claude plugin enable <name>
797
+ claude plugin disable <name>
798
+ claude plugin validate
799
+ claude --plugin-dir ./path # Local dev testing
800
+ /reload-plugins # Hot-reload in session
801
+ ```
802
+
803
+ ### Example Plugins from the Repo
804
+
805
+ **PR Review Plugin** (10 files):
806
+ - Commands: `/review-pr`, `/check-security`, `/check-tests`
807
+ - Agents: security-reviewer, test-checker, performance-analyzer
808
+ - MCP: GitHub integration
809
+ - Hooks: pre-review validation
810
+
811
+ **DevOps Plugin** (15 files):
812
+ - Commands: `/deploy`, `/rollback`, `/status`, `/incident`
813
+ - Agents: deployment-specialist, incident-commander, alert-analyzer
814
+ - MCP: Kubernetes integration
815
+ - Hooks: pre-deploy checks, post-deploy health checks
816
+ - Scripts: deploy.sh, rollback.sh, health-check.sh
817
+
818
+ **Documentation Plugin** (14 files):
819
+ - Commands: `/generate-api-docs`, `/generate-readme`, `/sync-docs`, `/validate-docs`
820
+ - Agents: api-documenter, code-commentator, example-generator
821
+ - Templates: api-endpoint.md, function-docs.md, adr-template.md
822
+
823
+ ### Advanced Plugin Features
824
+
825
+ - `userConfig` with `sensitive: true` for keychain-stored secrets
826
+ - `${CLAUDE_PLUGIN_DATA}` persistent storage directory per plugin
827
+ - Inline plugin definitions via `source: 'settings'`
828
+ - LSP support for Go (gopls), Python (pyright), TypeScript, Rust
829
+ - Marketplace sources: GitHub, Git URL, npm, pip, local path
830
+ - `strictKnownMarketplaces` for enterprise allowlisting
831
+ - Security sandbox: plugin subagents cannot define hooks, configure MCP, or override permissions
832
+
833
+ ### Plugin vs Manual Setup
834
+
835
+ | Aspect | Manual | Plugin |
836
+ |--------|--------|--------|
837
+ | Setup time | 2+ hours | 2 minutes |
838
+ | Reproducibility | Hope teammates configure correctly | Exact same setup |
839
+ | Versioning | Manual | Automatic |
840
+ | Updates | Manual per-component | One command |
841
+ | Distribution | Copy files | Install ID |
842
+
843
+ ### When to Create a Plugin
844
+
845
+ - Need multiple components (commands + agents + hooks)
846
+ - Team workflow that needs sharing
847
+ - Complex setup requiring auto-configuration
848
+ - DON'T create for: single-task automation (use command), single domain expertise (use skill), standalone live data (use MCP)
849
+
850
+ ---
851
+
852
+ ## 8. Checkpoints
853
+
854
+ ### What They Are
855
+ Automatic snapshots of conversation state (messages + file modifications + context) created with every user prompt. Enable safe experimentation and rollback.
856
+
857
+ ### Accessing Checkpoints
858
+
859
+ ```bash
860
+ Esc + Esc # Open checkpoint browser
861
+ /rewind # Same as above
862
+ /checkpoint # Manage checkpoints
863
+ ```
864
+
865
+ ### 5 Rewind Options
866
+
867
+ 1. **Restore code and conversation** — Full revert to that point
868
+ 2. **Restore conversation** — Rewind messages, keep current code
869
+ 3. **Restore code** — Revert files, keep conversation
870
+ 4. **Summarize from here** — Compress conversation into AI summary
871
+ 5. **Never mind** — Cancel
872
+
873
+ ### Key Facts
874
+
875
+ - Auto-created with every user prompt — no manual saving
876
+ - Persist up to 30 days, then auto-clean
877
+ - NOT a replacement for git
878
+ - Bash operations (`rm`, `mv`, `cp`) and external file changes are NOT tracked
879
+ - Only Claude's tool-based file modifications are tracked
880
+
881
+ ### Workflow Patterns
882
+
883
+ | Pattern | Steps |
884
+ |---------|-------|
885
+ | **A/B Testing** | Checkpoint -> Try A -> Checkpoint -> Rewind -> Try B -> Compare |
886
+ | **Safe Refactoring** | Auto-checkpoint -> Refactor -> Test -> If fail: rewind |
887
+ | **Debugging** | Checkpoint -> Hypothesis 1 -> Fail -> Rewind -> Hypothesis 2 |
888
+ | **Mistake Recovery** | Notice issue -> Rewind to last good state |
889
+
890
+ ### Configuration
891
+
892
+ ```json
893
+ {
894
+ "autoCheckpoint": true
895
+ }
896
+ ```
897
+
898
+ ---
899
+
900
+ ## 9. Advanced Features
901
+
902
+ ### Planning Mode
903
+
904
+ ```bash
905
+ /plan Implement user authentication system # Enter plan mode
906
+ # OR
907
+ claude --permission-mode plan "analyze code" # Read-only analysis
908
+ # OR
909
+ Shift+Tab # Cycle through modes
910
+ ```
911
+
912
+ - Two-phase: Plan -> Approve -> Execute
913
+ - `opusplan` model alias: Opus plans, Sonnet executes (cost optimization)
914
+ - `Ctrl+G` opens plan in external editor
915
+ - Plans include phases, time estimates, file counts, risk assessment
916
+
917
+ ### Extended Thinking
918
+
919
+ ```bash
920
+ Alt+T / Option+T # Toggle in session
921
+ /effort high # Set effort level
922
+ claude --effort max # CLI flag
923
+ export MAX_THINKING_TOKENS=50000 # Environment variable
924
+ ```
925
+
926
+ - Effort levels (Opus 4.6 only): `low`, `medium`, `high`, `max`
927
+ - "ultrathink" keyword in prompts activates deep reasoning
928
+ - `Ctrl+O` to view reasoning output (verbose mode)
929
+
930
+ ### Auto Mode (Research Preview)
931
+
932
+ ```bash
933
+ claude --enable-auto-mode # Enable, then Shift+Tab to activate
934
+ claude auto-mode defaults # Print default rules as JSON
935
+ ```
936
+
937
+ - Background safety classifier reviews each action
938
+ - Requires Team plan + Sonnet 4.6/Opus 4.6
939
+ - **Blocked by default**: pipe-to-shell installs, sending sensitive data externally, production deploys, mass deletion, IAM changes, force push to main
940
+ - **Allowed by default**: local file operations, declared dependency installs, read-only HTTP
941
+ - Fallback to user prompt after 3 consecutive or 20 total classifier blocks
942
+
943
+ ### Permission Modes (6 Total)
944
+
945
+ | Mode | Behavior |
946
+ |------|----------|
947
+ | `default` | Read only; prompts for everything else |
948
+ | `acceptEdits` | Auto-approve file edits; prompts for commands |
949
+ | `plan` | Read only, no modifications |
950
+ | `auto` | Safety classifier reviews all actions |
951
+ | `dontAsk` | Only pre-approved tools; others denied |
952
+ | `bypassPermissions` | No checks (requires `--dangerously-skip-permissions`) |
953
+
954
+ ### Background Tasks
955
+
956
+ ```
957
+ "Run tests in background"
958
+ /task list # Show all tasks
959
+ /task status bg-1234 # Check progress
960
+ /task show bg-1234 # View output
961
+ /task cancel bg-1234 # Cancel
962
+ ```
963
+
964
+ Config: `backgroundTasks.enabled`, `maxConcurrentTasks` (up to 5)
965
+
966
+ ### Scheduled Tasks
967
+
968
+ ```bash
969
+ /loop 5m /check-status # Every 5 minutes
970
+ /loop 2h "check dependency updates" # Every 2 hours
971
+ /schedule "daily at 9am" "run tests" # Cloud-persisted schedule
972
+ ```
973
+
974
+ - Session-scoped, up to 50 per session, auto-expire after 3 days
975
+ - Cloud scheduled tasks via `/schedule` persist across restarts
976
+ - Disable: `CLAUDE_CODE_DISABLE_CRON=1`
977
+
978
+ ### Session Management
979
+
980
+ ```bash
981
+ claude -c # Continue most recent conversation
982
+ claude -r "feature-auth" # Resume session by name
983
+ /resume # Browse and resume sessions
984
+ /rename "Feature Work" # Name current session
985
+ /fork # Branch into new session
986
+ --fork-session <id> # Branch from specific session
987
+ ```
988
+
989
+ ### Chrome Integration (Beta)
990
+
991
+ ```bash
992
+ claude --chrome # Enable browser automation
993
+ /chrome # Toggle in session
994
+ ```
995
+
996
+ - Live DOM inspection, form testing, data extraction, session recording
997
+ - Shares browser login state for authenticated app testing
998
+ - Chrome and Edge only
999
+
1000
+ ### Remote Control
1001
+
1002
+ ```bash
1003
+ claude remote-control # Start server
1004
+ /remote-control # In-session
1005
+ ```
1006
+
1007
+ - Continue CLI sessions from any browser/phone/tablet
1008
+ - Connect via session URL, QR code, or by name at claude.ai/code
1009
+ - Security: no inbound ports, outbound HTTPS only, scoped tokens
1010
+
1011
+ ### Web Sessions
1012
+
1013
+ ```bash
1014
+ claude --remote "task" # Create web session
1015
+ claude --teleport # Resume web session locally
1016
+ /teleport # In-session
1017
+ ```
1018
+
1019
+ ### Desktop App
1020
+
1021
+ - Visual diff review, parallel sessions, app preview
1022
+ - PR monitoring with auto-fix
1023
+ - Connectors: GitHub, Slack, Linear, Notion, Asana, Calendar
1024
+ - Handoff from CLI: `/desktop`
1025
+
1026
+ ### Git Worktrees
1027
+
1028
+ ```bash
1029
+ claude --worktree # Isolated branch work
1030
+ claude -w # Short form
1031
+ ```
1032
+
1033
+ - Sparse checkout for monorepos via `worktree.sparsePaths`
1034
+ - Auto-cleanup if no changes made
1035
+
1036
+ ### Sandboxing
1037
+
1038
+ ```bash
1039
+ /sandbox # Toggle in session
1040
+ claude --sandbox # CLI flag
1041
+ ```
1042
+
1043
+ - OS-level filesystem and network isolation for Bash commands
1044
+ - Configure allowed/denied read/write paths
1045
+ - Works alongside permission rules for defense in depth
1046
+
1047
+ ### Keyboard Shortcuts
1048
+
1049
+ | Shortcut | Action |
1050
+ |----------|--------|
1051
+ | `Ctrl+C` | Cancel current operation |
1052
+ | `Ctrl+L` | Clear screen |
1053
+ | `Ctrl+R` | Search command history |
1054
+ | `Ctrl+G` | Open plan in editor |
1055
+ | `Ctrl+O` | Toggle verbose/thinking output |
1056
+ | `Ctrl+B` | Background current agent |
1057
+ | `Ctrl+F` | Kill background agent |
1058
+ | `Alt+T` / `Option+T` | Toggle extended thinking |
1059
+ | `Alt+P` | Toggle planning mode |
1060
+ | `Shift+Tab` | Cycle permission modes |
1061
+ | `Esc+Esc` | Open checkpoint browser |
1062
+ | `Tab` | Autocomplete |
1063
+ | `!command` | Direct bash execution |
1064
+
1065
+ ### Custom Keybindings
1066
+
1067
+ ```bash
1068
+ /keybindings # Configure
1069
+ # Stored in ~/.claude/keybindings.json
1070
+ # Supports chord sequences: ctrl+k ctrl+s
1071
+ # 18 contexts for scope (Chat, Confirmation, Global, Autocomplete, etc.)
1072
+ ```
1073
+
1074
+ ---
1075
+
1076
+ ## 10. CLI Reference
1077
+
1078
+ ### Core Commands
1079
+
1080
+ ```bash
1081
+ claude # Interactive REPL
1082
+ claude "query" # REPL with initial prompt
1083
+ claude -p "query" # Print mode (non-interactive)
1084
+ claude -p --output-format json "query" # JSON output for scripts
1085
+ claude -p --json-schema '{}' "query" # Validated structured output
1086
+ claude -c # Continue last session
1087
+ claude -r "session-name" # Resume by name
1088
+ claude -w # Git worktree isolation
1089
+ claude --bare # Skip hooks, skills, plugins, MCP, memory
1090
+ claude update # Update CLI
1091
+ claude mcp add/list/remove # MCP management
1092
+ claude mcp serve # Run as MCP server
1093
+ claude agents # List agents
1094
+ claude plugin install/list/remove # Plugin management
1095
+ claude auto-mode defaults # Print auto mode rules
1096
+ claude remote-control # Start remote server
1097
+ claude auth login/logout/status # Authentication
1098
+ ```
1099
+
1100
+ ### Key Flags
1101
+
1102
+ | Flag | Purpose |
1103
+ |------|---------|
1104
+ | `-p, --print` | Non-interactive mode |
1105
+ | `-c, --continue` | Continue last session |
1106
+ | `-r, --resume` | Resume specific session |
1107
+ | `-w, --worktree` | Isolated git worktree |
1108
+ | `--model opus/sonnet/haiku/opusplan` | Model selection |
1109
+ | `--effort low/medium/high/max` | Thinking effort |
1110
+ | `--permission-mode` | Set permission mode |
1111
+ | `--tools` | Restrict available tools |
1112
+ | `--allowedTools / --disallowedTools` | Fine-grained tool control |
1113
+ | `--output-format text/json/stream-json` | Output format |
1114
+ | `--json-schema` | Validated JSON output |
1115
+ | `--max-turns N` | Limit autonomous turns |
1116
+ | `--max-budget-usd N` | Spending cap (print mode) |
1117
+ | `--bare` | Skip all extensions |
1118
+ | `--chrome / --no-chrome` | Browser integration |
1119
+ | `--remote` | Create web session |
1120
+ | `--teleport` | Resume web session locally |
1121
+ | `--channels` | Subscribe to MCP channels |
1122
+ | `--fork-session` | Branch from session |
1123
+ | `--agents '{}'` | Inline JSON agent definitions |
1124
+ | `--mcp-config` | MCP server configuration |
1125
+ | `--sandbox` | Enable sandboxing |
1126
+ | `--enable-auto-mode` | Enable auto mode |
1127
+
1128
+ ### Models
1129
+
1130
+ | Model | Context | Notes |
1131
+ |-------|---------|-------|
1132
+ | Opus 4.6 | 1M tokens | Most capable, adaptive effort levels |
1133
+ | Sonnet 4.6 | 1M tokens | Balanced speed and capability |
1134
+ | Haiku 4.5 | 1M tokens | Fastest, quick tasks |
1135
+ | opusplan | — | Opus plans, Sonnet executes |
1136
+
1137
+ ### Piping and Batch Processing
1138
+
1139
+ ```bash
1140
+ cat error.log | claude -p "explain this error"
1141
+ git log --oneline -20 | claude -p "summarize recent changes"
1142
+
1143
+ # Batch processing
1144
+ for file in *.md; do
1145
+ claude -p --output-format json "summarize: $(cat $file)" > ${file%.md}.json
1146
+ done
1147
+ ```
1148
+
1149
+ ### CI/CD Integration
1150
+
1151
+ ```bash
1152
+ # GitHub Actions
1153
+ - name: AI Code Review
1154
+ run: claude -p --output-format json --max-turns 3 "review code"
1155
+
1156
+ # With permission mode
1157
+ claude -p --permission-mode dontAsk "run tests"
1158
+
1159
+ # With auto mode
1160
+ claude --enable-auto-mode -p "implement and test feature"
1161
+
1162
+ # With spending cap
1163
+ claude -p --max-budget-usd 5 "refactor auth module"
1164
+ ```
1165
+
1166
+ ### Key Environment Variables
1167
+
1168
+ | Variable | Purpose |
1169
+ |----------|---------|
1170
+ | `ANTHROPIC_API_KEY` | API authentication |
1171
+ | `ANTHROPIC_MODEL` | Default model |
1172
+ | `MAX_THINKING_TOKENS` | Extended thinking budget |
1173
+ | `CLAUDE_CODE_EFFORT_LEVEL` | Default effort level |
1174
+ | `CLAUDE_CODE_DISABLE_AUTO_MEMORY` | Disable auto-memory |
1175
+ | `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS` | Disable background tasks |
1176
+ | `CLAUDE_CODE_ENABLE_TASKS` | Enable task management |
1177
+ | `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` | Enable agent teams |
1178
+ | `CLAUDE_CODE_SUBAGENT_MODEL` | Override subagent model |
1179
+ | `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` | Override compaction threshold |
1180
+ | `CLAUDE_CODE_DISABLE_CRON` | Disable scheduled tasks |
1181
+
1182
+ ---
1183
+
1184
+ ## Feature Selection Guide
1185
+
1186
+ ### Decision Tree
1187
+
1188
+ ```
1189
+ What do you need?
1190
+
1191
+ Quick repeated task?
1192
+ -> Manual trigger? -> Slash Command
1193
+ -> Auto trigger? -> Skill
1194
+
1195
+ External live data?
1196
+ -> Real-time? -> MCP
1197
+ -> Static/cross-session? -> Memory
1198
+
1199
+ Complex project?
1200
+ -> Multiple specialized roles? -> Subagents
1201
+ -> Single domain? -> Skills + Memory
1202
+
1203
+ Event-driven automation?
1204
+ -> Hook
1205
+
1206
+ Complete team workflow?
1207
+ -> Plugin (bundles everything)
1208
+ ```
1209
+
1210
+ ### Installation Priority
1211
+
1212
+ | Priority | Feature | Command |
1213
+ |----------|---------|---------|
1214
+ | 1 | Memory | Create `./CLAUDE.md` with team standards |
1215
+ | 2 | Slash Commands | `.claude/commands/*.md` or `.claude/skills/` |
1216
+ | 3 | Subagents | `.claude/agents/*.md` |
1217
+ | 4 | Hooks | Configure in `~/.claude/settings.json` |
1218
+ | 5 | MCP | `claude mcp add github -- npx -y @modelcontextprotocol/server-github` |
1219
+ | 6 | Skills | `.claude/skills/<name>/SKILL.md` |
1220
+ | 7 | Plugins | `/plugin install <name>` |
1221
+
1222
+ ---
1223
+
1224
+ ## Configuration Examples
1225
+
1226
+ ### Development (General)
1227
+
1228
+ ```json
1229
+ {
1230
+ "model": "sonnet",
1231
+ "temperature": 0.7,
1232
+ "planning": { "autoEnter": true },
1233
+ "backgroundTasks": { "enabled": true, "maxConcurrentTasks": 3 },
1234
+ "hooks": {
1235
+ "PostToolUse": [{ "matcher": "Write", "hooks": [{ "type": "command", "command": "prettier --write $CLAUDE_FILE_PATH" }] }]
1236
+ }
1237
+ }
1238
+ ```
1239
+
1240
+ ### Code Review (Read-Only)
1241
+
1242
+ ```json
1243
+ {
1244
+ "model": "opus",
1245
+ "temperature": 0.3,
1246
+ "permissions": { "mode": "plan" },
1247
+ "extendedThinking": { "enabled": true }
1248
+ }
1249
+ ```
1250
+
1251
+ ### CI/CD Pipeline
1252
+
1253
+ ```json
1254
+ {
1255
+ "temperature": 0,
1256
+ "permissions": { "mode": "bypassPermissions" },
1257
+ "logging": { "level": "debug" },
1258
+ "timeout": 3600
1259
+ }
1260
+ ```
1261
+
1262
+ ### Security Audit
1263
+
1264
+ ```json
1265
+ {
1266
+ "model": "opus",
1267
+ "extendedThinking": { "enabled": true, "minThinkingTime": 10 },
1268
+ "permissions": { "mode": "plan" },
1269
+ "hooks": {
1270
+ "PostToolUse": [{ "matcher": "Write", "hooks": [{ "type": "command", "command": "security-scan.sh" }] }]
1271
+ }
1272
+ }
1273
+ ```
1274
+
1275
+ ### Autonomous Development
1276
+
1277
+ ```json
1278
+ {
1279
+ "model": "sonnet",
1280
+ "permissions": { "mode": "auto" },
1281
+ "sandbox": { "enabled": true }
1282
+ }
1283
+ ```
1284
+
1285
+ ---
1286
+
1287
+ ## Clean Code Rules
1288
+
1289
+ Distilled from `clean-code-rules.md` in the repo:
1290
+
1291
+ ### Naming
1292
+ - Intention-revealing names that explain WHY something exists
1293
+ - Class names: nouns (UserAccount, PaymentProcessor)
1294
+ - Method names: verbs (calculateTotal, sendEmail)
1295
+ - Avoid: data, info, manager, temp, result
1296
+
1297
+ ### Functions
1298
+ - Small (<20 lines ideal)
1299
+ - Single responsibility — do one thing
1300
+ - 0-2 arguments (3 maximum, never flag arguments)
1301
+ - No side effects — function does what its name says
1302
+ - Separate commands (change state) from queries (return info)
1303
+
1304
+ ### Comments
1305
+ - Code should be self-explanatory
1306
+ - Good: legal info, warnings, TODOs, public API docs
1307
+ - Bad: redundant, misleading, explaining bad code
1308
+ - Never comment out code — delete it
1309
+
1310
+ ### Error Handling
1311
+ - Exceptions over return codes
1312
+ - Provide context in exception messages
1313
+ - Never return null — return empty collections or Optional
1314
+ - Never pass null as arguments
1315
+
1316
+ ### Classes
1317
+ - Measured by responsibilities, not lines
1318
+ - Single Responsibility Principle
1319
+ - High cohesion, low coupling
1320
+ - Open/Closed Principle
1321
+
1322
+ ### Testing (F.I.R.S.T.)
1323
+ - **F**ast, **I**ndependent, **R**epeatable, **S**elf-validating, **T**imely
1324
+ - One concept per test
1325
+ - Arrange-Act-Assert pattern
1326
+ - Test code quality = production code quality
1327
+
1328
+ ### Principles
1329
+ - **DRY**: No duplication
1330
+ - **YAGNI**: Don't build for hypothetical futures
1331
+ - **KISS**: Avoid unnecessary complexity
1332
+ - **Boy Scout Rule**: Leave code cleaner than you found it
1333
+
1334
+ ---
1335
+
1336
+ ## Qualia Gap Analysis
1337
+
1338
+ ### What We Already Do (Often Better)
1339
+
1340
+ | Area | Our Approach | Repo's Approach |
1341
+ |------|-------------|-----------------|
1342
+ | Memory | 7-tier with session-digest, auto-handoff, stale warnings | 8-tier (same + managed drop-ins) |
1343
+ | Hooks | 11 custom hooks (branch-guard, pre-deploy-gate, etc.) | 8 example hooks |
1344
+ | Skills | 50+ skills with trigger phrases + Qualia workflow | 6 example skills |
1345
+ | Subagents | 30+ agent types with model overrides | 8 example agents |
1346
+ | Feature branches | branch-guard hook enforces automatically | Manual discipline |
1347
+ | Post-deploy | `/deploy-verify` 8-check verification | Not covered |
1348
+ | Cross-session | session-digest.md, auto-handoff, .continue-here | Not covered |
1349
+
1350
+ ### Patterns Worth Adopting
1351
+
1352
+ 1. **Directory-specific CLAUDE.md** — Place CLAUDE.md inside `apps/mobile/`, `apps/backend/` for monorepo module-specific rules (useful for Sakani)
1353
+
1354
+ 2. **Python analysis scripts in skills** — Bundle `analyze-metrics.py` (cyclomatic complexity), `compare-complexity.py` (before/after), `detect-smells.py` (14 smell types) with our `/review` skill for objective metrics
1355
+
1356
+ 3. **Context tracker hook** — `context-tracker-tiktoken.py` monitors token usage per request. Dual-hook pattern (UserPromptSubmit + Stop) with temp file state per session_id
1357
+
1358
+ 4. **Security scan hook** — Auto-scan written files for hardcoded secrets (password patterns, AKIA keys, private keys). Add as PostToolUse:Write hook
1359
+
1360
+ 5. **Plugin packaging** — Bundle our Qualia workflow (skills + hooks + agents + memory templates) as a distributable plugin for team onboarding
1361
+
1362
+ 6. **`opusplan` model** — Opus for planning, Sonnet for execution. Cost optimization for complex tasks
1363
+
1364
+ 7. **`--bare` flag** — Useful for debugging when hooks/skills interfere
1365
+
1366
+ 8. **`--json-schema` flag** — Validated structured JSON output for automation scripts
1367
+
1368
+ 9. **Path-scoped rules** — YAML frontmatter in `.claude/rules/` with `paths: src/api/**/*.ts` for targeted rules
1369
+
1370
+ 10. **`user-invocable: false` skills** — Background knowledge skills that Claude applies silently (e.g., brand voice, coding standards)
1371
+
1372
+ ### Things They Cover That We've Evolved Past
1373
+
1374
+ - Manual skill installation (`cp -r`) — we use registered skills with auto-discovery
1375
+ - Simple frontmatter — our skills use richer metadata
1376
+ - Basic memory — we have cross-session intelligence
1377
+ - Tutorial-driven learning — our workflow is project-driven
1378
+ - Linear progression — we have adaptive routing (`/qualia` smart router)
1379
+
1380
+ ---
1381
+
1382
+ *Source: [github.com/luongnv89/claude-howto](https://github.com/luongnv89/claude-howto) v2.2.0*
1383
+ *Studied: 2026-03-28*
1384
+ *100+ files across 10 modules, all root docs, 3130-line master concepts guide*