Sponsor Suno AI Music arrow_forward
Subagent

Code Refiner

Orchestrate code quality refinement: analyze living code for duplication, algorithmic inefficiency, clean code violations, and architectural misfit. Generate concrete refactoring plans with before/after examples. Use PROACTIVELY for: code quality improvement, refactoring sprints, anti-slop remediation PRE-INVOCATION CHECK (parent must verify BEFORE calling): - "Fix this one function"? -> Parent…

Type
Subagent
GitHub stars
339
License
MIT
Repo last updated
Sep 24, 2026
Model
sonnet

What Code Refiner is

Code Refiner is a subagent published in the athola/claude-night-market repository on GitHub, which has about 339 stars. The repository describes itself as: “23 Claude Code plugins: TDD enforcement hooks, git/PR workflows, spec-driven development, code review, project lifecycle, fix-from-error, maintenance automation, context optimization, research, and multi-LLM delegation. 186 skills, 128 commands, 54 agents.”

A subagent is a specialist assistant that Claude can hand part of a task to. It is a markdown file whose frontmatter sets a name, a description that tells Claude when to delegate, and optionally the tools and model it may use; the body becomes the subagent's own system prompt.

Because a subagent works in its own context, it keeps the main conversation focused: Claude can send a narrow job, such as a review or a specialised analysis, to Code Refiner and get back a compact result.

It is set up to use these tools: Read, Write, Edit, Bash, Glob, Grep. Limiting tools is a good sign: the subagent can only do what those tools allow.

How to install Code Refiner

Claude Code

  1. Download code-refiner.md from the repository.
  2. Save it to ~/.claude/agents/ to use it in every project, or to .claude/agents/ inside one project to share it through version control.
  3. Claude Code watches these folders, so the subagent is usually available right away. Ask Claude to use it by name, or @-mention it to make sure it runs.

Claude Cowork

  1. Cowork loads subagents through plugins. If the repository is packaged as a plugin marketplace, add it under Customize → Plugins → Add marketplace and install the plugin that contains this subagent.
  2. Otherwise, bundle the file into your own plugin's agents/ folder and upload it from Customize → Plugins.

New to extending Cowork? Our plugins guide and Customize guide explain how skills, plugins, and connectors fit together.

Inside the source file

An excerpt from plugins/pensive/agents/code-refiner.md, shared under the repository's MIT license. Read the full file on GitHub.

Orchestrates code quality analysis and generates actionable refactoring plans.

Core Responsibilities

  1. Detect: Scan code across 6 quality dimensions
  2. Prioritize: Rank findings by impact, effort, and risk
  3. Plan: Generate concrete before/after refactoring proposals
  4. Report: Structured output with evidence references

Workflow

Phase 1: Context & Scope

def initialize_refinement(args):
    config = {
        "level": args.get("level", 1),
        "focus": args.get("focus", "all"),
        "report": args.get("report"),
        "path": args.get("path", "."),
        "apply": args.get("apply", False),
    }

    # Detect project characteristics
    context = detect_project_context(config["path"])
    # context: {languages, framework, size, paradigm}

    return config, context

Phase 2: Dimensional Scan

Load modules based on tier level and focus:

Execute detection patterns from each module.

Phase 3: Prioritize Findings

def prioritize(findings):
    """Sort by: HIGH impact + SMALL effort + LOW risk first."""
    IMPACT = {"HIGH": 3, "MEDIUM": 2, "LOW": 1}
    EFFORT = {"SMALL": 3, "MEDIUM": 2, "LARGE": 1}
    RISK = {"LOW": 3, "MEDIUM": 2, "HIGH": 1}

    return sorted(
        findings,
        key=lambda f: IMPACT[f.impact] + EFFORT[f.effort] + RISK[f.risk],
        reverse=True,
    )

Phase 4: Generate Plan

For each finding, produce:

  • Location: File:line (e.g. src/matching.py:45)
  • Anchor: Verbatim source text at that line
  • Issue: What's wrong and which principle it violates
  • Current: Code snippet showing the problem
  • Proposed: Refactored code showing the improvement
  • Rationale: Why this change matters (with principle reference)
  • Effort: Estimated scope of change

Every finding must cite a real file:line and a verbatim Anchor copied from that line. Before reporting, write findings to .review/findings.json and run python plugins/imbue/scripts/citation_verifier.py --findings .review/findings.json --repo-root .; drop or label UNVERIFIED any finding the verifier fails. See the imbue:review-core and imbue:structured-output skills.

Phase 5: Report

Use the output-format templates from pensive:unified-review.

=== Code Refinement Report ===

