# SkillOpt-Sleep: nightly self-improvement from your past sessions (microsoft/SkillOpt) — skill card for AI agents

> AgentGid skill card. Checked on 2026-11-02 against commit e2edfa9 (version 0.2.0).
> Every fact comes from the pack's own files at that commit. Numbers marked "as reported" are the author's.
> Human page: https://agentgid.com/skills/microsoft/skillopt/

> Note: the pack has changed since this check; re-read its files before relying on details.

## Explain it to a non-programmer
Your assistant gets a "sleep cycle". On request or every night, it rereads your recent chats with it, finds tasks you repeat, retries them and proposes small edits to its own instruction files. An edit is kept only if it scores better on test tasks it held back, and nothing changes until you approve it.

## Who it is for
- You use Claude Code, Codex, Cursor, GitHub Copilot or Devin every day on similar tasks
- You want your assistant to learn your habits and preferences across sessions
- You are fine with installing Python 3.10 and running a few terminal commands
- Not for: Your chats contain secrets you cannot send to a model provider: the real modes send excerpts of them out
- Not for: You want a ready skill that changes the assistant at once; this one only proposes changes after a run

## What it is
- Kind: command, scripts
- License: MIT
- Repository: https://github.com/microsoft/SkillOpt

## What it does
- Harvest: read your past sessions from ~/.claude (read only)
- Mine: turn them into a list of recurring tasks
- Replay: run those tasks again with the current skill and memory, and score the answers
- Consolidate: look at failures, propose a few small add / delete / replace edits, keep them only if a held-out score goes up
- Stage: write the proposal and a report into <project>/.skillopt-sleep/staging/<timestamp>/; nothing live changes
- Adopt: on your command, copy the staged files over the live ones, with a backup first
- Never cuts: the held-out check (on by default); a backup before every adopt; your live CLAUDE.md and skill files stay untouched until adopt
- Level mock: Default: fixed rule-based answers, no model calls, no cost; tests the plumbing only
- Level real backend: claude, codex, cursor, copilot, pi, opencode or azure_openai: real model calls on your budget
- Level handoff: No model subprocess: the current session answers the prompts through fresh subagents

## Skills
| Skill | Call | Changes code? | In plain words |
|---|---|---|---|
| skillopt-sleep | /skillopt-sleep [run | dry-run | status | adopt | harvest | schedule | unschedule], or plain language ("run the sleep cycle") | no | Runs the sleep cycle and shows what your assistant would learn; edits its instruction files only when you adopt |
| skillopt-sleep-handoff | /skillopt-sleep-handoff [run | dry-run] (Claude Code only) | no | The same cycle, but the current chat answers the model questions, so no separate key is needed |

### skillopt-sleep
- Asks for: Your project folder (the current one by default)
- Asks for: Which model does the work: mock (free), claude, codex and others
- Asks for: Optional house rules, for example "Prefer pytest"
- Asks for: How far back to look (72 hours by default) and how many tasks (40 by default)
- Gives: A list of recurring tasks found in your sessions
- Gives: Held-out score before and after
- Gives: The gate decision: accept or reject
- Gives: The exact edits proposed to CLAUDE.md and the learned skill
- Gives: Where the proposal is staged, and a backup on adopt
- Say: "Run the sleep cycle for this project as a dry run"

### skillopt-sleep-handoff
- Asks for: run or dry-run
- Asks for: Optional house rules
- Gives: Up to 8 rounds of prompts answered in fresh, isolated helpers
- Gives: The same report: score before and after, decision, proposed edits
- Say: "/skillopt-sleep-handoff run"

