Agent skill

Refactor

by open-guji in open-guji/luatex-cn

“清理重构代码 (Code cleanup and refactoring)”

— description from SKILL.md by open-guji
Apache-2.0Auto-check passedDevelopment

Install Refactor

skills CLI
$ npx skills add open-guji/luatex-cn --skill refactor -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install open-guji/luatex-cn refactor --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/open-guji/luatex-cn.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/refactor .claude/skills/refactor && rm -rf skills-src

Use ~/.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/

Facts

Skill name
refactor
GitHub stars
118
Token cost
~532 tokens
SKILL.md length
160 words
Files
1
Skills in repo
7
Repo updated
First seen
Licence
Apache-2.0

At a glance

  • Works in 10 steps: 删除死代码 → 提取重复代码 → 逻辑迁移:STY → Lua → …
  • SKILL.md covers 重构原则, 执行流程, 如何选择重构目标 and 注意事项
  • Calls git and python3

About this skill

Refactor is a skill in open-guji/luatex-cn (118 stars). Its SKILL.md is about 532 tokens. Licence: Apache-2.0.

Workflow steps

10 steps, taken from the step headings in SKILL.md.

  1. 删除死代码
  2. 提取重复代码
  3. 逻辑迁移:STY → Lua
  4. 使用 Style Stack 管理样式
  5. 模块职责单一
  6. 文件大小控制
  7. 命令复用
  8. 分析 (不改代码)
  9. 逐步执行
  10. 最终验证

What it can do on your machine

Read from SKILL.md and the folder at commit 8c48bdc. It shows what the files ask for, not the result of running them.

  • Tool permissions

    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.

  • Runs code

    Shell commands in SKILL.md call:

    • git
    • python3

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Refactor loads about 532 tokens when it runs. Until then it costs about 12 tokens; SKILL.md has 160 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~12
When it runs · the whole SKILL.md, loaded when a task matches
~532

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.

Safety

Auto-check passed

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.

SKILL.md

The full file from open-guji/luatex-cn at commit 8c48bdc, republished under its Apache-2.0 licence (© open-guji). 160 words, ~532 tokens.

