Guest User

Untitled

a guest
Feb 8th, 2026
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. ---
  2. name: review-claudemd
  3. description: >
  4. Review recent conversations to improve project CLAUDE.md.
  5. USE WHEN user says "review claudemd", "update claudemd", "improve instructions",
  6. "setup-memory", "what should I add to claudemd".
  7. ---
  8.  
  9. # Review CLAUDE.md
  10.  
  11. Analyze recent conversation history to find improvements for the project CLAUDE.md.
  12.  
  13. ## Routing
  14.  
  15. | User says | Action |
  16. |-----------|--------|
  17. | "review claudemd", "update claudemd", "improve instructions" | Full review workflow below |
  18. | "setup-memory" | Same as above |
  19. | "what should I add to claudemd" | Same as above |
  20.  
  21. ## Step 1: Find Conversations
  22.  
  23. Locate JSONL session files. The project folder in `~/.claude/projects/` is the project's absolute path with `/` replaced by `-`:
  24.  
  25. ```bash
  26. PROJECT_PATH=$(pwd | sed 's|/|-|g' | sed 's|^-||')
  27. CONVO_DIR=~/.claude/projects/-${PROJECT_PATH}
  28. ls -lt "$CONVO_DIR"/*.jsonl 2>/dev/null | head -20
  29. ```
  30.  
  31. If the path contains spaces or special characters and `sed` fails, use Python instead:
  32.  
  33. ```bash
  34. python3 -c "
  35. import os
  36. project_dir = os.path.join(os.path.expanduser('~/.claude/projects'), '-' + os.getcwd().replace('/', '-').lstrip('-'))
  37. print(project_dir)
  38. "
  39. ```
  40.  
  41. Take the **15–20 most recent** files that contain actual conversation messages (skip files with only `file-history-snapshot` entries).
  42.  
  43. List what you found:
  44. ```
  45. Found N conversations (date range: YYYY-MM-DD to YYYY-MM-DD)
  46. ```
  47.  
  48. ## Step 2: Extract Conversation Text
  49.  
  50. Use this Python script via Bash to extract user/assistant text from session files. Replace `CONVO_DIR` with the path from Step 1.
  51.  
  52. ```bash
  53. python3 -c "
  54. import json, sys, os, glob
  55. from datetime import datetime
  56.  
  57. base = os.path.join(os.path.expanduser('~/.claude/projects'), '-' + os.getcwd().replace('/', '-').lstrip('-')) + '/'
  58. files = sorted(glob.glob(base + '*.jsonl'), key=os.path.getmtime, reverse=True)
  59.  
  60. MAX_SESSIONS = 20
  61. MAX_CHARS_PER_SESSION = 8000
  62. sessions_found = 0
  63.  
  64. for fpath in files:
  65. if sessions_found >= MAX_SESSIONS:
  66. break
  67. texts = []
  68. char_count = 0
  69. has_messages = False
  70. with open(fpath) as f:
  71. for line in f:
  72. obj = json.loads(line)
  73. role = obj.get('type', '')
  74. if role not in ('user', 'assistant'):
  75. continue
  76. has_messages = True
  77. content = obj.get('message', {}).get('content', '')
  78. if isinstance(content, str):
  79. if content.strip():
  80. texts.append(f'[{role}] {content.strip()}')
  81. char_count += len(content)
  82. elif isinstance(content, list):
  83. for block in content:
  84. bt = block.get('type', '')
  85. if bt != 'text':
  86. continue
  87. txt = block.get('text', '').strip()
  88. if not txt:
  89. continue
  90. if '<system-reminder>' in txt:
  91. clean = txt.split('<system-reminder>')[0].strip()
  92. if clean:
  93. texts.append(f'[{role}] {clean}')
  94. char_count += len(clean)
  95. continue
  96. texts.append(f'[{role}] {txt}')
  97. char_count += len(txt)
  98. if char_count >= MAX_CHARS_PER_SESSION:
  99. break
  100. if not has_messages:
  101. continue
  102. sessions_found += 1
  103. session_id = os.path.basename(fpath).replace('.jsonl', '')
  104. mtime = os.path.getmtime(fpath)
  105. date = datetime.fromtimestamp(mtime).strftime('%Y-%m-%d')
  106. output = '\n'.join(texts)
  107. if len(output) > MAX_CHARS_PER_SESSION:
  108. output = output[:MAX_CHARS_PER_SESSION] + '\n[...truncated]'
  109. print(f'=== SESSION {session_id} ({date}) ===')
  110. print(output)
  111. print()
  112. "
  113. ```
  114.  
  115. ## Step 3: Analyze with Subagents
  116.  
  117. First, read the current instructions:
  118. - `CLAUDE.md` (project root)
  119. - `.claude/rules/*.md` (all rule files)
  120.  
  121. Then launch **Sonnet subagents** (via Task tool, `subagent_type: "general-purpose"`, `model: "sonnet"`) to analyze the conversations. Batch **4–5 conversations per subagent**.
  122.  
  123. Each subagent prompt should include:
  124. 1. The full text of CLAUDE.md and rules files
  125. 2. The batch of conversation extracts
  126. 3. Instructions to return **structured JSON** with three categories:
  127.  
  128. ```json
  129. {
  130. "violated": [
  131. {
  132. "rule": "Which CLAUDE.md instruction was violated",
  133. "example": "Brief quote or description from conversation",
  134. "session": "session_id",
  135. "suggestion": "How to clarify or strengthen the rule"
  136. }
  137. ],
  138. "additions": [
  139. {
  140. "pattern": "What recurring pattern was observed",
  141. "example": "Brief evidence from conversations",
  142. "sessions": ["session_ids"],
  143. "suggested_rule": "Proposed text to add to CLAUDE.md"
  144. }
  145. ],
  146. "outdated": [
  147. {
  148. "rule": "Which CLAUDE.md instruction seems outdated",
  149. "evidence": "Why it appears outdated based on conversations",
  150. "suggestion": "Remove, update, or replace with..."
  151. }
  152. ]
  153. }
  154. ```
  155.  
  156. **Subagent instructions:** Look for patterns like:
  157. - User correcting Claude's behavior (suggests a missing/unclear rule)
  158. - Claude doing something the rules say not to do (violated rule)
  159. - Rules that never come up or contradict actual usage (outdated)
  160. - Repeated user preferences not captured in CLAUDE.md
  161. - Workflow patterns that should be documented
  162.  
  163. ## Step 4: Report
  164.  
  165. Aggregate results from all subagents. Deduplicate findings (same rule/pattern across sessions).
  166.  
  167. Present as **three markdown tables**:
  168.  
  169. ### Rules Violated
  170.  
  171. | Rule | Example | Sessions | Suggestion |
  172. |------|---------|----------|------------|
  173. | ... | ... | ... | ... |
  174.  
  175. ### Suggested Additions
  176.  
  177. | Pattern | Evidence | Sessions | Suggested Rule |
  178. |---------|----------|----------|----------------|
  179. | ... | ... | ... | ... |
  180.  
  181. ### Potentially Outdated
  182.  
  183. | Rule | Evidence | Suggestion |
  184. |------|----------|------------|
  185. | ... | ... | ... |
  186.  
  187. If a category has no findings, show: *"No findings in this category."*
  188.  
  189. ## Step 5: Ask Before Editing
  190.  
  191. **Mandatory confirmation.** Never edit CLAUDE.md without asking.
  192.  
  193. Present options:
  194. 1. **Apply all** — make all suggested changes
  195. 2. **Pick individually** — go through each finding one by one
  196. 3. **Skip** — don't edit, optionally save report
  197.  
  198. If user picks **Apply all** or **Pick individually**:
  199. - Make edits to CLAUDE.md using the Edit tool
  200. - Show a summary of what changed
  201.  
  202. If user picks **Skip**:
  203. - Offer to save the report as a note
  204.  
  205. ## Edge Cases
  206.  
  207. - **Few conversations (<5):** Proceed but note limited data: *"Only N sessions found — results may be incomplete."*
  208. - **No conversations:** Report it and exit: *"No conversation history found for this project."*
  209. - **Empty sessions:** Already filtered out in Step 2
  210. - **No findings:** *"No issues found! Your CLAUDE.md looks well-aligned with actual usage."*
  211.  
Advertisement
Add Comment
Please, Sign In to add comment