Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Dev Refactor

ASecurity

Refactor code for better structure and patterns

15 stars
0 votes
0 copies
0 views
Added 9/23/2026
developmenttypescriptpythonrustgojavakotlinbashreactspringrefactoring

Security Analysis

A100/100

Scanned 9/23/2026

Install to Claude Code

$npx -y skills add baekenough/second-brain --skill dev-refactor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dev Refactor?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Dev Refactor
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/baekenough-dev-refactor-second-brain/badge)](https://www.skillsdirectory.com/skills/baekenough-dev-refactor-second-brain)

More formats (shields.io, HTML) on the badges page.

Download with Pro
Files
SKILL.md
---
name: dev-refactor
description: Refactor code for better structure and patterns
scope: core
argument-hint: "<file-or-directory> [--lang <language>] [--spec]"
user-invocable: true
---

# Code Refactoring Skill

Refactor code for better structure, naming, and patterns using language-specific expert agents.

## When NOT to Use

| Scenario | Better Alternative |
|----------|--------------------|
| Renaming only (no structural change) | IDE rename refactoring or `sed` |
| Formatting cleanup | Run formatter (`prettier`, `gofmt`, `black`) |
| No test coverage for target code | Write tests first (`/structured-dev-cycle`) |
| Moving files between directories | `git mv` via mgr-gitnerd |

**Pre-execution check**: Verify test coverage exists for the refactoring target. Refactoring without tests risks silent regressions.

## Pre-flight Guards

Before executing the refactoring workflow, the agent MUST run these checks:

### Guard 1: Test Coverage Check
**Level**: WARN
**Check**: Verify test files exist for the refactoring target
```bash
# For target file src/module/foo.ts, check for:
# - src/module/foo.test.ts
# - src/module/foo.spec.ts
# - tests/module/foo.test.ts
# - test/module/foo.test.ts
# - __tests__/module/foo.test.ts
# For Go: foo_test.go in same package
# For Python: test_foo.py or foo_test.py
```
**Action**: `[Pre-flight] WARN: No test file found for {target}. Refactoring without tests risks silent regressions. Consider writing tests first (/structured-dev-cycle).`

### Guard 2: Rename-Only Detection
**Level**: INFO
**Check**: If the user request is purely about renaming (no structural change)
```
# Keyword detection in user request
keywords: rename, 이름 변경, 이름 바꿔, rename variable, rename function
# AND no structural keywords
structural_keywords: extract, split, merge, restructure, reorganize, decompose
```
**Action**: `[Pre-flight] INFO: For rename-only refactoring, IDE rename (F2) or sed is faster and safer (handles all references). Proceeding with full refactoring.`

### Guard 3: Formatting-Only Request Detection
**Level**: INFO
**Check**: If the request is about formatting or style cleanup
```
# Keyword detection
keywords: format, formatting, indent, indentation, 포맷, 스타일, whitespace, spacing
```
**Action**: `[Pre-flight] INFO: For formatting cleanup, run the appropriate formatter (prettier, gofmt, black, rustfmt). Proceeding with full refactoring.`

### Guard 4: File Move Detection
**Level**: INFO
**Check**: If the request is about moving files between directories
```
# Keyword detection
keywords: move file, move to, 파일 이동, 옮겨, relocate, reorganize files
# AND no code-level changes mentioned
```
**Action**: `[Pre-flight] INFO: For file moves without code changes, use git mv via mgr-gitnerd to preserve git history.`

### Display Format

```
[Pre-flight] dev-refactor
├── Test coverage: WARN — no test file for src/utils.ts
├── Rename-only: PASS
├── Formatting-only: PASS
└── File move: PASS
Result: PROCEED WITH CAUTION (0 GATE, 1 WARN, 0 INFO)
```

If any GATE: block and suggest prerequisite.
If any WARN: show warning, ask user to confirm.
If only PASS/INFO: proceed automatically.

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| path | string | yes | File or directory to refactor |

## Options

```
--lang, -l       Language (auto-detected if not specified)
                 Values: go, python, rust, kotlin, typescript, java
--focus, -f      Focus area (structure, naming, patterns, all)
--dry-run        Show proposed changes without applying
--verbose, -v    Detailed output
```

## Workflow

```
0. Run pre-flight guards (MUST complete before proceeding)
1. Detect language (or use --lang)
2. Select appropriate expert agent
3. Load language-specific skill
4. Analyze code structure
5. Propose refactoring changes
6. Apply changes (if not --dry-run)
```

## Agent Selection

| File Extension | Agent | Skill |
|----------------|-------|-------|
| .go | lang-golang-expert | go-best-practices |
| .py | lang-python-expert | python-best-practices |
| .rs | lang-rust-expert | rust-best-practices |
| .kt | lang-kotlin-expert | kotlin-best-practices |
| .ts, .tsx | lang-typescript-expert | typescript-best-practices |
| .java | be-springboot-expert | springboot-best-practices |
| .jsx, .js (React) | fe-vercel-agent | react-best-practices |

## Refactoring Categories

| Category | Description |
|----------|-------------|
| structure | File/module organization, package structure |
| naming | Variable, function, type naming conventions |
| patterns | Design patterns, idiomatic code |
| duplication | Extract common code, reduce repetition |
| complexity | Simplify complex functions, reduce nesting |

## Output Format

### Dry Run
```
[dev:refactor src/utils.go --dry-run]

┌─ Agent: lang-golang-expert (sw-engineer)
├─ Skill: go-best-practices
└─ File: src/utils.go

Analysis:

[Structure] Lines 10-45
  Issue: Function too long (35 lines)
  Suggest: Extract helper functions

[Naming] Line 12
  Issue: Abbreviation in function name
  Found: func procData()
  Suggest: func processData()

[Patterns] Lines 20-30
  Issue: Repeated error handling pattern
  Suggest: Create handleError() helper

Proposed Changes:
  1. Extract lines 15-25 into validateInput()
  2. Rename procData → processData
  3. Create handleError() helper function

No changes made (dry-run mode).
Run without --dry-run to apply changes.
```

### Apply Changes
```
[dev:refactor src/utils.go]

┌─ Agent: lang-golang-expert (sw-engineer)
├─ Skill: go-best-practices
└─ File: src/utils.go

Refactoring:

[1/3] Extracting validateInput()...
  ✓ Created function at line 50
  ✓ Updated calls at lines 15, 22

[2/3] Renaming procData → processData...
  ✓ Renamed function definition
  ✓ Updated 3 call sites

[3/3] Creating handleError() helper...
  ✓ Created function at line 60
  ✓ Replaced 5 error handling blocks

Summary:
  Changes applied: 3
  Lines modified: 28
  Functions added: 2
  Functions renamed: 1

Recommendation: Run tests to verify changes.
```

## Spec Mode (`--spec`)

When the `--spec` flag is present, refactoring is guided by the target's canonical specification:

### Workflow

1. **Load spec**: Read `.claude/specs/<agent-name>.spec.md` (generated by `/omcustom-takeover`)
   - If spec doesn't exist, run takeover first: `/omcustom-takeover <name>`
2. **Extract invariants**: Parse the spec's `## Invariants` section as pre-flight guard constraints
3. **Refactor**: Perform normal refactoring (per existing workflow)
4. **Verify invariants**: After refactoring, check each invariant still holds:
   ```
   [Spec Verification]
   ├── ✓ Invariant 1: {description} — PASS
   ├── ✓ Invariant 2: {description} — PASS
   └── ✗ Invariant 3: {description} — FAIL (reason)
   ```
5. **Regenerate spec**: If refactoring changed the contract, run `/omcustom-takeover <name>` to update

### When to Use

| Scenario | Use `--spec`? |
|----------|--------------|
| Refactoring agent internals | Yes — preserves declared invariants |
| Renaming/restructuring skill | Yes — ensures contract stability |
| Simple code cleanup | No — overhead not justified |
| Adding new capability | No — spec will change anyway |

### Prerequisites

- `.claude/specs/<name>.spec.md` must exist (or will be auto-generated via takeover)
- Target must be an agent or skill (not arbitrary code)

Attribution

baekenoughbaekenough
View sourceMore from baekenough →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284722 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2192 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

9881 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →