refactor

refactor is a command for Claude Code from eddiesanjuan/markupr. It costs 0 tokens per session (1,098 once invoked), scanned A, original, MIT.

A command for incrementally restructuring part of the markupr codebase while running tests after each change.

In plain words
What is it for?
Use it to refactor a file, module, or code pattern in markupr and review the baseline and resulting test status.
Why use it?
It reduces the risk that cleanup work introduces bugs by checking the existing test suite throughout the refactor.

Command for Claude Code

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 commands/eddiesanjuan/markupr/refactor
Clone the repo
git clone --depth 1 https://github.com/eddiesanjuan/markupr

Made for: Claude Code.

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 refactor

README.md
[![agentmods](https://agentmods.dev/badge/commands/eddiesanjuan/markupr/refactor.svg)](https://agentmods.dev/commands/eddiesanjuan/markupr/refactor)
Your own site
<a href="https://agentmods.dev/commands/eddiesanjuan/markupr/refactor"><img src="https://agentmods.dev/badge/commands/eddiesanjuan/markupr/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,098 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 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.00000 $0.01098
Opus 5 $0.00000 $0.00549
Sonnet 5 $0.00000 $0.00220
Haiku 4.5 $0.00000 $0.00110

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

Security

Grade A, and why

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 4d 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.

.claude/commands/refactor.md · 129 lines

How it starts

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

Refactor -- Safe Refactoring with Test Guard Rails

Perform incremental, test-guarded refactoring of a specified area of the markupr codebase. Every change is validated by re-running the test suite to ensure nothing breaks.

Target area: $ARGUMENTS

If no argument is provided, ask the user what area to refactor. Examples:

  • A specific file: src/main/SessionController.ts
  • A module: src/main/pipeline/
  • A pattern: error handling, IPC layer, AI pipeline

Instructions

1. Establish Baseline -- Run Tests First

cd ~/Projects/markupr && npm test -- --run 2>&1

Record the baseline: total tests, passed, failed. If any tests are ALREADY failing, report them and ask the user whether to proceed (refactoring on a red test suite is risky).

2. Read and Analyze the Target Code

Read the target file(s) thoroughly. Identify refactoring opportunities specific to markupr's Electron + React + TypeScript stack:

Electron Main Process (src/main/)

  • SessionController FSM: overly complex state transitions, duplicated guard clauses
  • IPC handlers in src/main/ipc/: handlers doing too much work (should delegate to services)
  • CrashRecovery: deeply nested try/catch, unclear recovery paths
  • Pipeline steps: tight coupling between PostProcessor, TranscriptAnalyzer, FrameExtractor
  • Settings: redundant validation that Zod should handle

React Renderer (src/renderer/)

  • Components over 200 lines that should be split (especially App.tsx, SettingsPanel.tsx, SessionReview.tsx)
  • Props drilling that should use React context or composition
  • useEffect cleanup functions missing for event subscriptions via window.markupr.*
  • Inline styles or magic numbers that should be Tailwind utilities or constants
  • State that lives in components but should be lifted or extracted to hooks

Shared / Cross-cutting

  • Type definitions in src/shared/types.ts that have grown too large (split by domain)
  • Duplicated type definitions between main and renderer
  • String-based IPC channel names that could benefit from a type-safe wrapper
  • Error handling patterns that swallow errors silently

Read the full file on GitHub · 129 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. 4d ago First seen · 129 lines · 0 tokens per session scan A 93efd11ef953

Subscribe to this mod's changes

refactor is a command published in the GitHub repository eddiesanjuan/markupr (18 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,098 tokens. 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.