Skip to content

Commit 59784a0

Browse files
authored
Merge pull request #4 from ActiveMemory/feature/cleanup
Cleanup (part one) before release cut.
2 parents 9d7e664 + 150c439 commit 59784a0

137 files changed

Lines changed: 6469 additions & 2516 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/commands/audit-docs.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
description: "Audit documentation for consistency and accuracy"
33
---
44

5-
Perform a documentation audit across the codebase. This is an AI-assisted review that produces a report for human judgment.
5+
Perform a documentation audit across the codebase. This is an AI-assisted
6+
review that produces a report for human judgment.
67

78
## Audit Scope
89

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
description: "Analyze session logs to identify vague prompts and suggest improvements"
3+
---
4+
5+
Analyze recent session transcripts to identify prompts that led to unnecessary clarification back-and-forth. This helps the user improve their prompting patterns.
6+
7+
## Your Task
8+
9+
1. **Read recent sessions** from `.context/sessions/` (focus on the 3-5 most recent)
10+
2. **Identify vague prompts** - user messages that caused you to ask clarifying questions
11+
3. **Generate a coaching report** with concrete examples and suggestions
12+
13+
## What Makes a Prompt "Vague"
14+
15+
Look for user prompts where Claude's immediate response was to ask clarifying questions rather than take action. Signs include:
16+
17+
- **Missing file context**: "fix the bug" without specifying which file or error
18+
- **Ambiguous scope**: "optimize it" without what to optimize or success criteria
19+
- **Undefined targets**: "update the component" when multiple components exist
20+
- **Missing error details**: "it's not working" without symptoms or expected behavior
21+
- **Vague action words**: "make it better", "clean this up", "improve the code"
22+
23+
## Important Nuance
24+
25+
Not every short prompt is vague! Consider context:
26+
- "fix the bug" after discussing a specific error in detail → **NOT vague**
27+
- "fix the bug" as the first message → **VAGUE**
28+
- "optimize it" when working on a single function → probably fine
29+
- "optimize it" in a large codebase with no context → **VAGUE**
30+
31+
## Output Format
32+
33+
Generate a report like this:
34+
35+
```
36+
## Prompt Audit Report
37+
38+
**Sessions analyzed**: 5
39+
**User prompts reviewed**: 47
40+
**Vague prompts found**: 4 (8.5%)
41+
42+
---
43+
44+
### Example 1: Missing File Context
45+
46+
**Your prompt**: "fix the bug"
47+
48+
**What happened**: I had to ask which file and what error you were seeing, adding 2 messages of back-and-forth.
49+
50+
**Better prompt**: "fix the authentication error in src/auth/login.ts where JWT validation fails with 401"
51+
52+
**Cost**: ~2 extra messages, ~30 seconds
53+
54+
---
55+
56+
### Example 2: Undefined Target
57+
58+
**Your prompt**: "optimize the component"
59+
60+
**What happened**: Multiple components exist. I asked which one and what performance issue to address.
61+
62+
**Better prompt**: "optimize UserList in src/components/UserList.tsx to reduce re-renders when parent state updates"
63+
64+
**Cost**: ~3 extra messages, ~1 minute
65+
66+
---
67+
68+
## Patterns to Watch
69+
70+
Based on your sessions, you tend to:
71+
1. Skip mentioning file paths (3 occurrences)
72+
2. Use "it" without establishing what "it" refers to (2 occurrences)
73+
74+
## Tips
75+
76+
- Start prompts with the **file path** when discussing specific code
77+
- Include **error messages** when debugging
78+
- Specify **success criteria** for optimization tasks
79+
```
80+
81+
## Guidelines
82+
83+
- Be constructive, not critical - the goal is to help, not shame
84+
- Show the actual prompt from their session (quoted)
85+
- Explain what happened (what you had to ask)
86+
- Provide a concrete better alternative
87+
- Estimate the "cost" in extra messages/time
88+
- Look for patterns across multiple examples
89+
- End with actionable tips based on their specific tendencies

