# Refactor Code Without Changing Behavior

Complex code slows maintenance and makes changes risky. This skill guides small, tested refactoring steps that improve structure while preserving behavior.

## Install

```bash
npx skillstore add github/refactor
```

## Metadata

- Status: approved
- Slug: github-refactor
- Skillstore revision: r2
- Version status: missing
- Tree hash: 8d18bcc794e10dd5450b485e1f783326f2009d391d14a3113887983df5150f0d
- Author: github
- GitHub username: github
- License: MIT
- Repository: https://github.com/github/awesome-copilot/tree/main/skills/refactor/
- Ref: c43861a65bb95efcae259cd161c9d6f4dc7eec6f
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, filesystem
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/github-refactor
- Manifest: https://skillstore.pages.dev/api/skills/github-refactor/manifest

## Capabilities

- Identifies common code smells and recommends focused refactoring operations.
- Breaks long functions and large classes into smaller responsibilities.
- Consolidates duplicated logic and replaces magic values with named constants.
- Introduces clearer types, domain value objects, and parameter objects.
- Simplifies nested conditionals with guard clauses and result-oriented flows.
- Applies strategy and responsibility-chain patterns when they fit the existing design.

## Use Cases

- Simplify Legacy Functions: Decompose long functions into focused units while keeping existing inputs, outputs, and side effects stable.
- Strengthen Type Boundaries: Replace ambiguous primitives and untyped interfaces with clear domain types and validation boundaries.
- Plan Incremental Cleanup: Create a sequence of small refactoring steps that reviewers can verify and merge independently.

## Prompt Templates

### Refactor One Function

```
Refactor the selected function for clarity while preserving behavior. Explain each change and identify tests I should run.
```

### Remove Code Smells

```
Review this module for duplication, long methods, unclear names, and magic values. Propose small steps, then apply the safest first step.
```

### Improve Type Safety

```
Refactor these classes to improve responsibility boundaries and type safety. Preserve public APIs, update affected tests, and summarize compatibility risks.
```

### Plan a Subsystem Refactor

```
Analyze this subsystem for coupling, duplication, and unstable boundaries. Create an incremental refactoring plan with verification gates, rollback points, and dependency impacts.
```

## Limitations

- Requires tests or other reliable behavior checks before risky changes.
- Does not guarantee performance improvements after structural changes.
- Does not replace domain knowledge needed to confirm intended behavior.
- Focuses on gradual refactoring rather than full repository rewrites.

## Best Practices

- Establish passing behavior tests before changing structure.
- Make one focused change, then run relevant tests and inspect the diff.
- Preserve public contracts unless the user explicitly approves an interface change.

## Anti Patterns

- Do not combine feature work with a behavior-preserving refactor.
- Do not apply design patterns without a concrete maintainability problem.
- Do not perform broad rewrites when small verified steps can solve the issue.

## Security Audit

- Audited at: 2026-07-23T18:08:49.826\+00:00
- Summary: All 53 static findings are false positives caused by Markdown fences, JavaScript template literals, regular-expression syntax, validation prose, or testing instructions. No prompt injection, data exfiltration, reconnaissance, or executable command behavior was found.

## Stats

- Views: 104
- Downloads: 13
- Favorites: 0
- Popularity score: 0