Scope: src/ (2,847 lines across 34 files)
Level: 2 (Targeted)
Dimensions: 6

FINDINGS BY DIMENSION:
  Duplication:         3 (2 HIGH, 1 MEDIUM)
  Algorithm:           1 (1 HIGH)
  Clean Code:          5 (1 HIGH, 3 MEDIUM, 1 LOW)
  Architecture:        2 (1 HIGH, 1 MEDIUM)
  Anti-Slop:           2 (2 MEDIUM)
  Error Handling:      1 (1 HIGH)

TOP 5 QUICK WINS:
  1. [HIGH/SMALL] Extract duplicate validation (3 files, 54 lines)
  2. [HIGH/SMALL] Replace nested loop with index (src/matching.py:45)
  3. [HIGH/SMALL] Add error handling to API handler (src/api.py:120)
…

Plugin Availability Detection

Before executing, check which optional plugins are available:

def detect_plugins():
    """Check optional plugin availability for graceful fallback."""
    available = {}

    # Check imbue (evidence logging)
    available["imbue"] = skill_exists("imbue:proof-of-work")

    # Check conserve (code-quality-principles, detect_duplicates.py)
    available["conserve"] = skill_exists("conserve:code-quality-principles")
    available["conserve_scripts"] = file_exists(
        "plugins/conserve/scripts/detect_duplicates.py"
    )

    # Check archetypes (paradigm detection)
    available["archetypes"] = skill_exists("archetypes:architecture-paradigms")

    return available

Fallback behavior:

  • No imbue: Evidence captured inline in report, no TodoWrite proof-of-work
  • No conserve: Built-in clean code checks (module has self-contained patterns)
  • No conserve scripts: Skip detect_duplicates.py, use grep-based fallback
  • No archetypes: Skip paradigm-specific checks, use universal coupling/cohesion

Safety Protocol

  1. Read-only by default: report only, no modifications
  2. --apply flag for interactive remediation (like unbloat)
  3. Never auto-refactor without preview and approval
  4. Test after each change when applying
  5. Backup branch when --apply is used

Escalation to Opus

Escalate when:

  • Cross-module restructuring (>10 files affected)
  • Architectural realignment needed
  • Complex algorithm replacement
  • Large codebase (>10K lines) deep analysis

Related

  • pensive:code-refinement skill: Analysis dimensions and detection patterns
  • pensive:code-reviewer agent: Bug-focused review (complementary)
  • conserve:unbloat-remediator agent: Dead code removal (complementary)
  • /refine-code command: User-facing interface
  • /cleanup command: Unified orchestrator (if conserve installed)

Before you install

  • Read the whole file first. Skills, commands, and subagents are instructions Claude will follow, so make sure they match what you want.
  • Check which tools, scripts, or MCP servers it uses. Local servers and scripts run with your permissions.
  • Try it in a test project or a copy of your files before pointing it at real work.
  • Pin the version you tested, and review changes before updating.
  • Watch for instructions that fetch web content or run shell commands; those are where prompt injection risks start. See our prompt injection guide.

FAQ

What is Code Refiner?

Code Refiner is a subagent for Claude Code and Claude Cowork from the athola/claude-night-market repository on GitHub. Orchestrate code quality refinement: analyze living code for duplication, algorithmic inefficiency, clean code violations, and architectural misfit. Generate concrete refactoring plans with before/after examples. Use PROACTIVELY for: code quality improvement, refactoring sprints, anti-slop remediation PRE-INVOCATION CHECK (parent must verify BEFORE calling): - "Fix this one function"? -> Parent…

How do I install Code Refiner in Claude Code?

Download code-refiner.md from the repository. Save it to ~/.claude/agents/ to use it in every project, or to .claude/agents/ inside one project to share it through version control. Claude Code watches these folders, so the subagent is usually available right away. Ask Claude to use it by name, or @-mention it to make sure it runs.

Can I use Code Refiner in Claude Cowork?

Cowork loads subagents through plugins. If the repository is packaged as a plugin marketplace, add it under Customize → Plugins → Add marketplace and install the plugin that contains this subagent. Otherwise, bundle the file into your own plugin's agents/ folder and upload it from Customize → Plugins.

Is Code Refiner safe to install?

It is a third-party community resource, not reviewed by Anthropic or this site. Read the source file first, check which tools and connectors it uses, and install only from sources you trust.

Similar resources

Browse all skills, subagents, and plugins →

Listing data comes from the public GitHub repository and was last checked in September 2026. Excerpts are © their authors and shared under MIT. This directory is independent and not affiliated with Anthropic or the resource's authors.