# Refine

> Continual-harness refinement (port of prime-agent's /refine). Reviews the current session trajectory and applies small, evidence-backed create/update/delete edits to persistent memory, logging before/after snapshots to support rollback. Use when the user runs /refine, /refine rollback <id>, or asks to persist lessons from this session.

- Skill: `emran05/refine` (Agent Skill)
- Install (CLI): `npx skillmds@latest add emran05/refine`
- Raw SKILL.md: https://api.skillmd.com/api/skills/emran05/refine/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: Emran05 (https://skillmd.com/u/emran05)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/emran05/refine

---


# /refine — continual harness refinement

Port of prime-agent's Continual Harness for Claude Code. Reviews what happened
in the current session and persists a small number of durable lessons into the
memory system, each backed by quoted evidence, each snapshotted for rollback.

## Invocations

- `/refine` — review the trajectory, propose and apply refinements
- `/refine <instructions>` — refine with focus (e.g. "only capture the deploy workflow")
- `/refine rollback <id>` — undo a recorded refinement
- `/refine history` — list recent refinements from the log

## Storage layout

- **Harness state** = the persistent memory directory (listed in your system
  prompt's Memory section) — memory files + `MEMORY.md` index. That is the
  supplemental state this skill edits.
- **Refinement log** = `~/.claude/harness/refinements.jsonl` (create the
  directory if missing). One JSON object per line.

## Refinement procedure

1. **Review the trajectory.** Scan the conversation for durable lessons:
   corrections the user made, approaches that worked after failures, workflow
   patterns repeated 2+ times, project constraints discovered the hard way,
   reusable subagent/tool recipes. Ignore anything session-specific,
   already-recorded, or derivable from the repo itself.

2. **Propose at most 5 edits.** Each edit is one of:
   - `create` — a new memory file (kinds: `user`, `feedback`, `project`, `reference`)
   - `update` — revise an existing memory file that this session proved wrong or incomplete
   - `delete` — remove a memory this session invalidated

   Every edit MUST carry **evidence**: a short verbatim quote (or precise
   paraphrase with location) from THIS conversation showing why the edit is
   warranted. No evidence, no edit. Prefer fewer, higher-confidence edits.

3. **Hard rules (immutability):**
   - NEVER edit `~/.claude/CLAUDE.md`, project `CLAUDE.md`, or any settings
     file — those are the immutable base prompt, exactly as in prime-agent.
   - Only memory files and `MEMORY.md` index lines may change.
   - Respect the existing memory frontmatter format; keep entries short.

4. **Apply and log.** For each applied edit, append one line to
   `~/.claude/harness/refinements.jsonl`:
   ```json
   {"id": "<8-hex>", "ts": "<ISO-8601>", "action": "create|update|delete",
    "file": "<memory file path>", "evidence": "<the quote>",
    "before": <full prior file content as string, or null>,
    "after": <full new file content as string, or null>,
    "index_before": "<prior MEMORY.md line or null>",
    "index_after": "<new MEMORY.md line or null>"}
   ```
   Generate the id with 8 random hex chars. `before`/`after` snapshots are the
   rollback mechanism — never skip them.

5. **Report.** Tell the user what was created/updated/deleted, one line each
   with its refinement id and the evidence, so rollback ids are visible.

## Rollback procedure (`/refine rollback <id>`)

1. Find the line with matching `id` in `~/.claude/harness/refinements.jsonl`.
2. Invert it: `create` → delete the file and its index line; `update` →
   restore `before` content and `index_before`; `delete` → recreate the file
   from `before` and restore its index line.
3. Append a new log line recording the rollback (action `rollback`, with the
   inverse snapshots), and confirm to the user.

## Mapping prime-agent kinds → memory types

- prompt note → `feedback` memory (how to behave, with **Why** and **How to apply**)
- memory → `user` or `project` memory (facts, preferences, constraints)
- skill description → `reference` memory describing a reusable call, e.g. an
  rlm-repl `py_exec` recipe or a shell one-liner, with exact invocation
- subagent spec → `reference` memory containing a reusable Agent-tool prompt
  (agent type, prompt template, when to use)

## Calibration

Prime-agent's own weakness (verified by source audit): "evidence-backed" was
prompt-only there. Here the evidence quote is mandatory in every log line, and
an edit without a verifiable quote from the current conversation must be
dropped. When in doubt, propose nothing — an empty refinement is a valid
outcome and better than memory pollution.

