structural-refactor

structural-refactor is a skill for Claude Code, Codex from rolandbrecht/agent-skills. It costs 375 tokens per session (3,707 once invoked), scanned B, original, MIT.

A guide to tools for changing code according to its structure, including comby for cross-language edits and Python-specific migration tools. Structural editing recognizes balanced code parts instead of treating files as plain text.

In plain words
What is it for?
It helps replace patterns across many files, capture and rearrange code fragments, migrate Python 2 code, modernize Python 3 code, and select AST-based analysis for dead-code or call-graph work.
Why use it?
It makes large or complicated replacements safer than ad hoc grep or sed commands. The guide helps choose a suitable tool for rearranging code, updating Python, or analyzing dependencies.

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

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/rolandbrecht/agent-skills/structural-refactor.svg)](https://agentmods.dev/skills/rolandbrecht/agent-skills/structural-refactor)
Your own site
<a href="https://agentmods.dev/skills/rolandbrecht/agent-skills/structural-refactor"><img src="https://agentmods.dev/badge/skills/rolandbrecht/agent-skills/structural-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 375 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,707 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 2 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.00375 $0.03707
Opus 5 $0.00187 $0.01853
Sonnet 5 $0.00075 $0.00741
Haiku 4.5 $0.00038 $0.00371

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

Security

Grade B, and why

structural-refactor scanned grade B with 2 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 5d 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.

Asks for rootmediumPrivilege escalation

A mod that escalates privileges can change anything on the machine, not only the project.

> `sudo ln -s /usr/lib/libpcre.so /usr/lib/libpcre.so.3`

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

**Structural find-and-replace across a codebase:** "replace all fetch(url, options) calls
structural-refactor/SKILL.md · 371 lines

How it starts

The opening of the file, as written. The whole thing — 371 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Structural Code Refactoring

This skill covers three complementary tools for structural code transformation. Use the right one for the job — they're not competitors, they're specialists.

Pick the Right Tool

Situation Best tool
Cross-language pattern replace (JS, Go, SQL, HTML…) comby
Rearrange/capture subexpressions across many files comby
Python 2 → 3 migration (print, unicode, exec, dict…) 2to3
Modernizing Python 3 idioms (f-strings, type hints…) pyupgrade
True AST analysis (dead code, call graphs, imports) ast-code-graph skill
Simple string search grep / ripgrep

comby — Structural Search and Replace

comby understands code shape: balanced delimiters, string boundaries, comment regions. Unlike sed, you write patterns that look like the code you're targeting.

Match:   request.get(':[url]')
Rewrite: request({ url: ':[url]', method: 'get' })

Wins over grep/sed when:

  • The pattern spans multiple lines or contains nested brackets
  • The same text appears in comments/strings and you want to skip it
  • You need to capture and rearrange subexpressions
  • You're working across multiple languages in one pass

Installation

which comby          # check first

brew install comby   # macOS
bash <(curl -sL get-comby.netlify.app)   # Ubuntu/Debian
cargo install comby  # any platform

# Docker — no install, prefix every command with:
# docker run --rm -it -v "$PWD":/src -w /src comby/comby

Linux PCRE note: if comby complains about libpcre, run: sudo ln -s /usr/lib/libpcre.so /usr/lib/libpcre.so.3

Hole Syntax

Holes are the wildcards in comby templates. Choose carefully to avoid over-matching.

Hole Matches Use when
:[x] Zero or more chars (lazy, respects delimiters) General expressions, argument lists, bodies
:[[x]] One or more word chars ([a-zA-Z0-9_]) Identifiers, variable names
:[x~regex] PCRE regex Constrained patterns (e.g., :[n~[0-9]+])
:[?x] Optional — can be absent Optional arguments, trailing commas
... or :[_] Unnamed match (discard) Skipping parts you don't need

Read the full file on GitHub · 371 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 5d ago First seen · 371 lines · 375 tokens per session scan B 90ba54ca90f3

Subscribe to this mod's changes

structural-refactor is a skill published in the GitHub repository rolandbrecht/agent-skills (4 stars, last pushed 23d ago), licensed MIT. It adds 375 tokens to every session and 3,707 once invoked, about $0.0019 per session on Opus 5. A static security scan graded it B with 2 findings (asks for root, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.