skills/refactor-cpp/SKILL.md
Scans a C++ codebase for duplicate or near-duplicate logic patterns across .cpp and .h files, then extracts them into reusable utility functions in a shared utils/ directory. Use when the user asks to "refactor this C++ code", "find duplicate logic in C++", "extract shared C++ utilities", "apply DRY to C++", "deduplicate C++ code", or "find repeated patterns in C++". Groups extracted helpers by the object type they operate on (strings, numbers, containers, etc.). Template functions are placed in .h headers only; non-template utilities get a .h declaration and a .cpp definition. Do NOT use for performance optimization, debugging logic errors, code formatting (use format-cpp), or explaining code. Do NOT extract code that appears only once. Run this skill before format-cpp.
npx skillsauth add armandli/get-skilled refactor-cppInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
If $ARGUMENTS is provided, use it as the target path. Otherwise, scan the
C++ code most recently written or discussed in the conversation.
.cpp, .cc, .cxx, .h, .hpp, .hxx files recursivelybuild/, cmake-build-*/, third_party/, vendor/,
external/, deps/*_test.cpp, *_unittest.cpp, test/ or
tests/ directories) unless the user explicitly includes themRead all target files and search for:
Minimum threshold:
Classify every finding as:
| Class | Meaning | Action | |-------|---------|--------| | Auto | Safe mechanical extraction; all occurrences are semantically equivalent | Extract and replace | | Suggest | Needs judgment — structural change, uncertain equivalence, or side-effect concern | Report only, do not apply |
Auto-extraction threshold: only extract when you are certain every occurrence has the same return type, the same side-effect profile, and would behave identically when replaced by a call to the new utility. When in doubt, classify as Suggest.
For each finding, assign:
.h only, plain functions get a .h
declaration and a .cpp definitionconst, noexcept, &, and &&
qualifiers as appropriate; use std::string_view for read-only string
parameters; prefer const T& for read-only input, T&& for sinks;
prefer return type over output parameters — only use a non-const reference
parameter when the caller must supply an existing object to be filled or
when returning multiple values with no natural primary result; if output
parameters are unavoidable, list them before all input parametersutils/<type>_utils.h (and .cpp if
non-template)Group all findings by operand type to determine which utility files to create or update.
For each operand type group that has ≥ 1 Auto finding:
<project_root>/utils/<type>_utils.h (and .cpp
for non-template definitions)utils/ directory does not exist, create it.h file; never split the
definition into a .cpp file (the compiler requires the definition visible
at every instantiation site).h, define in .cpp#ifndef header guards (not #pragma once); guard name is
UTILS_<TYPE>_UTILS_H in UPPER_SNAKE_CASEnamespace utils { }inline constexpr for constants shared across translation unitsusing namespace at file scope in any headerOne function per distinct logical operation. Do not merge unrelated helpers into a single function.
For each Auto finding:
#include "utils/<type>_utils.h" at the top of every modified source
file (place after the corresponding header in .cpp files, following
include ordering conventions)utils:: (e.g., utils::strip_prefix(s, "user_"))utils/<type>_utils.cpp file is created,
report that it must be registered in CMakeLists.txt, Makefile, or
BUILD — do not edit build files automaticallyAfter all files are processed, output a structured summary:
## Refactor Report
### Extracted (N utilities created/updated)
- utils/<file>.h — utils::<function>: extracted from <file1>:<line>, <file2>:<line>, ...
### Replaced (N call sites updated)
- <file>:<line> — replaced with utils::<function>(...)
### Suggested (N items — not applied)
- <file>:<line> — <description>: <why it qualifies> — Recommended: <proposed signature>
### Build System Note
- New .cpp file(s) requiring build system registration: <list>
### Skipped
- <any patterns considered but not extracted, and why>
Keep descriptions concise. For Suggest items, include a short code snippet showing the recommended extracted form when it aids clarity.
.h ONLY — never define a template function body
in a .cpp file; the compiler requires the definition visible at every
instantiation site.h, define in .cppnoexcept correctness — if uncertain whether the extracted
function can guarantee no-throw, classify as Suggest rather than marking
noexceptstatic local variables or global mutable stateconst T& / std::string_view — use const T& for read-only
inputs, T&& for sinks, and std::string_view for read-only string
parameters (C++17 or later)const reference output parameter
when the caller must supply an existing object to fill or when returning
multiple values with no natural primary result; if output parameters are
required, place them before all input parameters in the signatureusing namespace at file scope in headers — headers must not pollute
the global namespaceAfter the skill's primary task completes, run:
python3 ${PWD}/.claude/skills/skill-stat/scripts/record-stat.py "refactor-cpp"
tools
--- name: update-readme description: Updates a project README.md with build instructions, unit test instructions, and a mermaid architecture diagram. Use when a project README needs to be created or refreshed. Trigger phrases: "update readme", "generate readme", "create readme", "refresh readme docs". Emphasizes project interfaces, extension points, and customization hooks in the diagram — not concrete implementations. Do NOT use for documentation sites, wikis, or non-project READMEs. argument-h
business
--- name: skill-stat description: Records skill usage statistics and issue reports into .claude/skill-stats.md. Increments the Uses count for a skill name, and optionally logs an issue report that increments the Issues count and appends a row to the Issue Reports table. Use when tracking how often a skill is invoked, when a user reports a problem with a skill, or when another skill needs to log its own usage. Trigger phrases: "record skill stat", "log skill usage", "report skill issue". Do NOT u
testing
--- name: revert description: Reverts ALL git changes in the working directory: staged changes, unstaged modifications, and new untracked files. Use when user asks to "revert all changes", "undo all changes", "discard all changes", "reset all git changes", or "clean working directory". Do NOT use for reverting a specific file or a specific commit — those need targeted git commands. disable-model-invocation: true --- Revert all git changes in the working directory. This is destructive and cannot
tools
Scans a Python codebase for duplicate or near-duplicate logic patterns across functions, classes, and files, then extracts those patterns into typed utility classes in a shared module. Use when the user asks to "refactor this Python code", "find duplicate logic", "extract shared utilities", "apply DRY to Python", "deduplicate Python code", or "find repeated patterns in Python". Groups extracted helpers by the object type they operate on (strings, numbers, dates, collections, etc.). Do NOT use for performance optimization (use optimize-python), for debugging logic errors, or for explaining code. Do NOT extract code that appears only once. Run this skill before optimize-python.