cc-discipline 2.10.1 → 2.10.3
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.
- package/README.md +236 -153
- package/README.zh-CN.md +299 -207
- package/bin/cli.sh +96 -96
- package/global/CLAUDE.md +45 -45
- package/init.sh +594 -594
- package/lib/doctor.sh +145 -145
- package/lib/stack-remove.sh +68 -68
- package/lib/status.sh +100 -100
- package/package.json +34 -34
- package/templates/.claude/agents/investigator.md +44 -44
- package/templates/.claude/agents/reviewer.md +46 -46
- package/templates/.claude/hooks/action-counter.sh +58 -58
- package/templates/.claude/hooks/git-guard.sh +62 -62
- package/templates/.claude/hooks/phase-gate.sh +10 -10
- package/templates/.claude/hooks/post-error-remind.sh +114 -114
- package/templates/.claude/hooks/pre-edit-guard.sh +100 -100
- package/templates/.claude/hooks/session-start.sh +44 -44
- package/templates/.claude/hooks/streak-breaker.sh +111 -111
- package/templates/.claude/rules/00-core-principles.md +16 -16
- package/templates/.claude/rules/01-debugging.md +32 -32
- package/templates/.claude/rules/02-before-edit.md +22 -22
- package/templates/.claude/rules/03-context-mgmt.md +44 -44
- package/templates/.claude/rules/04-no-mole-whacking.md +26 -26
- package/templates/.claude/rules/05-phase-discipline.md +15 -15
- package/templates/.claude/rules/06-multi-task.md +12 -12
- package/templates/.claude/rules/07-integrity.md +92 -92
- package/templates/.claude/rules/stacks/embedded.md +24 -24
- package/templates/.claude/rules/stacks/js-ts.md +21 -21
- package/templates/.claude/rules/stacks/mobile.md +16 -16
- package/templates/.claude/rules/stacks/python.md +20 -20
- package/templates/.claude/rules/stacks/rtl.md +24 -24
- package/templates/.claude/settings.json +84 -84
- package/templates/.claude/skills/commit/SKILL.md +40 -40
- package/templates/.claude/skills/evaluate/SKILL.md +57 -57
- package/templates/.claude/skills/investigate/SKILL.md +192 -192
- package/templates/.claude/skills/retro/SKILL.md +40 -40
- package/templates/.claude/skills/self-check/SKILL.md +112 -87
- package/templates/.claude/skills/summary/SKILL.md +48 -48
- package/templates/.claude/skills/think/SKILL.md +108 -108
- package/templates/CLAUDE.md +96 -96
- package/templates/docs/debug-log.md +48 -48
- package/templates/docs/progress.md +72 -72
- package/templates/memory/MEMORY.md +23 -23
package/README.md
CHANGED
|
@@ -1,153 +1,236 @@
|
|
|
1
|
-
# cc-discipline
|
|
2
|
-
|
|
3
|
-
Guardrails for Claude Code. Shell hooks that **actually block** bad behavior, not just markdown that asks nicely.
|
|
4
|
-
|
|
5
|
-
[中文文档](README.zh-CN.md)
|
|
6
|
-
|
|
7
|
-
## The Problem
|
|
8
|
-
|
|
9
|
-
Claude Code in long sessions tends to:
|
|
10
|
-
- Edit the same file 5+ times chasing symptoms instead of finding root cause
|
|
11
|
-
- See an error and immediately change code without understanding it
|
|
12
|
-
- Lose track of what it was doing after context compaction
|
|
13
|
-
|
|
14
|
-
Markdown rules help, but Claude can ignore them. **Hooks can't be ignored** — they run as shell scripts and `exit 2` physically blocks the operation.
|
|
15
|
-
|
|
16
|
-
## What This Does
|
|
17
|
-
|
|
18
|
-
### Hooks (the enforcer)
|
|
19
|
-
|
|
20
|
-
Three shell scripts that run automatically before/after Claude's actions:
|
|
21
|
-
|
|
22
|
-
**`streak-breaker.sh`** — Tracks per-file edit counts. Warns at 3, **hard-blocks at 5**. Forces Claude to stop and find the root cause instead of endlessly patching.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
You
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
# cc-discipline
|
|
2
|
+
|
|
3
|
+
Guardrails for Claude Code. Shell hooks that **actually block** bad behavior, not just markdown that asks nicely.
|
|
4
|
+
|
|
5
|
+
[中文文档](README.zh-CN.md)
|
|
6
|
+
|
|
7
|
+
## The Problem
|
|
8
|
+
|
|
9
|
+
Claude Code in long sessions tends to:
|
|
10
|
+
- Edit the same file 5+ times chasing symptoms instead of finding root cause
|
|
11
|
+
- See an error and immediately change code without understanding it
|
|
12
|
+
- Lose track of what it was doing after context compaction
|
|
13
|
+
|
|
14
|
+
Markdown rules help, but Claude can ignore them. **Hooks can't be ignored** — they run as shell scripts and `exit 2` physically blocks the operation.
|
|
15
|
+
|
|
16
|
+
## What This Does
|
|
17
|
+
|
|
18
|
+
### Hooks (the enforcer)
|
|
19
|
+
|
|
20
|
+
Three shell scripts that run automatically before/after Claude's actions:
|
|
21
|
+
|
|
22
|
+
**`streak-breaker.sh`** — Tracks per-file edit counts. Warns at 3, **hard-blocks at 5**. Forces Claude to stop and find the root cause instead of endlessly patching.
|
|
23
|
+
|
|
24
|
+
Here's what it looks like in practice:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
You: "Fix the login validation bug in auth.py"
|
|
28
|
+
|
|
29
|
+
Claude: I'll fix the validation logic.
|
|
30
|
+
[Edit src/auth.py — fix email regex]
|
|
31
|
+
|
|
32
|
+
Claude: The regex wasn't enough, let me also add length check.
|
|
33
|
+
[Edit src/auth.py — add input length validation]
|
|
34
|
+
|
|
35
|
+
Claude: That broke the existing tests, let me adjust.
|
|
36
|
+
[Edit src/auth.py — fix test compatibility]
|
|
37
|
+
⚠️ EDIT NOTE: File src/auth.py has been edited 3 times.
|
|
38
|
+
Quick check: are these edits building toward a goal,
|
|
39
|
+
or fixing previous edits?
|
|
40
|
+
|
|
41
|
+
Claude: Let me try a different approach to the validation.
|
|
42
|
+
[Edit src/auth.py — rewrite validation layer]
|
|
43
|
+
|
|
44
|
+
Claude: Almost there, one more adjustment...
|
|
45
|
+
[Edit src/auth.py — blocked]
|
|
46
|
+
|
|
47
|
+
🛑 EDIT CHECKPOINT
|
|
48
|
+
File src/auth.py has been edited 5 times this session.
|
|
49
|
+
Reflect:
|
|
50
|
+
1. Are these edits progressing toward a goal,
|
|
51
|
+
or fixing previous edits?
|
|
52
|
+
2. If fixing previous edits: pause and look
|
|
53
|
+
for the root cause.
|
|
54
|
+
|
|
55
|
+
Claude: You're right. Looking at all 5 edits, I was patching
|
|
56
|
+
symptoms. The real issue is that the User model's
|
|
57
|
+
validate() method is called before sanitization.
|
|
58
|
+
Let me fix it at the source instead.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Without the hook, Claude would keep editing `auth.py` indefinitely — each fix creating the next bug. The hook forces a pause that leads to root-cause discovery.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
**`pre-edit-guard.sh`** — Checks `docs/debug-log.md` for unverified hypotheses. If you're debugging and haven't finished the process, it blocks source code edits until you do.
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
You: "The API is returning 500 errors on /users endpoint"
|
|
69
|
+
|
|
70
|
+
Claude: Let me investigate.
|
|
71
|
+
[Bash: curl localhost:3000/users]
|
|
72
|
+
→ 500 Internal Server Error
|
|
73
|
+
|
|
74
|
+
Claude: I think it's a database connection issue. Let me fix
|
|
75
|
+
the connection pool config.
|
|
76
|
+
[Edit src/db.py — blocked]
|
|
77
|
+
|
|
78
|
+
🛑 docs/debug-log.md has 2 unverified hypotheses.
|
|
79
|
+
Please complete the debugging process (verify or
|
|
80
|
+
eliminate hypotheses) before editing source code.
|
|
81
|
+
|
|
82
|
+
Claude: Right, I haven't verified my hypothesis yet.
|
|
83
|
+
Let me check the actual error logs first.
|
|
84
|
+
[Bash: tail -50 logs/error.log]
|
|
85
|
+
→ TypeError: Cannot read property 'map' of undefined
|
|
86
|
+
at UserSerializer.format (src/serializers.py:42)
|
|
87
|
+
|
|
88
|
+
Claude: The error is in the serializer, not the database.
|
|
89
|
+
My first hypothesis was wrong. Let me update
|
|
90
|
+
debug-log.md and then fix the actual issue.
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Without the hook, Claude would have "fixed" the database config — a perfectly working component — and the real bug would remain.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
**`post-error-remind.sh`** — Detects error patterns (test failures, crashes, build errors) in command output and injects a debugging discipline reminder before Claude can react impulsively.
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Claude: Let me run the tests.
|
|
101
|
+
[Bash: pytest tests/]
|
|
102
|
+
→ FAILED tests/test_auth.py::test_login - AssertionError
|
|
103
|
+
→ 1 failed, 23 passed
|
|
104
|
+
|
|
105
|
+
⚡ Error encountered — debugging checklist:
|
|
106
|
+
1. Resist modifying code immediately
|
|
107
|
+
2. Fully understand the error message
|
|
108
|
+
3. List >=3 possible causes
|
|
109
|
+
4. Only then fix
|
|
110
|
+
|
|
111
|
+
Claude: Before jumping in, let me understand the failure.
|
|
112
|
+
The test expects a 200 but gets 401. Three possible
|
|
113
|
+
causes:
|
|
114
|
+
1. Token generation changed (check auth.py changes)
|
|
115
|
+
2. Test fixture uses expired mock token
|
|
116
|
+
3. Middleware order changed after recent refactor
|
|
117
|
+
Let me verify each...
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Without the hook, Claude's instinct is to immediately open the test or source file and start editing. The reminder forces a diagnostic pause.
|
|
121
|
+
|
|
122
|
+
### Rules (the reminders)
|
|
123
|
+
|
|
124
|
+
Auto-injected markdown in `.claude/rules/` — Claude sees them when operating on matching files. Not as strong as hooks, but provides structure:
|
|
125
|
+
|
|
126
|
+
- Debugging process: gather → hypothesize → verify → fix (no skipping)
|
|
127
|
+
- Pre-edit checklist: understand the file, know the impact, fix root cause
|
|
128
|
+
- Mole-whacking detection: recognize the pattern, stop, report
|
|
129
|
+
- Phase discipline: stay in research/plan/implement, don't jump ahead
|
|
130
|
+
- Multi-task gates: complete tasks in order, confirm each before moving on
|
|
131
|
+
- Tech stack rules for Python, JS/TS, embedded, RTL, mobile
|
|
132
|
+
|
|
133
|
+
### Subagents (the auditors)
|
|
134
|
+
|
|
135
|
+
- **reviewer** — Reviews your modification plan in a separate context. Challenges assumptions, suggests alternatives, checks for missing edge cases.
|
|
136
|
+
- **investigator** — Researches the codebase in isolation. Returns structured findings without polluting your main conversation.
|
|
137
|
+
|
|
138
|
+
## Install
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
git clone https://github.com/TechHU-GS/cc-discipline.git ~/.cc-discipline
|
|
142
|
+
cd your-project
|
|
143
|
+
bash ~/.cc-discipline/init.sh
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The installer is interactive — pick your tech stack, name your project, done.
|
|
147
|
+
|
|
148
|
+
**Already have a `.claude/` setup?** The installer detects this and runs in append mode:
|
|
149
|
+
- Your `CLAUDE.md` is **never overwritten**
|
|
150
|
+
- Your `settings.json` hooks are **preserved** (cc-discipline hooks are merged in via `jq`)
|
|
151
|
+
- Your custom rules, agents, and docs are **untouched**
|
|
152
|
+
- A timestamped backup is created before any changes
|
|
153
|
+
|
|
154
|
+
**Upgrading?** Just run `init.sh` again. It detects the existing installation and updates framework files while preserving your configuration.
|
|
155
|
+
|
|
156
|
+
## What Gets Installed
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
.claude/
|
|
160
|
+
├── rules/ # Auto-injected when Claude operates on matching files
|
|
161
|
+
│ ├── 00-core-principles.md
|
|
162
|
+
│ ├── 01-debugging.md
|
|
163
|
+
│ ├── 02-before-edit.md
|
|
164
|
+
│ ├── 03-context-mgmt.md
|
|
165
|
+
│ ├── 04-no-mole-whacking.md
|
|
166
|
+
│ ├── 05-phase-discipline.md
|
|
167
|
+
│ ├── 06-multi-task.md
|
|
168
|
+
│ └── stacks/ # Picked during install
|
|
169
|
+
├── hooks/ # Shell scripts, exit 2 = block operation
|
|
170
|
+
│ ├── streak-breaker.sh
|
|
171
|
+
│ ├── pre-edit-guard.sh
|
|
172
|
+
│ └── post-error-remind.sh
|
|
173
|
+
├── agents/
|
|
174
|
+
│ ├── reviewer.md
|
|
175
|
+
│ └── investigator.md
|
|
176
|
+
├── skills/
|
|
177
|
+
│ └── commit/SKILL.md # /commit: test → update docs → commit
|
|
178
|
+
└── settings.json # Hook registration
|
|
179
|
+
docs/
|
|
180
|
+
├── progress.md # Claude maintains this, read after compact
|
|
181
|
+
└── debug-log.md # Debug session tracking
|
|
182
|
+
CLAUDE.md # Your project info (you fill this in)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Customization
|
|
186
|
+
|
|
187
|
+
**Adjust hook strictness:**
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# In .claude/hooks/streak-breaker.sh
|
|
191
|
+
WARN_THRESHOLD=3 # Warn after N edits to same file
|
|
192
|
+
STOP_THRESHOLD=5 # Hard block after N edits
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Add your own rules:**
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
cat > .claude/rules/my-rule.md << 'EOF'
|
|
199
|
+
---
|
|
200
|
+
globs: "src/api/**/*"
|
|
201
|
+
description: "API layer rules"
|
|
202
|
+
---
|
|
203
|
+
- All API changes must be backwards-compatible
|
|
204
|
+
- New endpoints need OpenAPI spec updates
|
|
205
|
+
EOF
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Write your own hooks:**
|
|
209
|
+
|
|
210
|
+
Any script in `.claude/hooks/` can be registered in `settings.json`. The key behaviors:
|
|
211
|
+
- `exit 0` = allow (stdout can inject context via JSON for PreToolUse hooks)
|
|
212
|
+
- `exit 2` + stderr = block operation, stderr message shown to Claude
|
|
213
|
+
|
|
214
|
+
See [Claude Code hooks docs](https://docs.anthropic.com/en/docs/claude-code/hooks) for the full spec.
|
|
215
|
+
|
|
216
|
+
## FAQ
|
|
217
|
+
|
|
218
|
+
**Is this just markdown rules?**
|
|
219
|
+
No. The hooks are the real enforcement — they're shell scripts that physically block operations. The rules are supplementary structure.
|
|
220
|
+
|
|
221
|
+
**Does it slow things down?**
|
|
222
|
+
No. Hooks are lightweight shell scripts, typically <100ms. Rules add ~8KB to context (~2%).
|
|
223
|
+
|
|
224
|
+
**Should I commit `.claude/` to git?**
|
|
225
|
+
Yes. Team members get the same guardrails. Hook paths use `$CLAUDE_PROJECT_DIR`, so they work across machines.
|
|
226
|
+
|
|
227
|
+
**Does it work with existing projects?**
|
|
228
|
+
Yes. The installer has an append mode that merges with your existing `.claude/` configuration without overwriting anything. Run `init.sh` and it auto-detects.
|
|
229
|
+
|
|
230
|
+
## Contributing
|
|
231
|
+
|
|
232
|
+
PRs welcome — especially new hooks. The hooks are where the real value is.
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
[MIT](LICENSE)
|