$npx -y skills add microsoft/SkillOpt --skill skillopt-sleepUse when the user wants their Claude agent to self-improve from past usage, asks about a nightly/offline 'sleep' or 'dream' cycle, memory/skill consolidation, or says things like 'make my agent better the more I use it', 'review my past sessions', 'learn my preferences', 'consoli
| 1 | # SkillOpt-Sleep: usage-driven self-evolution for a local Claude agent |
| 2 | |
| 3 | SkillOpt-Sleep gives the user's agent a **sleep cycle**. On demand or on a |
| 4 | nightly schedule, it reviews real past Claude Code sessions, re-runs recurring |
| 5 | tasks through the selected backend, and consolidates what it |
| 6 | learns into **memory** (`CLAUDE.md`) and **skills** (`SKILL.md`). With the |
| 7 | default validation gate enabled, it keeps only changes that improve a held-out |
| 8 | score. Live files change only through explicit adoption or a user-requested |
| 9 | `--auto-adopt`. It aims to improve this user's recurring work, while making |
| 10 | each accepted proposal measurable on the run's held-out tasks, |
| 11 | with no model-weight training. It is the deployment-time analogue of training: |
| 12 | short-term experience → long-term competence. |
| 13 | |
| 14 | It synthesizes three ideas: |
| 15 | - **SkillOpt** — the skill/memory doc is trainable text; bounded add/delete/replace |
| 16 | edits; accepted only through a held-out gate; rejected edits are recorded in |
| 17 | the run report for review. |
| 18 | - **Claude Dreams** — consolidation that reads past sessions and proposes changes |
| 19 | inside protected learned blocks; the input is never mutated, and output is |
| 20 | reviewed before adoption. |
| 21 | - **Agent sleep** — periodic background replay turns episodes into durable skill. |
| 22 | |
| 23 | ## When to use this skill |
| 24 | |
| 25 | Trigger when the user wants any of: |
| 26 | - "make my agent learn from how I use it" / "get better the more I use it" / "remember my preferences across sessions" |
| 27 | - a nightly/scheduled or on-demand **offline self-improvement / dream / sleep** run |
| 28 | - to **review past sessions/trajectories** and distill recurring tasks |
| 29 | - to **consolidate** feedback into `CLAUDE.md` or a managed skill |
| 30 | - to **schedule** the cycle (cron) or **adopt** a staged proposal |
| 31 | |
| 32 | ## The cycle (six stages) |
| 33 | |
| 34 | 1. **Harvest** — read `~/.claude/projects/*/<session>.jsonl` + `~/.claude/history.jsonl` (READ-ONLY) → session digests. |
| 35 | 2. **Mine** — digests → `TaskRecord`s (recurring intents + outcome labels + checkable refs where possible). |
| 36 | 3. **Replay** — re-run tasks through the selected backend under the *current* |
| 37 | skill+memory → (hard, soft) scores. |
| 38 | 4. **Consolidate** — reflect on failures → propose bounded edits → **gate** on a held-out slice; with the default gate enabled, accept only if it strictly improves. |
| 39 | 5. **Stage** — write the accepted `proposed_CLAUDE.md` and/or |
| 40 | `proposed_SKILL.md`, plus `report.md`, `report.json`, `manifest.json`, and |
| 41 | `diagnostics.json` into `<project>/.skillopt-sleep/staging/<timestamp>/`. |
| 42 | **Nothing live changes.** A rejected run still has a report but no proposed |
| 43 | live-file replacement. |
| 44 | 6. **Adopt** — explicit (or opt-in auto): copy staged files over live ones, backing up first. |
| 45 | |
| 46 | ## How to drive it |
| 47 | |
| 48 | Prefer the `/skillopt-sleep` command. Under the hood it calls the bundled runner: |
| 49 | |
| 50 | ```bash |
| 51 | "${CLAUDE_PLUGIN_ROOT}/scripts/sleep.sh" status # what's happened |
| 52 | "${CLAUDE_PLUGIN_ROOT}/scripts/sleep.sh" dry-run --project "$(pwd)" # no-staging preview |
| 53 | "${CLAUDE_PLUGIN_ROOT}/scripts/sleep.sh" run --project "$(pwd)" # full cycle, stages a proposal |
| 54 | "${CLAUDE_PLUGIN_ROOT}/scripts/sleep.sh" adopt --project "$(pwd)" # apply staged proposal (with backup) |
| 55 | ``` |
| 56 | |
| 57 | - Default backend is `mock` (deterministic, **no API spend**) — good for trying the plumbing. |
| 58 | - Add `--backend claude` or `--backend codex` to spend the user's real budget |
| 59 | for model-driven optimization. A held-out gain is run-specific evidence, not |
| 60 | a guarantee of broader improvement; results depend on the tasks, model, and |
| 61 | checks. |
| 62 | - Scope defaults to the invoked project; `--scope all` harvests every Claude |
| 63 | project into the current run's configured targets. |
| 64 | - A real backend sends truncated transcript/task content to its provider. See |
| 65 | the data-boundary rules below before using one with sensitive sessions. |
| 66 | |
| 67 | ### Scheduling |
| 68 | |
| 69 | ```bash |
| 70 | "${CLAUDE_PLUGIN_ROOT}/scripts/sleep.sh" schedule --project "$(pwd)" --hour 3 --minute 17 |
| 71 | "${CLAUDE_PLUGIN_ROOT}/scripts/sleep.sh" unschedule --project "$(pwd)" |
| 72 | ``` |
| 73 | |
| 74 | Installs a nightly cron entry. `unschedule --all` removes every managed entry. |
| 75 | |
| 76 | ## Common CLI flags |
| 77 | |
| 78 | | Flag | Default | Description | |
| 79 | |------|---------|-------------| |
| 80 | | `--project PATH` | cwd | Project directory to evolve | |
| 81 | | `--scope all\|invoked` | invoked | Harvest scope | |
| 82 | | `--backend mock\|claude\|codex\|copilot\|handoff\|azure_openai` | mock | Backend (mock = no provi |