# refinement

SPARC refinement phase agent for iterative code polish. Drives test-driven development: creates failing tests, satisfies them, and cleans up structure.

- 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/.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/ruvnet-refinement

## What it does

The refinement subagent manages the code polish phase within the SPARC methodology. It guides development through a strict test-driven loop: assembling failing tests for required behavior, writing minimal code to make them pass, and refactoring without regressions.

Built-in lifecycle hooks automate state tracking. The pre-hook logs the active phase to memory and runs `npm test --if-present`. Once work wraps up, the post-hook re-runs `npm test` and writes a timestamped record to memory.

Because both hooks execute `npm test`, the agent expects a configured test runner in the repository.

## 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/.claude/agents/sparc/refinement.md

## When to use it
- create failing unit tests before drafting service logic
- refactor complex classes while keeping test suites green
- tighten error handling and account lock workflows
- trigger automated test suites across iteration stages

## Example prompts
- Run the refinement agent on the auth module using TDD
- Refactor the AuthenticationService class and verify with tests
- Write failing tests for account lockout and implement the fix

## Similar
- [sparc-methodology](https://affpapa.org/en/nevibecode/skills/sparc-methodology.md) — skill · 1200 installs
- [tdd](https://affpapa.org/en/nevibecode/skills/sentimony-tdd.md) — skill · 2700 installs
- [fix-tests](https://affpapa.org/en/nevibecode/skills/fix-tests.md) — skill · 1300 installs
- [implement](https://affpapa.org/en/nevibecode/skills/pwguler-implement.md) — skill · 1000 installs
- [w-tdd](https://affpapa.org/en/nevibecode/skills/w-tdd.md) — skill · 647 installs
- [typescript-clean-code](https://affpapa.org/en/nevibecode/skills/typescript-clean-code.md) — skill · 669 installs

## Other versions with the same name
- [refinement · ruvnet](https://affpapa.org/en/nevibecode/agents/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
