# Context Digest Pattern

## Purpose

Reduces token usage between multi-step skill executions (BA, business-analyse-develop) by compressing step outputs into compact summaries.

## How It Works

```
Step N completes
    ↓
Generate digest (max 50 lines)
    ↓
Pass digest to Step N+1 (in-context)
    ↓
Step N+1 reads:
  - Digest from previous step (compact)
  - 00-context.md for state variables
  - Full output files ONLY if digest indicates need
```

## Digest Sections

| Section | Max Lines | Content |
|---------|-----------|---------|
| Changes | 10 | Files modified with brief description |
| Decisions | 10 | Key architectural decisions |
| Findings | 10 | Issues found, patterns identified |
| State | 5 | Updated state variables |
| Blockers | 5 | Open issues, unresolved questions |
| Next | 5 | What the next step needs to know |

## Token Savings Estimate

| Scenario | Without Digest | With Digest | Savings |
|----------|---------------|-------------|---------|
| step-01 → step-02 | ~2000 tokens | ~500 tokens | 75% |
| step-02 → step-03 | ~1500 tokens | ~400 tokens | 73% |
| step-03 → step-04 | ~1800 tokens | ~450 tokens | 75% |
| **Total workflow** | ~5300 tokens | ~1350 tokens | **~75%** |

## Applies To

- BA skill (between phases)
- Ralph-loop skill (between tasks)
- Any future multi-step skill

## Resume Exception

When a skill resumes via `-r` flag:
- Digest is ephemeral (not saved to disk)
- Resume reads full output files from `.claude/output/` or `.business-analyse/`
- This ensures complete state restoration after session break
