/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
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.
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.
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.
Apply and log. For each applied edit, append one line to
~/.claude/harness/refinements.jsonl:
{"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.
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>)
- Find the line with matching
id in ~/.claude/harness/refinements.jsonl.
- 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.
- 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.
1---2name: refine3description: 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.4---56# /refine — continual harness refinement78Port of prime-agent's Continual Harness for Claude Code. Reviews what happened9in the current session and persists a small number of durable lessons into the10memory system, each backed by quoted evidence, each snapshotted for rollback.1112## Invocations1314- `/refine` — review the trajectory, propose and apply refinements15- `/refine <instructions>` — refine with focus (e.g. "only capture the deploy workflow")16- `/refine rollback <id>` — undo a recorded refinement17- `/refine history` — list recent refinements from the log1819## Storage layout2021- **Harness state** = the persistent memory directory (listed in your system22 prompt's Memory section) — memory files + `MEMORY.md` index. That is the23 supplemental state this skill edits.24- **Refinement log** = `~/.claude/harness/refinements.jsonl` (create the25 directory if missing). One JSON object per line.2627## Refinement procedure28291. **Review the trajectory.** Scan the conversation for durable lessons:30 corrections the user made, approaches that worked after failures, workflow31 patterns repeated 2+ times, project constraints discovered the hard way,32 reusable subagent/tool recipes. Ignore anything session-specific,33 already-recorded, or derivable from the repo itself.34352. **Propose at most 5 edits.** Each edit is one of:36 - `create` — a new memory file (kinds: `user`, `feedback`, `project`, `reference`)37 - `update` — revise an existing memory file that this session proved wrong or incomplete38 - `delete` — remove a memory this session invalidated3940 Every edit MUST carry **evidence**: a short verbatim quote (or precise41 paraphrase with location) from THIS conversation showing why the edit is42 warranted. No evidence, no edit. Prefer fewer, higher-confidence edits.43443. **Hard rules (immutability):**45 - NEVER edit `~/.claude/CLAUDE.md`, project `CLAUDE.md`, or any settings46 file — those are the immutable base prompt, exactly as in prime-agent.47 - Only memory files and `MEMORY.md` index lines may change.48 - Respect the existing memory frontmatter format; keep entries short.49504. **Apply and log.** For each applied edit, append one line to51 `~/.claude/harness/refinements.jsonl`:52 ```json53 {"id": "<8-hex>", "ts": "<ISO-8601>", "action": "create|update|delete",54 "file": "<memory file path>", "evidence": "<the quote>",55 "before": <full prior file content as string, or null>,56 "after": <full new file content as string, or null>,57 "index_before": "<prior MEMORY.md line or null>",58 "index_after": "<new MEMORY.md line or null>"}59 ```60 Generate the id with 8 random hex chars. `before`/`after` snapshots are the61 rollback mechanism — never skip them.62635. **Report.** Tell the user what was created/updated/deleted, one line each64 with its refinement id and the evidence, so rollback ids are visible.6566## Rollback procedure (`/refine rollback <id>`)67681. Find the line with matching `id` in `~/.claude/harness/refinements.jsonl`.692. Invert it: `create` → delete the file and its index line; `update` →70 restore `before` content and `index_before`; `delete` → recreate the file71 from `before` and restore its index line.723. Append a new log line recording the rollback (action `rollback`, with the73 inverse snapshots), and confirm to the user.7475## Mapping prime-agent kinds → memory types7677- prompt note → `feedback` memory (how to behave, with **Why** and **How to apply**)78- memory → `user` or `project` memory (facts, preferences, constraints)79- skill description → `reference` memory describing a reusable call, e.g. an80 rlm-repl `py_exec` recipe or a shell one-liner, with exact invocation81- subagent spec → `reference` memory containing a reusable Agent-tool prompt82 (agent type, prompt template, when to use)8384## Calibration8586Prime-agent's own weakness (verified by source audit): "evidence-backed" was87prompt-only there. Here the evidence quote is mandatory in every log line, and88an edit without a verifiable quote from the current conversation must be89dropped. When in doubt, propose nothing — an empty refinement is a valid90outcome and better than memory pollution.