refactor

refactor is a skill for Claude Code, Codex from richardcb/oh-my-gemini. It costs 47 tokens per session (1,319 once invoked), scanned A, original, MIT.

A code-restructuring workflow that preserves how the software behaves. It requires a clean Git working tree, passing tests, and successful type checks before changes are made.

In plain words
What is it for?
Use it to remove duplication, improve structure or readability, simplify code, and address technical debt when tests and type checks are available.
Why use it?
It reduces the risk of breaking existing behavior during cleanup or reorganization by checking the project before and after the work.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to remove duplication, improve structure or readability, simplify code, and…

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/richardcb/oh-my-gemini/refactor
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.

Any agent
npx skills add richardcb/oh-my-gemini --skill refactor
Clone the repo
git clone --depth 1 https://github.com/richardcb/oh-my-gemini

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/richardcb/oh-my-gemini/refactor.svg)](https://agentmods.dev/skills/richardcb/oh-my-gemini/refactor)
Your own site
<a href="https://agentmods.dev/skills/richardcb/oh-my-gemini/refactor"><img src="https://agentmods.dev/badge/skills/richardcb/oh-my-gemini/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 47 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,319 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00047 $0.01319
Opus 5 $0.00023 $0.00660
Sonnet 5 $0.00009 $0.00264
Haiku 4.5 $0.00005 $0.00132

Measured 6d ago against content hash df6f8dfb8320, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, 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 6d 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.

skills/refactor/SKILL.md · 195 lines

How it starts

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

Refactor Skill

Goal

Restructure existing code to improve quality, readability, or maintainability without changing external behavior. Every refactor must be provably safe through tests and type checks.

Activation Triggers

  • User says "refactor", "restructure", "clean up", "reorganize", or "simplify"
  • Code review identified structural issues
  • Technical debt needs to be addressed
  • Code duplication needs to be consolidated

Safety Checklist (Pre-Flight)

Before making any changes, verify all of these:

1. Git State is Clean

# Ensure no uncommitted changes
git status --short 2>/dev/null

If there are uncommitted changes, ask the user to commit or stash them first. Refactoring on a dirty working tree makes rollback difficult.

2. Tests Exist and Pass

# Run full test suite
npm test 2>&1 | tail -30

# Check exit code
echo "Exit code: $?"

If no tests exist: Stop and suggest using the test-generation skill first. Refactoring without tests is risky - you cannot verify behavior is preserved.

3. Types Check Clean

# Verify no type errors
npm run typecheck 2>&1 | tail -20 || tsc --noEmit 2>&1 | tail -20

Process

1. Define Scope

Clearly identify what is being refactored and why:

Questions to answer:

  • What specific code needs restructuring?
  • Why does it need to change? (readability, performance, maintainability)
  • What is explicitly NOT being changed?
  • What is the expected outcome?
# Understand the code to refactor
cat [target-file] | head -100

# Find all usages/callers
grep -rn "functionOrClassName" src/ --include="*.ts" --include="*.js" | head -20

# Check test coverage for this code
find . -name "*.test.*" -o -name "*.spec.*" 2>/dev/null | xargs grep -l "functionOrClassName" 2>/dev/null

2. Verify Tests Pass (Before)

# Run tests - record baseline
npm test 2>&1 | tail -30

# Run typecheck - record baseline
npm run typecheck 2>&1 | tail -20 || tsc --noEmit 2>&1 | tail -20

Read the full file on GitHub · 195 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. 6d ago First seen · 195 lines · 47 tokens per session scan A df6f8dfb8320

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository richardcb/oh-my-gemini (16 stars, last pushed 5mo ago), licensed MIT. It adds 47 tokens to every session and 1,319 once invoked, about $0.0002 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.

Related

Other skills, from other repositories

intuitive-tests

Use this skill whenever the user asks about unit test best practices, test organization, flat test suites, redundant tests, test refactors, pytest/JUnit/Jest/xUnit layout, test taxonomy, flaky tests, coverage quality, fixtures, mocks, parametrization, pruning existing UTs, or "which tests are worth keeping." It…

MiaoDX/intuitive-flow · 154 tokens

intuitive-preflight

Turn a vague task, plan, issue, or "LGTM/go ahead" request into an approval-ready preflight contract before implementation starts. Use when the user wants prompt preflight, clearer scope, non-goals, context package, acceptance criteria, definition of done, verification, stop gates, the exact execution command, or…

MiaoDX/intuitive-flow · 112 tokens

intuitive-refactor

Refactor and cleanup router for known code/module/API seams, stale surfaces, compatibility shims, architecture cleanup targets, changed-code quality review, oversized modules, repeated cleanup campaigns, and recurring whole-repo architecture maintenance goals. Use this when the user names a concrete seam, wants…

MiaoDX/intuitive-flow · 185 tokens

skill-runner

Run a bounded development task through named skills in an isolated, tmux-backed Codex or Claude session. Use for durable or artifact-sensitive worker phases, supervised skill runs, and post-run skill evaluation.

MiaoDX/intuitive-flow · 45 tokens

intuitive-doc

Create and maintain an intuitive human documentation surface for AI-agent-developed repos. Use when humans should only need README.md, ARCHITECTURE.md, STATUS.md, and docs/human/ while planning logs, generated docs, retrospectives, ADR detail, and implementation evidence stay in AI-agent-only folders.

MiaoDX/intuitive-flow · 64 tokens

intuitive-shape

Shape a raw product or project idea into a bounded decision before planning or implementation. Use when deciding whether an idea deserves a bet, setting an appetite, comparing candidate bets under finite capacity, cutting scope, exposing rabbit holes and no-gos, or choosing BET, RESEARCH, RESHAPE, or PASS. This skill…

MiaoDX/intuitive-flow · 126 tokens