## Know before installing
- This is mainly a research framework from Microsoft for training skill files on benchmarks; the installable part for assistants is SkillOpt-Sleep in the plugins folder.
- Real modes send shortened excerpts of your past chats to the chosen model provider, and secrets are not guaranteed to be removed. Use mock, or export the tasks, review them and mark them reviewed first.
- Adopt writes outside the project: the learned skill goes to ~/.claude/skills/skillopt-sleep-learned/SKILL.md by default, plus your project CLAUDE.md.
- The Claude Code plugin needs the Python engine too: a clone of the repository or pip install skillopt. PyPI 0.2.0 lacks handoff mode and some newer options.
- The token budget per night (400,000 by default) is not a hard cap: a started step finishes.
- --auto-adopt and gate_mode off remove the safety steps: changes go live, or every edit is accepted.

## Install (official commands)
- Claude Code: `git clone https://github.com/microsoft/SkillOpt.git` && `cd SkillOpt` && `/plugin marketplace add ./plugins/claude-code` && `/plugin install skillopt-sleep@skillopt-sleep` && `/skillopt-sleep status` — Needs Python 3.10+. If no engine is installed, the runner installs nothing itself: it prints `uv tool install skillopt` or `pip install skillopt` as a hint. Remove: `/plugin remove skillopt-sleep; also /skillopt-sleep unschedule if you scheduled it`.
- Codex: `bash plugins/codex/install.sh` — Copies the skill to ~/.agents/skills/skillopt-sleep/ and renames an old ~/.codex/prompts/sleep.md to a .bak file. Then set SKILLOPT_SLEEP_REPO in your shell profile. Remove: `delete ~/.agents/skills/skillopt-sleep/`.
- Cursor: `bash plugins/cursor/install.sh` && `powershell -File plugins/cursor/install.ps1 (Windows)` — Copies the plugin into ~/.cursor/plugins/local/skillopt-sleep; restart Cursor. Remove: `delete ~/.cursor/plugins/local/skillopt-sleep`.
- GitHub Copilot, Devin: Register plugins/copilot/mcp_server.py or plugins/devin/mcp_server.py using the example MCP config, then ask it to run sleep_status.
- Engine only (any agent): `pip install skillopt` && `python -m skillopt_sleep run --project "$(pwd)" --scope invoked --backend mock`

## What runs on the user's machine
- Code on the machine: yes (plugin and script installs; the engine is Python run through scripts/sleep.sh)
- Network: optional
- End of every Claude Code session: An async hook appends one line (time and folder) to ~/.skillopt-sleep/session-end.log. No optimizer, no network.
- /skillopt-sleep run, dry-run, harvest: Reads ~/.claude session files (read only), runs the Python engine; run writes reports and proposals to <project>/.skillopt-sleep/staging/<timestamp>/ and state to ~/.skillopt-sleep/.
- Real backend (opt-in): Calls the chosen tool as a subprocess, e.g. `claude -p` with tools and slash commands disabled in an empty temp folder; it uses your login or ANTHROPIC_API_KEY. azure_openai uses AZURE_OPENAI_* keys. Transcript excerpts go to that provider.
- /skillopt-sleep adopt: Copies staged files over your project CLAUDE.md and the target skill (default under ~/.claude/skills/), after a backup in the staging folder's backup/.
- /skillopt-sleep schedule: Adds a managed crontab entry (Unix) or Scheduled Task (Windows) that runs the cycle nightly; unschedule removes it.
- Codex / Cursor install: Shell or PowerShell scripts copy skill files into ~/.agents/skills or ~/.cursor/plugins/local.

## Settings
- `~/.skillopt-sleep/config.json`: preferences, gate_mode, gate_metric, gate_no_regression, dream_rollouts, recall_k, evolve_memory, evolve_skill, max_tokens_per_night, target_skill_path
- `SKILLOPT_SLEEP_REPO`: path to a SkillOpt clone so the runner finds the engine
- `SKILLOPT_SLEEP_PYTHON`: explicit Python interpreter for the runner
- `SKILLOPT_SLEEP_AGENT_MARKERS`: drop sessions whose first prompt contains one of these markers
- `SKILLOPT_SLEEP_NEG_FEEDBACK / SKILLOPT_SLEEP_POS_FEEDBACK`: extra phrases that count as rejecting or approving an answer
- `SKILLOPT_SLEEP_REPEAT_MIN_SESSIONS`: drop repeated single-turn template sessions (default 0, off)
- `ANTHROPIC_API_KEY`: optional auth for the claude backend
- `AZURE_OPENAI_ENDPOINT / AZURE_OPENAI_API_KEY / AZURE_OPENAI_AUTH_MODE`: for --backend azure_openai