Download SKILL.mdSave it as .claude/skills/refactor/SKILL.md (or your agent's skills folder).
name
refactor
description
清理重构代码 (Code cleanup and refactoring)

代码清理与重构

以资深程序架构师的视角审视项目代码,使其更整洁、更模块化、更易维护。

重构原则

按优先级排列:

1. 删除死代码
  • 找出未被调用的函数和未使用的变量
  • 搜索方式:用 Grep 搜索函数名/变量名,确认只有定义没有调用
  • Lua 文件:检查 local function 和 module 导出的函数
  • STY 文件:检查 \cs_new 定义的命令是否被使用
2. 提取重复代码
  • 在同一文件或相关文件中找到高度相似的代码段
  • 提取为通用函数,放到合适的工具模块中
  • 命名清晰,参数明确
3. 逻辑迁移:STY → Lua
  • 复杂逻辑应放在 Lua 中,STY 只负责命令定义和参数解析
  • STY 文件应尽量薄:定义命令 → 调用 Lua 函数
  • 模式:
    latex
    % STY 中:只做参数解析和 Lua 调用
    \NewDocumentCommand{\MyCmd}{O{} m}{
      \lua_now:e { my_module.my_func("\exp_not:n{#1}", "\exp_not:n{#2}") }
    }
4. 使用 Style Stack 管理样式
  • 格式和样式的设置应通过 style stack 来管理
  • 避免全局变量传递样式参数
  • 查看 tex/core/ 中 style stack 的现有用法作为参考
5. 模块职责单一
  • 每个模块(文件)负责一个独立功能
  • 与该功能相关的所有代码都应集中在该模块中
  • 如果发现某个功能的代码散落在多个不相关的文件中,应该收拢
6. 文件大小控制
  • 单个文件超过 400~600 行时,必须考虑拆分
  • 按子功能拆分为多个文件
  • 通过 require (Lua) 或 \RequirePackage (STY) 组织
7. 命令复用
  • 如果一个命令可以由其他命令组合实现,优先复用
  • 避免重复实现已有功能

执行流程

Phase 1: 分析 (不改代码)
  1. 扫描目标模块

    • 读取目标文件,理解其功能和结构
    • 统计行数,标记过大的文件
  2. 识别问题

    • 用 Grep 搜索未使用的函数/变量
    • 找出重复代码段
    • 标记可以迁移到 Lua 的 STY 逻辑
    • 检查模块职责是否单一
  3. 制定计划

    • 列出所有要做的重构项
    • 按风险从低到高排序
    • 每个重构项作为独立的一步
    • 使用 EnterPlanMode 让用户审批计划
Phase 2: 逐步执行

对每一步重构:

  1. 修改代码

    • 只做当前这一步的改动
    • 保持功能不变
  2. 回归测试

    bash
    python3 test/regression_test.py check
    • 所有测试必须 PASSED
    • 如果失败,立即修复或回滚
  3. 提交

    bash
    git add <changed-files>
    git commit -m "refactor: <描述这一步做了什么>
    
    Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
  4. 继续下一步

Phase 3: 最终验证
bash
# 运行完整回归测试
python3 test/regression_test.py check --all

如何选择重构目标

如果用户没有指定目标模块,按以下顺序扫描:

bash
# 找出最大的文件
find tex/ -name '*.lua' -o -name '*.sty' | xargs wc -l | sort -rn | head -20

优先处理:

  1. 行数最多的文件
  2. 最近频繁修改的文件 (git log --format='%H' --since='2 weeks ago' -- tex/ | head)
  3. 已知有技术债的模块

注意事项

  • 不要一次改太多 — 每步只做一个类型的重构
  • 测试优先 — 每步改完必须跑回归测试
  • 保持功能不变 — 重构不改变外部行为
  • 先读 LEARNING.md — 避免踩已知的坑
  • STY 中的 expl3 — 遇到展开问题先读 ai_must_read/expl3_note.md
  • 不要改测试文件 — 除非测试本身有问题

© open-guji, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/refactor of open-guji/luatex-cn.

Open the folder on GitHubat commit 8c48bdc

Compare with similar skills

Refactor 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.

Refactor compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Refactor this skillopen-guji/luatex-cn118—~532Automated safety check: PassApache-2.0
Ss Cpp ModernSerial-Studio/Serial-Studio7.2k—~1.6kAutomated safety check: PassCustom licence
Guidelinesakash-network/node1.1k22 repos~577Automated safety check: PassMIT
Component Refactoringlangflow-ai/langflow156k—~3.5kAutomated safety check: PassMIT
Migrate Core Code to Submodulestinyhumansai/openhuman42k—~2.6kAutomated safety check: PassGPL-3.0
Systematic Code Refactoringluongnv89/claude-howto42k—~3kAutomated safety check: PassMIT

Similar skills

  • Ss Cpp Modern

    Serial-Studio/Serial-Studio

    Modern C++20 authoring guidance for Serial Studio (Qt 6.11, C++20): concepts, ranges, move/RAII, std smart pointers, constexpr, lock-free SPSC atomics.

    7.2k GitHub stars~1.6k tokensUpdated today
    DevelopmentAuto-check passed
  • Guidelines

    akash-network/node

    Behavioral guidelines to reduce common LLM coding mistakes. An agent skill from akash-network/node.

    1.1k GitHub starsUsed in 22 repos~577 tokens
    DevelopmentAuto-check passed
  • Component Refactoring

    langflow-ai/langflow

    Refactor high-complexity React components in Langflow frontend.

    156k GitHub stars~3.5k tokensUpdated today
    DevelopmentAuto-check passed
  • Migrate Core Code to Submodules

    tinyhumansai/openhuman

    Plans and carries out moving non-host-specific code and its tests from the OpenHuman core into vendored tiny submodule libraries, then releases the submodule and re-pins the host.

    42k GitHub stars~2.6k tokensUpdated today
    DevelopmentAuto-check passed
  • Systematic Code Refactoring

    luongnv89/claude-howto

    Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.

    42k GitHub stars~3k tokensUpdated 7 days ago
    DevelopmentAuto-check passed
  • Codex

    skills-directory/skill-codex

    A skill your agent uses when the user asks to run Codex CLI (codex exec, codex resume) or references OpenAI Codex for code analysis, refactoring, or automated editing

    1.5k GitHub starsUsed in 3 repos~1.8k tokens
    DevelopmentAuto-check passed

More from open-guji/luatex-cn

  • Compare Layouts

    open-guji/luatex-cn

    比较 Original (ltc-guji.cls) 和 Digital (ltc-guji-digital.cls) TeX 文件的 layout 输出

    118 GitHub stars~550 tokensUpdated 5 days ago
    Auto-check passed
  • Convert To Digital

    open-guji/luatex-cn

    将 ltc-guji.cls 文件转换为 ltc-guji-digital 格式. An agent skill from open-guji/luatex-cn.

    118 GitHub stars~747 tokensUpdated 5 days ago
    Auto-check passed
  • Prepare Next Version

    open-guji/luatex-cn

    准备下一个补丁版本 (Prepare next patch version release). An agent skill from open-guji/luatex-cn.

    118 GitHub stars~412 tokensUpdated 5 days ago
    Auto-check passed
  • Regression Test

    open-guji/luatex-cn

    运行视觉回归测试验证代码更改是否正确,支持 basic/pastissue/complete 套件及基线更新. An agent skill from open-guji/luatex-cn.

    118 GitHub stars~350 tokensUpdated 5 days ago
    Auto-check passed
  • Test Tex

    open-guji/luatex-cn

    通过回归测试框架编译并查看 TeX 文件的渲染效果,避免在工作目录生成多余 PDF. An agent skill from open-guji/luatex-cn.

    118 GitHub stars~278 tokensUpdated 5 days ago
    Auto-check passed
  • Fix GitHub Issue

    open-guji/luatex-cn

    修复 GitHub Issue 的完整工作流

    118 GitHub stars~2k tokensUpdated 5 days ago
    Auto-check passed

Works with

Categories

Questions about Refactor

How do I install Refactor in Claude Code?

Run `npx skills add open-guji/luatex-cn --skill refactor -a claude-code`. Or copy the skill folder (.claude/skills/refactor in open-guji/luatex-cn) into .claude/skills/refactor in your project. Claude Code loads it when a task matches its description.

How do I install Refactor in Codex?

Run `npx skills add open-guji/luatex-cn --skill refactor -a codex`. Or copy the skill folder (.claude/skills/refactor in open-guji/luatex-cn) into .agents/skills/refactor in your project. Codex loads it when a task matches its description.

Can I use Refactor in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add open-guji/luatex-cn --skill refactor -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/refactor, .gemini/skills/refactor, .github/skills/refactor and .opencode/skills/refactor in your project.

What does Refactor need to run?

Going by SKILL.md and its folder, Refactor needs the command-line tools its instructions call (git and python3).

Does Refactor access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Refactor safe to install?

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.

What licence does Refactor use?

Refactor is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Refactor use?

About 532 tokens (SKILL.md is roughly 2.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Refactor?

Skills that share tags, products or a category with Refactor: Ss Cpp Modern (Serial-Studio/Serial-Studio, 7.2k stars), Guidelines (akash-network/node, 1.1k stars), Component Refactoring (langflow-ai/langflow, 156k stars) and Migrate Core Code to Submodules (tinyhumansai/openhuman, 42k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Refactor?

open-guji (a GitHub organization) maintains it in open-guji/luatex-cn, which has 118 GitHub stars. The repository holds 7 skills in this directory. The repository was last updated on October 2, 2026.

Source: open-guji/luatex-cn on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.