Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to claude-reflect will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- **`/reflect --workflows`** — Scans past sessions for recurring command sequences and
operational procedures. Generates `docs/WORKFLOWS.md` with copy-paste ready steps
grouped by category (build, deploy, test, etc.). Only includes patterns seen 3+ times.

## [3.1.0] - 2026-03-16

### Added
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Example: You've asked "review my productivity" 12 times → suggests creating `/
| **Skill Discovery** | Finds repeating patterns in your history → generates commands |
| **Multi-language** | AI understands corrections in any language |
| **Skill Improvement** | Corrections during `/deploy` improve the deploy skill itself |
| **Workflow Extraction** | Finds recurring command sequences → generates `WORKFLOWS.md` |

## Installation

Expand Down Expand Up @@ -82,6 +83,7 @@ After installation, **restart Claude Code** (exit and reopen). Then hooks auto-c
| `/reflect --targets` | Show detected config files (CLAUDE.md, AGENTS.md) |
| `/reflect --review` | Show queue with confidence scores and decay status |
| `/reflect --dedupe` | Find and consolidate similar entries in CLAUDE.md |
| `/reflect --workflows` | Extract recurring procedures → `docs/WORKFLOWS.md` |
| `/reflect --include-tool-errors` | Include tool execution errors in scan |
| `/reflect-skills` | Discover skill candidates from repeating patterns |
| `/reflect-skills --days N` | Analyze last N days (default: 14) |
Expand Down
88 changes: 88 additions & 0 deletions commands/reflect.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ allowed-tools: Read, Edit, Write, Glob, Bash, Grep, AskUserQuestion, TodoWrite
- `--organize`: Analyze memory hierarchy and suggest reorganization across tiers.
- `--include-tool-errors`: Include project-specific tool execution errors in scan (auto-enabled with `--scan-history`).
- `--model MODEL`: Model for semantic analysis (default: `sonnet`). Use `haiku` for faster/cheaper runs or `opus` for maximum accuracy.
- `--workflows`: Extract recurring command sequences from past sessions → generate `docs/WORKFLOWS.md` with copy-paste ready procedures.

## Context
- Project CLAUDE.md: @CLAUDE.md
Expand Down Expand Up @@ -444,6 +445,93 @@ Use AskUserQuestion for each proposed reorganization:

**6. Exit after reorganization (don't process queue).**

### Handle --workflows Argument

**If user passed `--workflows`:**

Scan past sessions for recurring command sequences and operational procedures, then generate
`docs/WORKFLOWS.md` with copy-paste ready instructions.

**1. Find session files (same method as `--scan-history` Step 0.5a).**

**2. Extract command patterns:**

Search for tool calls, command sequences, and "how to do X" discussions:

```bash
# Find assistant messages with multiple bash commands in sequence
grep -h '"type":"tool_use"' SESSION_FILES | grep '"name":"Bash"' | head -100

# Find user messages asking for procedures
grep -h -o '"content":"[^"]*\(how to\|how do I\|steps to\|procedure\|workflow\)[^"]*"' SESSION_FILES | head -50
```

**3. Identify workflow categories by frequency:**

Group extracted commands by purpose. Common categories to look for:
- File transfer (rsync, scp, cp)
- Build processes (make, npm, cargo, go build)
- Deployment (deploy, push, restart)
- Testing (test, pytest, jest, cargo test)
- Debugging (logs, status checks, diagnostics)
- Database operations (migrate, seed, query)
- Git operations (common multi-step sequences)

Only include categories that appear **3 or more times** across sessions.

**4. Generate `docs/WORKFLOWS.md`:**

```markdown
# Operational Workflows

> Auto-generated by /reflect --workflows from session history.
> Update manually as procedures evolve.

## Index
1. [Workflow A]
2. [Workflow B]

---

## [Workflow Name]

**Frequency:** Used N times across M sessions.

### Prerequisites
- [requirement]

### Steps

\`\`\`bash
# Step 1: [Description]
[exact command from session history]

# Step 2: [Description]
[exact command from session history]
\`\`\`

### Notes
- [Any caveats or gotchas observed in sessions]

### Troubleshooting
- **Problem:** [X] → **Solution:** [Y]
```

**5. Show summary and ask user to review before writing:**

```
Found N workflow categories (M total procedures):
- Build & Deploy: 12 occurrences
- Database: 7 occurrences
- Testing: 5 occurrences

Write docs/WORKFLOWS.md? (Y/n)
```

**6. Exit after workflow extraction (don't process queue).**

---

### First-Run Detection (Per-Project)

Check if /reflect has been run in THIS project before. Run these commands separately:
Expand Down
Loading