## Examples (from the pack's own files)
- The harvest progress line: output format defined in plugins/claude-code/README.md
- What a run report shows: output format defined in plugins/claude-code/commands/skillopt-sleep.md

## Author's numbers (as reported, not run by AgentGid)
- Best or tied-best on all 52 evaluated (model, benchmark, harness) cells (Six benchmarks, seven target models, three harnesses; see the paper). Source: microsoft/SkillOpt/README.md
- On GPT-5.5, average no-skill accuracy up +23.5 points in direct chat, +24.8 in Codex, +19.1 in Claude Code. Source: microsoft/SkillOpt/README.md
- SkillOpt-Sleep on gbrain-evals brief-writer: held-out 0.00 → 1.00 with Claude Haiku 4.5 (1 night) and Codex (2 nights) (A deliberately deficient seed skill, local rule judge, small replay and holdout limits). Source: microsoft/SkillOpt/plugins/claude-code/README.md
- Without the gate, GPT-5.4-nano on SearchQA fell from 0.554 to 0.026 over 5 nights; with the gate it stayed at 0.570 (Optimizer GPT-5.5, single seed, gate off vs on). Source: microsoft/SkillOpt/docs/sleep/RESULTS.md

## Steps only the person can do
- Install and log in to the agent command line tool you pick as the backend (claude, codex, cursor-agent, copilot or pi) (plugins/README.md (Install)) Then: The assistant runs the cycle with --backend set to that tool
- For sensitive chats, open the exported task file, remove anything private and set "reviewed": true (plugins/README.md (Data boundary)) Then: The assistant replays the reviewed file with --tasks-file and a real backend
- Read the report (score before and after, proposed edits) and decide what to adopt (plugins/claude-code/commands/skillopt-sleep.md) Then: The assistant runs adopt with the selection you chose (--legacy, --skill NAME or --all-skills)
- For --backend azure_openai, put your own endpoint and key in AZURE_OPENAI_* environment variables (.env.example) Then: The assistant runs the cycle against your Azure or OpenAI-compatible endpoint

## Mistakes to avoid
- Not: Run it in the default mock mode and expect real improvement. Instead: Use mock only to check the setup; pick a real backend (claude, codex and others) or handoff for actual learning. Why: Mock gives fixed rule-based answers and makes no model calls
- Not: Install the engine with pip install skillopt and use handoff mode, --preferences or subset adoption. Instead: Use a source checkout of the repository from main, or wait for the next release. Why: PyPI 0.2.0 lacks these newer features
- Not: In handoff mode, answer the pending prompts in the same chat that started the cycle. Instead: Answer each prompt in a fresh, isolated context (the /skillopt-sleep-handoff command does this with subagents). Why: A context that has seen the held-out answers makes the score look better than it is
- Not: Schedule a nightly run with --source, --model or --target-skill-path on the command line and expect them to stick. Instead: Put transcript_source, model and target_skill_path in ~/.skillopt-sleep/config.json before scheduling. Why: The scheduled command stores only the project, backend, time and auto-adopt setting
- Not: Choose --backend azure_openai without setting AZURE_OPENAI_ENDPOINT. Instead: Set AZURE_OPENAI_ENDPOINT to your own endpoint first. Why: Without it the engine falls back to a built-in table of Azure endpoints in its code

