code-refactor

code-refactor is a skill for Claude Code, Codex from u9401066/med-paper-assistant. It costs 36 tokens per session (718 once invoked), scanned A, original, Apache-2.0.

A code-refactoring workflow finds code that is too large, complex, deeply nested, or tightly connected, then plans and carries out structural improvements. It follows domain-driven design (DDD), an approach that organizes software around the business areas it represents.

In plain words
What is it for?
Use it to split long functions, oversized classes, crowded modules, repeated logic, and complicated conditionals. It can also plan tests and verify that tests pass after each refactoring step.
Why use it?
It helps prevent code from becoming difficult to understand and change as the project grows. It also checks that the project’s architectural layers keep the intended dependency direction.

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/u9401066/med-paper-assistant/code-refactor
Any agent
npx skills add u9401066/med-paper-assistant --skill code-refactor
Clone the repo
git clone --depth 1 https://github.com/u9401066/med-paper-assistant

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 code-refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/u9401066/med-paper-assistant/code-refactor.svg)](https://agentmods.dev/skills/u9401066/med-paper-assistant/code-refactor)
Your own site
<a href="https://agentmods.dev/skills/u9401066/med-paper-assistant/code-refactor"><img src="https://agentmods.dev/badge/skills/u9401066/med-paper-assistant/code-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 36 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 718 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.00036 $0.00718
Opus 5 $0.00018 $0.00359
Sonnet 5 $0.00007 $0.00144
Haiku 4.5 $0.00004 $0.00072

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

Security

Grade A, and why

code-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 4d 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/code-refactor/SKILL.md · 67 lines

What it actually says

程式碼重構技能

主動偵測並執行程式碼重構,維持 DDD 架構和程式碼品質。

觸發:「重構」「refactor」「太長了」「模組化」「拆分」,或偵測到超過閾值時主動觸發。


閾值設定

類型 警告 強制重構
檔案 > 200 行 > 400 行
類別 > 150 行 > 300 行
函數 > 30 行 > 50 行
目錄檔案數 > 10 > 15
圈複雜度 > 10 > 15
巢狀深度 > 3 層 > 4 層
參數數量 > 4 > 6
依賴數量 > 5 > 8

重構模式庫

# 模式 觸發條件
1 Extract Method 函數過長、重複邏輯
2 Extract Class 類別職責過多、>150 行
3 Replace Conditional with Polymorphism 大量 if-elif-else
4 Introduce Parameter Object 參數 >4 個
5 Split Module 目錄 >10 檔案 → 按子領域拆分

DDD 架構守護

依賴方向:Presentation → Application → Domain ← Infrastructure

禁止:Domain 依賴 Infrastructure、Presentation 直接存取 Domain、Entity 包含持久化邏輯。


重構流程

  1. 偵測:報告檔案/函數/複雜度超標情況
  2. 分析:識別重複邏輯、隱藏 Value Object、職責分離點
  3. 規劃:列出重構步驟(新檔案、遷移、測試)
  4. 執行:逐步重構,每步確認測試通過
  5. 驗證:全部測試通過、覆蓋率、複雜度、DDD 合規

與其他 Skills 整合

Skill 整合
code-reviewer 審查時觸發重構建議
test-generator 重構前先生成測試
ddd-architect 確保重構符合 DDD
memory-updater 記錄重構決策
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. 4d ago First seen · 67 lines · 36 tokens per session scan A 4f6a2343949d

Subscribe to this mod's changes

code-refactor is a skill published in the GitHub repository u9401066/med-paper-assistant (11 stars, last pushed 17d ago), licensed Apache-2.0. It adds 36 tokens to every session and 718 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

citation-manager

Format and manage citations — APA, MLA, Chicago, IEEE, and Vancouver styles with BibTeX export.

inbharatai/claude-skills · 25 tokens

e2e-testing

E2E test authoring for Backseat Driver. Use when: writing, modifying, or debugging e2e tests under e2e-test-ws/, adding new MCP test scenarios, investigating test failures, understanding test infrastructure, or working with files matching test.cljs in the e2e workspace.

BetterThanTomorrow/calva-backseat-driver · 66 tokens

author

Scaffold a conforming AI-layer artifact — a rule, skill, hook, agent, or output style — that already passes the format checks, then verify it. Use when adding any new AI-layer artifact — a shared one under .agents/ or a Claude-only one under .claude/ — so it matches the existing shape instead of drifting.

Ashkaan/contextium · 72 tokens

close

The "wrap" verb of the loop — end the session by writing the journal entry, updating touched project READMEs, committing, and pushing. Auto-invoked as the tail of /spec and /implement (the producer verbs) on clean completion, so "wrap" is not a verb the user types; also runnable directly. Dispatches /implement-audit…

Ashkaan/contextium · 121 tokens

debate

Adversarial debate — spawn competing AI agents to argue a question, then synthesize the strongest conclusion. Use when the user says "debate this", "I'm torn between X and Y", "red-team this plan", or "council on this".

Ashkaan/contextium · 56 tokens

implement-audit

Adversarial review of freshly-built code — find what was missed, what's inconsistent, what breaks. The single code reviewer for the loop, and it runs exactly once per session. Auto-fired by /implement; standalone-callable after any substantial ad-hoc change. Emits the implement-audit: commit trailer the git hook…

Ashkaan/contextium · 71 tokens