.claude/hooks/prompt-coach.sh

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/bin/bash
2+
3+
# / Context: https://ctx.ist
4+
# ,'`./ do you remember?
5+
# `.,'\
6+
# \ Copyright 2026-present Context contributors.
7+
# SPDX-License-Identifier: Apache-2.0
8+
9+
# Prompt coaching hook for Claude Code
10+
# Detects anti-patterns and suggests better alternatives.
11+
# Limits suggestions to MAX_SUGGESTIONS per pattern per session.
12+
#
13+
# Generated by: ctx init
14+
#
15+
# ANTI-PATTERNS DETECTED:
16+
# - "idiomatic X" → "follow project conventions"
17+
# - "best practices" → "follow CONVENTIONS.md"
18+
# - "fix the bug" (vague) → include error message, file, and context
19+
# - "optimize it" (vague) → specify what to optimize and why
20+
# - "make it better" (vague) → define "better" with criteria
21+
# - "update the component" (vague) → specify which component and what changes
22+
#
23+
# Output: Warnings to stderr (non-blocking)
24+
# Exit: Always 0 (never blocks execution)
25+
26+
MAX_SUGGESTIONS=3
27+
SESSION_FILE="/tmp/ctx-prompt-coach-$$-$(date +%Y%m%d).state"
28+
29+
# Initialize session file if it doesn't exist
30+
if [ ! -f "$SESSION_FILE" ]; then
31+
cat > "$SESSION_FILE" << 'EOF'
32+
idiomatic=0
33+
bestpractices=0
34+
fixbug=0
35+
optimize=0
36+
makebetter=0
37+
update=0
38+
EOF
39+
fi
40+
41+
# Read hook input from stdin (JSON)
42+
HOOK_INPUT=$(cat)
43+
44+
# Extract the prompt text
45+
PROMPT=$(echo "$HOOK_INPUT" | jq -r '.prompt // empty')
46+
47+
# If no prompt, allow
48+
if [ -z "$PROMPT" ]; then
49+
exit 0
50+
fi
51+
52+
# Helper: get count for a pattern
53+
get_count() {
54+
grep "^$1=" "$SESSION_FILE" 2>/dev/null | cut -d= -f2 || echo "0"
55+
}
56+
57+
# Helper: increment count for a pattern
58+
increment_count() {
59+
local pattern="$1"
60+
local count=$(get_count "$pattern")
61+
local new_count=$((count + 1))
62+
if grep -q "^$pattern=" "$SESSION_FILE" 2>/dev/null; then
63+
sed -i "s/^$pattern=.*/$pattern=$new_count/" "$SESSION_FILE"
64+
else
65+
echo "$pattern=$new_count" >> "$SESSION_FILE"
66+
fi
67+
}
68+
69+
# Helper: output a coaching tip (only if under limit)
70+
suggest() {
71+
local pattern="$1"
72+
local tip="$2"
73+
local example="$3"
74+
local count=$(get_count "$pattern")
75+
76+
if [ "$count" -lt "$MAX_SUGGESTIONS" ]; then
77+
echo "" >&2
78+
echo "┌─ Prompt Tip ─────────────────────────────────────" >&2
79+
echo "$tip" >&2
80+
if [ -n "$example" ]; then
81+
echo "" >&2
82+
echo "│ Example: $example" >&2
83+
fi
84+
echo "└──────────────────────────────────────────────────" >&2
85+
echo "" >&2
86+
increment_count "$pattern"
87+
fi
88+
}
89+
90+
# Calculate prompt length (for detecting short vague prompts)
91+
PROMPT_LEN=${#PROMPT}
92+
93+
# Check for "idiomatic X" pattern (case-insensitive)
94+
if echo "$PROMPT" | grep -qiE 'idiomatic (go|python|rust|javascript|typescript|java|c\+\+|ruby)'; then
95+
suggest "idiomatic" \
96+
"Instead of 'idiomatic X', try 'follow project conventions'" \
97+
"'follow CONVENTIONS.md patterns for error handling'"
98+
fi
99+
100+
# Check for "best practices" pattern (case-insensitive)
101+
if echo "$PROMPT" | grep -qiE '\bbest practices?\b'; then
102+
suggest "bestpractices" \
103+
"Instead of 'best practices', try 'follow CONVENTIONS.md'" \
104+
"'follow the error handling pattern from CONVENTIONS.md'"
105+
fi
106+
107+
# Check for vague "fix the bug" / "fix this bug" patterns
108+
# Only trigger if the prompt is short and lacks specifics
109+
if [ "$PROMPT_LEN" -lt 50 ] && echo "$PROMPT" | grep -qiE '\bfix (the|this|that|a) (bug|issue|error|problem)\b'; then
110+
# Check if prompt lacks context (no file path, no error message, no line number)
111+
if ! echo "$PROMPT" | grep -qE '(\.[a-z]{2,4}|line [0-9]|:[0-9]+|error:|Error:|failed|Failed)'; then
112+
suggest "fixbug" \
113+
"Add context: which file? what error? what's broken?" \
114+
"'fix the JWT validation error in src/auth/login.ts returning 401'"
115+
fi
116+
fi
117+
118+
# Check for vague "optimize" patterns
119+
if [ "$PROMPT_LEN" -lt 40 ] && echo "$PROMPT" | grep -qiE '\b(optimize|optimise) (it|this|that)\b'; then
120+
suggest "optimize" \
121+
"Specify what to optimize and what metric matters" \
122+
"'optimize UserList to reduce re-renders when parent state updates'"
123+
fi
124+
125+
# Check for vague "make it better" patterns
126+
if echo "$PROMPT" | grep -qiE '\bmake (it|this|that) (better|nicer|cleaner|good)\b'; then
127+
if [ "$PROMPT_LEN" -lt 50 ]; then
128+
suggest "makebetter" \
129+
"Define 'better' - readability? performance? maintainability?" \
130+
"'refactor to be more readable by extracting validation logic'"
131+
fi
132+
fi
133+
134+
# Check for vague "update the component/function/file" patterns
135+
if [ "$PROMPT_LEN" -lt 50 ] && echo "$PROMPT" | grep -qiE '\bupdate (the|this|that|a) (component|function|file|module|class)\b'; then
136+
# Check if prompt lacks specifics
137+
if ! echo "$PROMPT" | grep -qE '(\.[a-z]{2,4}|src/|lib/|internal/)'; then
138+
suggest "update" \
139+
"Specify which component and what changes" \
140+
"'update Button in src/components/Button.tsx to use new color tokens'"
141+
fi
142+
fi
143+
144+
# Always allow the prompt to proceed
145+
exit 0

.context/AGENT_PLAYBOOK.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,23 @@ Before writing or modifying CLI code (`internal/cli/**/*.go`):
366366

367367
1. **Read CONVENTIONS.md** — Load established patterns into context
368368
2. **Check similar commands** — How do existing commands in the same package handle output?
369-
3. **Use cmd methods for output**`cmd.Printf`, `cmd.Println`, not `fmt.Printf`, `fmt.Println`
369+
3. **Use cmd methods for I/O**Never use `fmt` for output in CLI code
370370
4. **Follow docstring format** — See Go Documentation Standard below
371371

372+
**cmd methods to use:**
373+
374+
| Instead of | Use | Purpose |
375+
|-------------------|--------------------|--------------------------------------|
376+
| `fmt.Printf` | `cmd.Printf` | Formatted stdout |
377+
| `fmt.Println` | `cmd.Println` | Line to stdout |
378+
| `fmt.Print` | `cmd.Print` | Raw stdout |
379+
| `fmt.Fprintf(os.Stderr, ...)` | `cmd.PrintErrf` | Formatted stderr |
380+
| `fmt.Fprintln(os.Stderr, ...)` | `cmd.PrintErrln` | Line to stderr |
381+
| `fmt.Sprintf` | `fmt.Sprintf` | String formatting (OK to keep) |
382+
| `fmt.Errorf` | `fmt.Errorf` | Error creation (OK to keep) |
383+
384+
**Why**: cmd methods write to testable buffers; fmt writes to real stdout/stderr.
385+
372386
**Quick pattern check:**
373387
```bash
374388
# See how other commands do output

.context/LEARNINGS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<!-- INDEX:START -->
44
| Date | Learning |
55
|------|--------|
6+
| 2026-01-30 | Say 'project conventions' not 'idiomatic X' |
67
| 2026-01-29 | Documentation audits require verification against actual standards |
78
| 2026-01-28 | Required flags now enforced for learnings |
89
| 2026-01-28 | Claude Code Hooks Receive JSON via Stdin |
@@ -40,6 +41,16 @@
4041

4142
---
4243

44+
## [2026-01-30-120009] Say 'project conventions' not 'idiomatic X'
45+
46+
**Context**: When asking Claude to follow documentation style, saying 'idiomatic Go' triggered training priors (stdlib conventions) instead of project-specific standards.
47+
48+
**Lesson**: Use 'follow project conventions' or 'check AGENT_PLAYBOOK' rather than 'idiomatic [language]' to ensure Claude looks at project files first.
49+
50+
**Application**: In prompts requesting style alignment, reference project files explicitly rather than language-wide conventions.
51+
52+
---
53+
4354
## [2026-01-29-164322] Documentation audits require verification against actual standards
4455

4556
**Context**: Agent claimed 'no Go docstring issues found' but manual inspection revealed many functions missing Parameters/Returns sections. The agent only checked if comments existed, not if they followed the standard format.

0 commit comments

Comments
 (0)