Code Refactoring Workflow
luongnv89/claude-howto
Guides systematic, test-backed refactoring in the style of Martin Fowler, moving through research, planning and small incremental changes with your approval at each phase.
Steers C++ code toward C++20, C++23 and C++26 idioms such as smart pointers, concepts, std::expected and std::print, with a security focus.
$ npx skills add trailofbits/skills --skill modern-cpp -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install trailofbits/skills modern-cpp --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/trailofbits/skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/modern-cpp/skills/modern-cpp .claude/skills/modern-cpp && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "modern-cpp" agent skill from https://github.com/trailofbits/skills/tree/main/plugins/modern-cpp/skills/modern-cpp into .claude/skills/modern-cpp/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "modern-cpp", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/trailofbits/skills/tree/main/plugins/modern-cpp/skills/modern-cppType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add trailofbits/skills --skill modern-cpp -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install trailofbits/skills modern-cpp --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/trailofbits/skills.git skills-src && mkdir -p .agents/skills && cp -r skills-src/plugins/modern-cpp/skills/modern-cpp .agents/skills/modern-cpp && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "modern-cpp" agent skill from https://github.com/trailofbits/skills/tree/main/plugins/modern-cpp/skills/modern-cpp into .agents/skills/modern-cpp/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "modern-cpp", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add trailofbits/skills --skill modern-cpp -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install trailofbits/skills modern-cpp --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/trailofbits/skills.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/plugins/modern-cpp/skills/modern-cpp .cursor/skills/modern-cpp && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "modern-cpp" agent skill from https://github.com/trailofbits/skills/tree/main/plugins/modern-cpp/skills/modern-cpp into .cursor/skills/modern-cpp/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "modern-cpp", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/trailofbits/skills.git --path plugins/modern-cpp/skills/modern-cpp--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add trailofbits/skills --skill modern-cpp -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install trailofbits/skills modern-cpp --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/trailofbits/skills.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/plugins/modern-cpp/skills/modern-cpp .gemini/skills/modern-cpp && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "modern-cpp" agent skill from https://github.com/trailofbits/skills/tree/main/plugins/modern-cpp/skills/modern-cpp into .gemini/skills/modern-cpp/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "modern-cpp", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install trailofbits/skills modern-cppInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add trailofbits/skills --skill modern-cpp -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/trailofbits/skills.git skills-src && mkdir -p .github/skills && cp -r skills-src/plugins/modern-cpp/skills/modern-cpp .github/skills/modern-cpp && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "modern-cpp" agent skill from https://github.com/trailofbits/skills/tree/main/plugins/modern-cpp/skills/modern-cpp into .github/skills/modern-cpp/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "modern-cpp", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add trailofbits/skills --skill modern-cpp -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install trailofbits/skills modern-cpp --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/trailofbits/skills.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/plugins/modern-cpp/skills/modern-cpp .opencode/skills/modern-cpp && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "modern-cpp" agent skill from https://github.com/trailofbits/skills/tree/main/plugins/modern-cpp/skills/modern-cpp into .opencode/skills/modern-cpp/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "modern-cpp", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
modern-cppSteers C++ code toward C++20, C++23 and C++26 idioms such as smart pointers, concepts, std::expected and std::print, with a security focus.
This skill guides the agent when writing new C++ or modernizing older code, with an emphasis on patterns that remove whole classes of vulnerabilities. Its core is a table of what to avoid and what to use instead: new and delete give way to make_unique, C arrays to std::array, pointer plus length to std::span, printf to std::format or std::print, SFINAE to concepts, error codes to std::expected, and manual locking to std::scoped_lock.
Features are ranked into tiers by how usable they are today rather than by standard version, and a decision tree helps choose an approach. Reference files cover anti-patterns (30+ of them), compiler hardening, safe idioms and notes on the C++20, C++23 and C++26 features. The skill steps aside for pure C, build-system questions such as CMake, and projects that must stay on an older standard.
Read from SKILL.md and the folder at commit 82fe822. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
No scripts in the folder and no shell commands in SKILL.md.
From the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Modern C++ Idioms loads about 2.2k tokens when it runs, and up to ~13k if it reads all its reference files. Until then it costs about 70 tokens; SKILL.md has 767 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from trailofbits/skills at commit 82fe822, republished under its CC-BY-SA-4.0 licence (© trailofbits). 767 words, ~2,158 tokens.
.claude/skills/modern-cpp/SKILL.md (or your agent's skills folder). This skill also uses 6 other files; get the full folder from GitHub.Guide for writing modern C++ using C++20, C++23, and C++26 idioms. Focuses on patterns that eliminate vulnerability classes and reduce boilerplate, with a security emphasis from Trail of Bits.
| Avoid | Use Instead | Why |
|---|---|---|
new/delete | std::make_unique, std::make_shared | Eliminates leaks, double-free |
| Raw owning pointers | std::unique_ptr, std::shared_ptr | RAII ownership semantics |
C arrays (int arr[N]) | std::array<int, N> | Bounds-aware, value semantics |
| Pointer + length params | std::span<T> | Non-owning, bounds-checkable |
printf / sprintf | std::format, std::print | Type-safe, no buffer overflow |
C-style casts (int)x | static_cast<int>(x) | Explicit intent, auditable |
#define constants | constexpr variables | Scoped, typed, debuggable |
SFINAE / enable_if | Concepts + requires | Readable constraints and errors |
| Error codes + out params | std::expected<T, E> | Composable, type-safe errors |
union | std::variant | Type-safe, no silent UB |
Raw mutex.lock()/unlock() | std::scoped_lock | Exception-safe, no deadlocks |
std::thread | std::jthread | Auto-join, stop token support |
assert() macro | contract_assert (C++26) | Visible to tooling, configurable |
| Manual CRTP | Deducing this (C++23) | Simpler, no template boilerplate |
| Macro code generation | Reflection (C++26) | Zero-overhead, composable |
See anti-patterns.md for the full table (30+ patterns).
What are you doing?
|
+-- Writing new C++ code?
| +-- Use modern idioms by default (C++20/23)
| +-- Choose the newest standard your compiler supports
| +-- See Feature Tiers below
|
+-- Modernizing existing code?
| +-- Start with Tier 1 (C++20/23) replacements
| +-- Prioritize by security impact (memory > types > style)
| +-- See anti-patterns.md for the migration table
|
+-- Security-critical code?
| +-- Enable compiler hardening flags (see below)
| +-- Enable hardened libc++ mode
| +-- Run sanitizers in CI
| +-- See safe-idioms.md and compiler-hardening.md
|
+-- Using C++26 features?
+-- Reflection: YES, plan for it (GCC 16+)
+-- Contracts: cautiously, for new API boundaries
+-- std::execution: wait for ecosystem maturity
+-- See cpp26-features.mdFeatures are ranked by practical usability today, not by standard version.
| Feature | Replaces | Standard |
|---|---|---|
Concepts + requires | SFINAE, enable_if | C++20 |
| Ranges + views | Raw iterator loops | C++20 |
std::span<T> | Pointer + length | C++20 |
std::format | sprintf, iostream chains | C++20 |
Three-way comparison <=> | Manual comparison operators | C++20 |
std::jthread | std::thread + manual join | C++20 |
| Designated initializers | Positional struct init | C++20 |
std::expected<T,E> | Error codes, exceptions at boundaries | C++23 |
std::print / std::println | printf, std::cout << | C++23 |
Deducing this | CRTP, const/non-const duplication | C++23 |
std::flat_map | std::map for read-heavy use | C++23 |
Monadic std::optional | Nested if-checks on optionals | C++23 |
See cpp20-features.md and cpp23-features.md.
These improve safety without changing your C++ standard version:
-D_FORTIFY_SOURCE=3, -fstack-protector-strong, -ftrivial-auto-var-init=zero-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST for ~0.3% overhead bounds-checking-Wall -Wextra -Wpedantic -WerrorReflection is the single most transformative C++26 feature. It eliminates:
to_json)GCC 16 (April 2026) has reflection merged. Plan new code to benefit from it.
pre/post/contract_assert) — Better than assert(), but no virtual function support and limited compiler support. Adopt cautiously for new API boundaries.See cpp26-features.md.
-Wall -Wextra -Wpedantic -Werror
-D_FORTIFY_SOURCE=3
-fstack-protector-strong
-fstack-clash-protection
-ftrivial-auto-var-init=zero
-fPIE -pie
-Wl,-z,relro,-z,now-Wunsafe-buffer-usage-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FASTGoogle deployed this across Chrome and their server fleet: ~0.3% overhead, 1000+ bugs found, 30% reduction in production segfaults.
See compiler-hardening.md for the full guide.
| Rationalization | Why It's Wrong |
|---|---|
| "It compiles without warnings" | Warnings depend on which flags you enable. Add -Wall -Wextra -Wpedantic. |
| "ASan is too slow for production" | Use GWP-ASan for sampling-based production detection (~0% overhead). |
| "We only use safe containers" | Iterator invalidation and unchecked optional access are still exploitable. |
| "Smart pointers are slower" | std::unique_ptr has zero overhead vs raw pointers. Measure before claiming. |
| "Our code doesn't have memory bugs" | Google found 1000+ bugs when enabling hardened libc++. So did everyone else. |
| "C++26 features aren't available yet" | C++20/23 features are. Hardening flags work on any standard. Start there. |
| "Modern C++ is harder to read" | std::expected is more readable than checking error codes across 5 out-params. |
std::span over pointer + length for function parametersstd::expected for functions that can fail with typed errorsconstexpr / consteval where possible (UB-free by design)[[nodiscard]] when ignoring the return value is likely a bugstd::variant over union, enum class over enum© trailofbits, CC-BY-SA-4.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
SKILL.md and 6 other files (references) in plugins/modern-cpp/skills/modern-cpp of trailofbits/skills.
Open the folder on GitHubat commit 82fe822
Modern C++ Idioms next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Modern C++ Idioms this skilltrailofbits/skills | 7.4k | — | ~2.2k | Automated safety check: Pass | CC-BY-SA-4.0 | |
| Code Refactoring Workflowluongnv89/claude-howto | 42k | — | ~3.1k | Automated safety check: Pass | MIT | |
| ONNX Runtime Shape Inference Safety Auditmicrosoft/onnxruntime | 22k | — | ~3.3k | Automated safety check: Pass | MIT | |
| Qt C++ Code Reviewx-tools-author/x-tools | 1.1k | 2 repos | ~4.3k | Automated safety check: Pass | BSD-3-Clause | |
| Ripwire Output Emissionredhat-et/ripwire | 2.4k | — | ~1k | Automated safety check: Pass | Apache-2.0 | |
| Msbuild Antipatternsrunceel/ReactiveProperty | 944 | — | ~3.7k | Automated safety check: Pass | MIT |
luongnv89/claude-howto
Guides systematic, test-backed refactoring in the style of Martin Fowler, moving through research, planning and small incremental changes with your approval at each phase.
microsoft/onnxruntime
Finds and fixes out-of-range output writes in ONNX Runtime operator shape-inference functions where a getNumOutputs guard admits too few outputs.
x-tools-author/x-tools
Read-only review of Qt6 C++ code that combines a deterministic lint script with six parallel analysis agents and reports only high-confidence issues.
redhat-et/ripwire
Rules for writing and converting formatted output in ripwire's C++ source with its emit helpers, keeping every printed byte identical to the old printf output.
runceel/ReactiveProperty
Catalog of MSBuild anti-patterns with detection rules and fix recipes.
webrtc-sdk/webrtc
Runs the WebRTC include-cleaner tool to add missing and remove unused C++ include directives before uploading a CL or after refactoring.
trailofbits/skills
Scans a codebase for vulnerabilities with CodeQL's data flow and taint tracking in run-all or important-only modes, including data extensions for project-specific sources and sinks.
trailofbits/skills
Generates Mermaid diagrams from Trailmark code graphs, including call graphs, class hierarchies, module dependency maps, complexity heatmaps and attack surface data flows.
trailofbits/skills
Compares Trailmark code graphs at two snapshots, such as commits, tags or directories, to surface attack paths, blast radius and taint changes that text diffs miss.
trailofbits/skills
Draws a 12 Houses tarot spread to break ties when a request is vague or casually delegated, then reads the cards to pick the next step.
trailofbits/skills
Detects languages, proposes rulesets for approval, then runs the approved Semgrep scan across a codebase and merges the output into one SARIF file.
trailofbits/skills
Searches and extracts data from Burp Suite project files on the command line: regex searches over responses, audit findings, proxy history and site map data.
Works with
Categories
Steers C++ code toward C++20, C++23 and C++26 idioms such as smart pointers, concepts, std::expected and std::print, with a security focus. This skill guides the agent when writing new C++ or modernizing older code, with an emphasis on patterns that remove whole classes of vulnerabilities. Its core is a table of what to avoid and what to use instead: new and delete give way to make_unique, C arrays to std::array, pointer plus length to std::span, printf to std::format or std::print, SFINAE to concepts, error codes to std::expected, and manual locking to std::scoped_lock.
Modern C++ Idioms fits situations like: writing new C++ functions, classes or libraries to current standards; modernizing code written to pre-C++20 patterns; working on security-critical or safety-sensitive C++; reviewing C++ code for outdated idioms.
Run `npx skills add trailofbits/skills --skill modern-cpp -a claude-code`. Or copy the skill folder (plugins/modern-cpp/skills/modern-cpp in trailofbits/skills) into .claude/skills/modern-cpp in your project. Claude Code loads it when a task matches its description.
Run `npx skills add trailofbits/skills --skill modern-cpp -a codex`. Or copy the skill folder (plugins/modern-cpp/skills/modern-cpp in trailofbits/skills) into .agents/skills/modern-cpp in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add trailofbits/skills --skill modern-cpp -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/modern-cpp, .gemini/skills/modern-cpp, .github/skills/modern-cpp and .opencode/skills/modern-cpp in your project.
SKILL.md names no scripts, command-line tools or credentials: Modern C++ Idioms is instructions for the agent only.
SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Modern C++ Idioms is published under the CC-BY-SA-4.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 2.2k tokens (SKILL.md is roughly 8.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 11k tokens, read only when the agent opens those files.
Skills that share tags, products or a category with Modern C++ Idioms: Code Refactoring Workflow (luongnv89/claude-howto, 42k stars), ONNX Runtime Shape Inference Safety Audit (microsoft/onnxruntime, 22k stars), Qt C++ Code Review (x-tools-author/x-tools, 1.1k stars) and Ripwire Output Emission (redhat-et/ripwire, 2.4k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
trailofbits (a GitHub organization, an official publisher) maintains it in trailofbits/skills, which has 7,400 GitHub stars. The repository holds 79 skills in this directory. The repository was last updated on October 2, 2026.
Source: trailofbits/skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.