## What leaves the machine
- Shortened excerpts of your past sessions and the tasks mined from them (mining, replay, judging and reflection prompts) → The provider behind the backend you pick (for example Anthropic through the claude tool, OpenAI through codex, Cursor and its model provider), Every run, dry-run or scheduled night with a real backend. Opt out: Use the default mock backend, or review and redact a task file first
- The same prompts, sent through the Cursor command line tool → Cursor and the model provider Cursor selects, Only with --backend cursor. Opt out: Use another backend or mock
- The same prompts, sent to an Azure OpenAI or OpenAI-compatible endpoint → AZURE_OPENAI_ENDPOINT, or a built-in Azure endpoint if it is not set, Only with --backend azure_openai. Opt out: Do not select azure_openai
- Pending prompts answered by fresh helpers in your current chat → The model provider of your current Claude Code session, Only with /skillopt-sleep-handoff. Opt out: Use mock, or stop when a batch looks private

## Lines in the pack aimed at agents (ask the person first)
- "| `schedule`   | install a nightly cron entry for this project (`--hour --minute`, off-:00 by default) |" (plugins/claude-code/commands/skillopt-sleep.md): A crontab entry or Scheduled Task is a lasting change on the computer; ask the person before scheduling.
- "Add `--backend claude` or `--backend codex` to spend the user's real budget" (plugins/claude-code/skills/skillopt-sleep/SKILL.md): A real backend costs money and sends chat excerpts to a provider; ask the person before leaving mock mode.
- "When a user asks about the sleep cycle or skill evolution, prefer calling these tools over explaining the concept." (plugins/devin/devin-rules.snippet.md): Explain first and run the tools only when the person asks for a run.
- "| `--auto-adopt` | off | Auto-adopt if gate passes |" (plugins/claude-code/skills/skillopt-sleep/SKILL.md): Auto-adopt changes live CLAUDE.md and skill files without review; use it only when the person asks for it.

## May I use it like this?
- commercial-app: yes (MIT: keep the copyright and license notice)
- redistribute-files: yes (MIT: include the copyright and permission notice in copies)
- client-work: yes (MIT allows use in work for others)
- inside-app-bundle: yes (MIT; the Python package declares the same license)

## Which one to pick
- If You want gated, measured edits to CLAUDE.md and a skill from replaying your past sessions, on demand or nightly: skill:microsoft/SkillOpt
- If You want corrections and preferences you give during work captured and synced to CLAUDE.md and AGENTS.md: skill:BayramAnnakov/claude-reflect
- If You want one skill evaluated, improved, tested, then kept or reverted in a loop: skill:alchaincyf/darwin-skill
- If You want to evaluate skills and evolve them with evidence, not learn from your own chats: skill:alibaba/skill-up

## Works well with
- agent:claude-code: The main plugin with /skillopt-sleep commands and a session-end hook is built for Claude Code
- agent:openai-codex: Codex gets the same engine as a user-level skill and can be the backend
- agent:cursor: A Cursor plugin, transcript source and cursor-agent backend are included
- tool:uv: The runner's fallback suggests uv tool install skillopt when no source checkout is found

## Works in and needs
- Works in Claude Code: plugin
- Works in Codex: skills folder
- Works in Cursor: plugin
- Works in GitHub Copilot: MCP server
- Works in Devin: MCP server
- Works in DeepSeek Harness: plugin
- Needs Python 3.10+: The engine is a Python package
- Needs An installed, logged-in agent command line tool (claude, codex, cursor-agent, copilot or pi): Only for real backends
- Needs Azure OpenAI or OpenAI-compatible endpoint and key: Only for --backend azure_openai

## How to tell it works
After installing, run /skillopt-sleep dry-run in a project you have used for a few days. It runs in mock mode, costs nothing and stages nothing; the output lists the recurring tasks it found and a held-out score. Switch to --backend claude only after reading what would be sent.

## Related
- alchaincyf/darwin-skill

## Safety
Install from github.com/microsoft/SkillOpt only. The plugin runs a small hook at every session end and Python code on demand; real backends send excerpts of your past sessions to a model provider, and adopt writes to ~/.claude/skills. The OpenClaw folder is a contributed reference with machine-specific paths: the repo says not to run it unchanged.
