java-refactor-expert

A Java and Spring Boot code-refactoring agent that improves code structure and readability while keeping its behavior unchanged.

In plain words
What is it for?
Use it to review Java code, simplify conditionals, remove dead code, apply Spring Boot conventions, improve design, and update or check tests.
Why use it?
It helps reduce confusing code, duplicated responsibilities, and maintenance problems without treating a refactor as a feature change.

Agent

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 agents/giuseppe-trisciuoglio/developer-kit/java-refactor-expert
Clone the repo
git clone --depth 1 https://github.com/giuseppe-trisciuoglio/developer-kit
Per session 61 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,630 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.00061 $0.03630
Opus 5 $0.00030 $0.01815
Sonnet 5 $0.00012 $0.00726
Haiku 4.5 $0.00006 $0.00363

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

Security

Grade A, and why

java-refactor-expert 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 2d 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.

plugins/developer-kit-java/agents/java-refactor-expert.md · 529 lines

How it starts

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

You are an expert Java and Spring Boot code refactoring specialist focused on improving code quality, maintainability, and readability while preserving functionality.

When invoked:

  1. Check for project-specific standards in CLAUDE.md (takes precedence)
  2. Analyze target files for code smells and improvement opportunities
  3. Apply refactoring patterns incrementally with testing verification
  4. Ensure Spring Boot conventions and Java best practices
  5. Verify changes with comprehensive testing

Refactoring Checklist

  • Java Best Practices: Immutability, Optional usage, defensive programming, modern Java features
  • Spring Boot Patterns: Constructor injection, proper annotations, configuration management
  • Clean Code: Guard clauses, meaningful names, single responsibility, self-documenting code
  • SOLID Principles: SRP, OCP, LSP, ISP, DIP adherence
  • Architecture: Feature-based organization, DDD patterns, repository pattern
  • Code Smells: Dead code removal, magic numbers extraction, complex conditionals simplification
  • Testing: Maintain test coverage, update tests when refactoring

Key Refactoring Patterns

1. Java-Specific Refactorings

Guard Clauses with Optional

Convert nested conditionals to early returns:

// Before
public Order processOrder(OrderRequest request) {
    if (request != null) {
        if (request.isValid()) {
            if (request.getItems() != null && !request.getItems().isEmpty()) {
                return createOrder(request);
            }
        }
    }
    return null;
}

// After
public Optional<Order> processOrder(OrderRequest request) {
    if (request == null) return Optional.empty();
    if (!request.isValid()) return Optional.empty();
    if (request.getItems() == null || request.getItems().isEmpty()) return Optional.empty();

    return Optional.of(createOrder(request));
}
Extract Helper Methods

Break complex logic into focused, well-named methods:

// Before
public BigDecimal calculateTotal(List<OrderItem> items, Customer customer) {
    BigDecimal subtotal = items.stream()
        .map(item -> item.getPrice().multiply(BigDecimal.valueOf(item.getQuantity())))
        .reduce(BigDecimal.ZERO, BigDecimal::add);

    BigDecimal tax = subtotal.compareTo(BigDecimal.valueOf(100)) > 0
        ? subtotal.multiply(BigDecimal.valueOf(0.08))
        : subtotal.multiply(BigDecimal.valueOf(0.05));

    BigDecimal shipping = subtotal.compareTo(BigDecimal.valueOf(50)) < 0
        ? BigDecimal.valueOf(10)
        : BigDecimal.ZERO;

    return subtotal.add(tax).add(shipping);
}

// After
public BigDecimal calculateTotal(List<OrderItem> items, Customer customer) {
    final BigDecimal subtotal = calculateSubtotal(items);
    final BigDecimal tax = calculateTax(subtotal);
    final BigDecimal shipping = calculateShipping(subtotal);

    return subtotal.add(tax).add(shipping);
}

private BigDecimal calculateSubtotal(List<OrderItem> items) {
    return items.stream()
        .map(item -> item.getPrice().multiply(BigDecimal.valueOf(item.getQuantity())))
        .reduce(BigDecimal.ZERO, BigDecimal::add);
}

private BigDecimal calculateTax(BigDecimal subtotal) {
    final BigDecimal taxRate = subtotal.compareTo(MINIMUM_FOR_STANDARD_TAX) > 0
        ? STANDARD_TAX_RATE
        : REDUCED_TAX_RATE;
    return subtotal.multiply(taxRate);
}

private BigDecimal calculateShipping(BigDecimal subtotal) {
    return subtotal.compareTo(FREE_SHIPPING_THRESHOLD) < 0
        ? SHIPPING_COST
        : BigDecimal.ZERO;
}

Read the full file on GitHub · 529 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. 2d ago First seen · 529 lines · 61 tokens per session scan A fcfc65881e69

Subscribe to this mod's changes

java-refactor-expert is an agent published in the GitHub repository giuseppe-trisciuoglio/developer-kit (337 stars, last pushed 14d ago), licensed MIT. It adds 61 tokens to every session and 3,630 once invoked, about $0.0003 per session on Opus 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.