code-simplify
paulrberg/agent-skills
Esta habilidade deve ser utilizada quando o usuário solicita “simplificar o código”, “limpar o código”, “refatorar para maior clareza”, “reduzir a complexidade”, “melhorar a legibilidade” ou pede para simplificar código que foi modificado recentemente.
...Expandir tudoSobre o código-simplify
A habilidade código-simplify foi desenvolvida para simplificar o código existente, preservando ao mesmo tempo seu comportamento em execução, interfaces públicas, efeitos colaterais e intenção operacional. Ela ajuda os desenvolvedores a reduzir a complexidade, melhorar a legibilidade e tornar o código mais fácil de manter, sem introduzir alterações funcionais. A habilidade se concentra em refatoring seguro e direcionado, em vez de reescritas abrangentes, garantindo que entradas, saídas, comportamento em caso de erro e contratos externamente dependentes permaneçam estáveis. É indicada para situações em que o código se tornou difícil de entender, excessivamente aninhado, duplicado ou desnecessariamente complexo.
A habilidade determina um escopo apropriado com base em metas fornecidas pelo usuário, arquivos modificados recentemente ou alterações no repositório. Ela analisa o contexto circundante para estabelecer uma linha de base comportamental antes de fazer alterações. A simplificação é realizada através de um processo estruturado que inclui a desaninhamento do fluxo de controle, melhoria da clareza dos nomes, redução de duplicações, reestruturação de transformações de dados densas em etapas mais claras e, quando apropriado, melhoria da clareza dos tipos ou contratos. O fluxo de trabalho enfatiza edições pequenas e reversíveis e segue as convenções existentes do projeto, linters, formatares e testes. Regras de segurança impedem alterações que mudem o comportamento, como converter APIs síncronas em assíncronas, remover proteções operacionais ou alterar interfaces externas sem instruções explícitas.
Esta habilidade é útil para desenvolvedores, mantenedores e equipes que trabalham com bases de código em evolução e desejam melhorar a qualidade do código sem alterar sua funcionalidade. Casos de uso comuns incluem a limpeza de código recentemente modificado, refatoring para melhorar a legibilidade, reduzir a carga cognitiva em funções complexas, simplificar lógicas aninhadas e preparar o código para manutenção a longo prazo. É particularmente valiosa em fluxos de trabalho de desenvolvimento baseados em repositórios, onde a verificação e a estabilidade comportamental são requisitos importantes.
Perguntas Frequentes
Quando devo usar esta habilidade?
Use-a quando desejar simplificar o código, melhorar a legibilidade, reduzir a complexidade, limpar código recentemente modificado ou tornar o código mais fácil de manter sem alterar seu comportamento.
Esta habilidade muda o comportamento do aplicativo ou as interfaces públicas?
Não. A habilidade foi desenvolvida para preservar o comportamento em execução, contratos públicos, efeitos colaterais, entradas, saídas e semântica de erros externamente dependentes.
Esta habilidade requer um repositório Git?
Sim. O fluxo de trabalho começa com a verificação do contexto do repositório. Se o diretório atual não for um repositório Git, o processo será interrompido e solicitará que seja executado a partir de um repositório.
Como a habilidade decide quais arquivos modificar?
Ela utiliza metas fornecidas pelo usuário quando disponíveis. Caso contrário, foca em arquivos modificados durante a sessão e pode recorrer a arquivos não comitidos, rastreados ou não rastreados se não houver arquivos modificados durante a sessão.
Existem alguma restrições nos tipos de refatoring realizados?
Sim. A habilidade evita modificações que mudam o comportamento, reescritas abrangentes, abstrações desnecessárias, alterações em APIs síncronas ou assíncronas, bem como a remoção de registros de log, telemetria, proteções, tentativas repetidas ou outro código de importância operacional.
Code Simplify
Objective
Simplify code while preserving behavior, public contracts, and side effects. Favor explicit code and local clarity over clever or compressed constructs.
Arguments
- Paths, patterns, a commit/range, or a scope phrase: used in Scope Resolution step 2.
--no-report: Skip the full user-facing report and return terse working notes for the caller.--no-verify: Skip verification because a parent orchestrator will verify the final result separately.- Default: verify touched behavior and present the full report.
Scope Resolution
Resolve scope once, then treat the result as fixed for the rest of the run.
- Verify repository context:
git rev-parse --git-dir. If this fails, stop and tell the user to run from a git repository. - If the request names targets — file paths/patterns, a commit/range, a natural-language subset (e.g. "the parser changes"), or a
resolved-scopefenced block with one repo-relative path per line — scope is exactly those targets. Map natural-language subsets to concrete paths before continuing. - Otherwise, scope is only session-modified files: files created or edited earlier in this session. Do not include other uncommitted changes.
- If there are no session-modified files, or earlier conversation history is not visible in this context, fall back to all uncommitted files, running each command once:
- tracked:
git diff --name-only --diff-filter=ACMR - untracked:
git ls-files --others --exclude-standard - combine both lists and de-duplicate.
- tracked:
- Exclude generated/low-signal files unless explicitly requested: lockfiles, minified bundles, build outputs, vendored code.
- If scope resolves to zero files, report that and stop.
- Emit the scope as a fenced code block tagged
resolved-scope, one repo-relative path per line. The block is authoritative: do not re-run scope commands or revisit exclusions afterward.
Operating Rules
- Preserve runtime behavior exactly. Keep inputs, outputs, side effects, and error behavior stable.
- Prefer project conventions over personal preferences. Infer conventions from existing code, linters, formatters, and tests.
- Make small, reversible edits. Avoid broad rewrites when targeted simplifications solve the problem.
- Call out uncertainty immediately when behavior may change.
Workflow
1) Determine Scope
- Apply the Scope Resolution section.
2) Build a Behavior Baseline
- Read surrounding context, not only changed lines.
- Identify invariants that must not change:
- function signatures and exported APIs
- state transitions and side effects
- persistence/network behavior
- user-facing messages and error semantics where externally relied on
- Note available verification commands (lint, tests, typecheck).
3) Apply Simplification Passes (in this order)
- Control flow:
- Flatten deep nesting with guard clauses and early returns.
- Replace nested ternaries with clearer conditionals.
- Naming and intent:
- Rename ambiguous identifiers when local context supports safe renaming.
- Separate mixed concerns into small helpers with intent-revealing names.
- Duplication:
- Remove obvious duplication.
- Abstract only when at least two real call sites benefit and the abstraction reduces cognitive load.
- Data shaping:
- Break dense transform chains into named intermediate steps when readability improves.
- Keep hot-path performance characteristics stable unless improvement is explicit and measured.
- Type and contract clarity:
- Add or tighten type annotations when they improve readability and safety without forcing broad churn.
- Preserve external interfaces unless asked to change them.
4) Enforce Safety Constraints
- Do not convert sync APIs to async (or reverse) unless explicitly requested.
- Do not alter error propagation strategy unless behavior remains equivalent and verified.
- Do not remove logging, telemetry, guards, or retries that encode operational intent.
- Do not collapse domain-specific steps into generic helpers that hide intent.
5) Verify
Skip when --no-verify is set. Otherwise verify per the Verification section below.
6) Report
Produce the Report section below.
Simplification Heuristics
- Prefer explicit local variables over nested inline expressions when it reduces cognitive load.
- Prefer one clear branch per condition over compact but ambiguous condition trees.
- Keep function length manageable, but do not split purely for line count.
- Keep comments that explain intent, invariants, or non-obvious constraints.
- Remove comments that restate obvious code behavior.
- Optimize for the next maintainer's comprehension time, not minimum character count.
Anti-Patterns
- Do not perform speculative architecture rewrites.
- Do not introduce framework-wide patterns while simplifying a small local change.
- Do not replace understandable duplication with opaque utility layers.
- Do not bundle unrelated cleanups into one patch.
Verification
Run the narrowest checks that validate touched behavior:
- formatter/lint on touched files
- targeted tests for touched modules
- typecheck when relevant
Run broader checks only when risk warrants it. Name every skipped check and why.
Report
Skip when --no-report is set; return terse working notes instead: touched scope, key simplifications, residual risks.
Use these section headings, in this order. Omit sections that do not apply — do not number them and do not leave gaps or placeholders.
Scope
Files and regions changed.
Simplifications
One sentence per meaningful change, focused on the readability or maintainability gain. Confirm behavior-preservation assumptions explicitly.
Verification
Commands run and outcomes, including skipped checks.
Residual Risks
One line per risk: Assumed <assumption>; if wrong, <what breaks>; check via <command or inspection>. Plain language — expand or gloss domain-specific terms. Include questions that need a user decision, phrased directly. Write None. when there are none.
Stop Conditions
Stop and ask for direction when:
- simplification requires changing public API/contracts.
- behavior parity cannot be confidently verified.
- the code appears intentionally complex due to domain constraints.
- the requested scope implies a larger redesign rather than simplification.
Instalar code-simplify
Baixe e extraia os arquivos de habilidades para o seu diretório .claude/skills/.
Baixar ZIPClone o repositório e copie os arquivos da habilidade para o seu projeto.
git clone https://github.com/PaulRBerg/agent-skills/blob/main/skills/code-simplify/SKILL.md # Copy SKILL.md to your .claude/skills/ directory
Copiar





Lar
