# Workflow Examples

Detailed workflow examples for common session history recovery scenarios.

## Recover Files Deleted in Cleanup

**Scenario**: Files were deleted during code review, need to recover specific components.

```bash
# 1. Find sessions mentioning the deleted files
python3 scripts/analyze_sessions.py search /path/to/project \
    DeletedComponent ModelScreen RemovedFeature

# 2. Recover content from most relevant session
python3 scripts/recover_content.py ~/.claude/projects/.../session-id.jsonl \
    -k DeletedComponent ModelScreen \
    -o ./recovered/

# 3. Review recovered files
ls -lh ./recovered/
```

## Track File Evolution Across Sessions

**Scenario**: Understand how a file changed over multiple sessions.

```bash
# 1. Find sessions that modified the file
python3 scripts/analyze_sessions.py search /path/to/project \
    "componentName.jsx"

# 2. Analyze each session's file operations
for session in session1.jsonl session2.jsonl session3.jsonl; do
    python3 scripts/analyze_sessions.py stats $session --show-files | \
        grep "componentName.jsx"
done

# 3. Recover all versions
python3 scripts/recover_content.py session1.jsonl -k componentName -o ./v1/
python3 scripts/recover_content.py session2.jsonl -k componentName -o ./v2/
python3 scripts/recover_content.py session3.jsonl -k componentName -o ./v3/

# 4. Compare versions
diff ./v1/componentName.jsx ./v2/componentName.jsx
```

## Find Session with Specific Implementation

**Scenario**: Remember implementing a feature but can't find which session.

```bash
# Search for distinctive keywords from that implementation
python3 scripts/analyze_sessions.py search /path/to/project \
    "useModelStatus" "downloadProgress" "ModelScope"

# Review top match
python3 scripts/analyze_sessions.py stats <top-result-session.jsonl>
```

## Batch Recovery Across Multiple Sessions

**Scenario**: Recover files containing a keyword from all matching sessions.

```bash
# Find relevant sessions
sessions=$(python3 scripts/analyze_sessions.py search /path/to/project \
    keyword --limit 999 | grep "Path:" | awk '{print $2}')

# Recover from each session
for session in $sessions; do
    output_dir="./recovery_$(basename $session .jsonl)"
    python3 scripts/recover_content.py "$session" -k keyword -o "$output_dir"
done
```

## Custom Extraction from Raw JSONL

For extraction needs not covered by bundled scripts:

```python
import json

with open('session.jsonl', 'r') as f:
    for line in f:
        data = json.loads(line)
        # Custom extraction logic
        # See references/session_file_format.md for structure
```
