refactor

A guided method for changing code structure while keeping its behavior, tests, and public interfaces intact.

In plain words
What is it for?
Use it to simplify code, move logic, rename or reorganize files, remove duplication, and split large refactors into smaller steps.
Why use it?
It reduces the risk of breaking callers or introducing unnoticed problems during code cleanup.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/actionhero/keryx/refactor
Any agent
npx skills add actionhero/keryx --skill refactor
Clone the repo
git clone --depth 1 https://github.com/actionhero/keryx

Made for: Claude Code, Codex.

Per session 87 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 949 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00087 $0.00949
Opus 5 $0.00044 $0.00475
Sonnet 5 $0.00017 $0.00190
Haiku 4.5 $0.00009 $0.00095

Measured 2d ago against content hash 5b398fc043dd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/refactor/SKILL.md · 102 lines

How it starts

The opening of the file, as written. The whole thing — 102 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Refactoring Workflow

Refactoring means changing code structure without changing behavior. Every step must preserve the existing test suite and public API contracts.

Phase 1: Understand Before Touching

  1. Read the target code — understand what it does, who calls it, and what depends on it
  2. Check for tests — find existing test coverage for the code being refactored
    • Search in packages/keryx/__tests__/ for framework code
    • Search in example/backend/__tests__/ for app code
  3. Run the existing tests to establish a green baseline before making changes:
    cd packages/keryx && bun test        # framework code
    cd example/backend && bun test       # app code
    
  4. Check for stale processes if tests behave unexpectedly:
    ps aux | grep "bun keryx" | grep -v grep
    

Phase 2: Plan the Refactoring

Before writing code, state the plan concisely:

  • What structural change you're making and why it improves the code
  • Which files will be created, modified, or deleted
  • Any import paths that will change
  • Whether the public API surface changes (it shouldn't)

If the refactoring is large (touches more than 5 files), break it into incremental steps where tests pass after each step.

Phase 3: Make Changes

Apply changes incrementally. After each logical step, verify nothing broke.

Import Conventions (must follow)

  • In packages/keryx/ — use relative imports:
    import { api } from "../api";
    import { Action } from "../classes/Action";
    
  • In example/backend/ — use "keryx" for framework, relative for app-local:
    import { api, Action, type ActionParams, HTTP_METHOD } from "keryx";
    import { SessionMiddleware } from "../middleware/session";
    

Code Quality Rules

  • No as any — use @ts-expect-error with a comment if the type system can't express something
  • JSDoc annotations on any new or modified public APIs in packages/keryx/
  • Don't add unnecessary abstractions — three similar lines are better than a premature helper
  • Don't add comments, docstrings, or type annotations to code you didn't change
  • If something is unused after the refactor, delete it completely — no _unused renames or // removed comments

Read the full file on GitHub · 102 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 102 lines · 87 tokens per session scan A 5b398fc043dd

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository actionhero/keryx (33 stars, last pushed 10d ago), licensed MIT. It adds 87 tokens to every session and 949 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.