safe-refactor

safe-refactor is a skill for Claude Code, Codex from edimuj/tokenlean. It costs 54 tokens per session (640 once invoked), scanned A, original, MIT.

A step-by-step method for changing code structure safely, such as renaming symbols, moving files, or extracting functions. It checks which other files depend on the code before and after the change.

In plain words
What is it for?
Use it to inspect dependencies and usages, make structural changes, check for circular dependencies or unused exports, and run tests.
Why use it?
It reduces the risk of breaking code that uses the part being changed and helps identify problems soon after the refactor.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to inspect dependencies and usages, make structural changes, check for circular dependencies or unused exports, and run tests.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/edimuj/tokenlean/safe-refactor
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.

Any agent
npx skills add edimuj/tokenlean --skill safe-refactor
Clone the repo
git clone --depth 1 https://github.com/edimuj/tokenlean

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/edimuj/tokenlean/safe-refactor/github.svg)](https://agentmods.dev/skills/edimuj/tokenlean/safe-refactor)
Your own site
<a href="https://agentmods.dev/skills/edimuj/tokenlean/safe-refactor"><img src="https://agentmods.dev/badge/skills/edimuj/tokenlean/safe-refactor/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for safe-refactor

Your own site · 80×15
<a href="https://agentmods.dev/skills/edimuj/tokenlean/safe-refactor"><img src="https://agentmods.dev/badge/skills/edimuj/tokenlean/safe-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 54 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 640 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00054 $0.00640
Opus 5.5 $0.00022 $0.00256
Sonnet 5.5 $0.00011 $0.00128
Haiku 4.5 $0.00005 $0.00064

Measured 3mo ago against content hash 3fc97a460ae9, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

safe-refactor scanned grade A with 0 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 3mo 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/claude/safe-refactor/SKILL.md · 92 lines

How it starts

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

Safe Refactor

Change code structure without breaking dependents.

Workflow

Analyze → Plan → Change → Verify

1. Analyze what you're changing

tl parallel \
  "impact=tl impact <file>" \
  "exports=tl exports <file>" \
  "symbols=tl symbols <file>"

These three commands tell you:

  • Blast radius — how many files will be affected
  • Contract — which exports are consumed externally
  • Shape — what you're working with

If tl impact shows 10+ dependents, consider whether this refactor is worth the risk. Discuss with the user.

2. Understand consumers

For each file that imports from the target:

tl snippet <imported-symbol> <consumer-file>

This shows how the symbol is actually used without reading the entire consumer file.

3. Make the changes

Apply the refactor. Then immediately check:

tl guard              # Circular deps, unused exports, other issues

4. Verify

tl parallel "test=tl run '<test-command>'" "impact=tl impact <file>"

If tests fail, tl run output shows only the failures. Fix and re-run.

Decision tree: refactor type

What are you changing?
  ├─ Renaming a symbol
  │   → tl impact to find all importers
  │   → Update all import sites
  │   → tl guard to verify no broken imports
  │
  ├─ Moving a file
  │   → tl impact for full dependent list
  │   → Move file, update all import paths
  │   → tl guard for circular deps
  │
  ├─ Extracting a function/module
  │   → tl symbols + tl deps on source file
  │   → Extract, add exports
  │   → tl impact on original to update importers
  │   → tl guard + tl run tests
  │
  └─ Changing a function signature
      → tl impact + tl flow to find all callers
      → tl snippet on each caller to see usage
      → Update signature + all call sites
      → tl run tests

Tips

  • Always check tl impact BEFORE starting — discovering 50 dependents mid-refactor is painful
  • Run tl exports before and after: the diff shows if you accidentally changed the public API
  • For large refactors (10+ files), make incremental commits so you can bisect failures
  • tl unused after refactoring catches exports you forgot to clean up

Read the full file on GitHub · 92 lines

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. 3mo ago First seen · 92 lines · 54 tokens per session scan A 3fc97a460ae9

Subscribe to this mod's changes

safe-refactor is a skill published in the GitHub repository edimuj/tokenlean (14 stars, last pushed 4mo ago), licensed MIT. It adds 54 tokens to every session and 640 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

safe-refactor compared with skills from other repositories

safe-refactor next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
safe-refactoredimuj/tokenleanSkill144mo agoMITA54Claude Code, Codex
wireshark-analysiszebbern/claude-code-guideSkill4.7ktodayMITA79Claude Code, Codex
log-error-digestzebbern/claude-code-guideSkill4.7ktodayMITA71Claude Code, Codex
vs-search-tuning-partial-casevolcengine/SearchCLISkill1.2k19d agoApache-2.0A85Claude Code, Codex
weedjuxt/alliumSkill54811d agoMITA71Claude Code
vs-searchvolcengine/SearchCLISkill1.2k19d agoApache-2.0A27Claude Code, Codex
dead-code-huntermagic5644/Graph-It-LiveSkill632d agoMITA165Claude Code