# refinement

SPARC methodology subagent for iterative code refinement. Optimizes architecture, runs test suites, and learns from refactoring history.

- subagent · `type=agent` · Claude Code, Codex, Cursor · ★ 850 repo stars
- Author: ruvnet
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/ruvnet/agentic-flow/tree/HEAD/agentic-flow/.claude/agents/sparc/refinement.md
- Updated: 2026-10-26
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/agents/refinement

## What it does

This agent handles the refinement phase in the SPARC workflow. It focuses on code tuning, unit test creation, and structural cleanup. Before touching the code, the pre-hook queries ReasoningBank to retrieve prior refactoring patterns and review previous test failures on similar tasks.

Execution relies on lifecycle hooks. A baseline check runs through `npm test`, while a post-hook calculates test coverage alongside overall test success. When tests pass, the hook triggers neural pattern training via `claude-flow@alpha` to preserve verified optimizations.

Because the hooks depend directly on `npx claude-flow@alpha` and `npm`, running this subagent without Node.js tooling causes memory queries and quality tracking to fail silently.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/agents/refinement.md` — For all projects use ~/.claude/agents/. Claude delegates by the description field or an @-mention

### Codex

**Manually: put the files in place**
- File: `.codex/agents/refinement.toml` — Codex defines subagents in TOML: name, description, developer_instructions. Move the Markdown text into developer_instructions by hand. For all projects use ~/.codex/agents/

### Cursor

**Manually: put the files in place**
- File: `.cursor/agents/refinement.md` — Cursor also reads .claude/agents/

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/ruvnet/agentic-flow/tree/HEAD/agentic-flow/.claude/agents/sparc/refinement.md

## When to use it
- refactor complex modules using historical pattern memory
- generate unit tests to increase test suite coverage
- store refactoring benchmarks and test metrics across sessions
- detect bottlenecks across interdependent code modules

## Example prompts
- Run refinement on the user service and improve test coverage
- Refactor database cache calls using patterns from previous sessions
- Inspect recent test failures and optimize error handling in the auth module

## Similar
- [sparc-methodology](https://affpapa.org/en/nevibecode/skills/sparc-methodology.md) — skill · 1200 installs
- [stream-chain](https://affpapa.org/en/nevibecode/skills/stream-chain.md) — skill · 1200 installs
- [iterative-refinement](https://affpapa.org/en/nevibecode/skills/iterative-refinement.md) — skill · ★ 173 repo stars
- [qcsd-refinement-swarm](https://affpapa.org/en/nevibecode/skills/qcsd-refinement-swarm.md) — skill · 105 installs
- [dspy-output-refinement-constraints](https://affpapa.org/en/nevibecode/skills/dspy-output-refinement-constraints.md) — skill · ★ 125 repo stars
- [quality-refinement-autoloop](https://affpapa.org/en/nevibecode/skills/quality-refinement-autoloop.md) — skill · 1400 installs

## Other versions with the same name
- [refinement · ruvnet](https://affpapa.org/en/nevibecode/agents/ruvnet-refinement.md) — ★ 850 repo stars

From the same set: [ruvnet/agentic-flow](https://affpapa.org/en/nevibecode/by/ruvnet/agentic-flow.md) — 76 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
