NAME

Claude::Agent::Code::Refactor - Automated code refactoring with review-fix loops

VERSION

Version 0.02

SYNOPSIS

use Claude::Agent::Code::Refactor qw(refactor refactor_until_clean);
use IO::Async::Loop;

my $loop = IO::Async::Loop->new;

# Automatic review -> fix -> re-review loop
my $result = refactor_until_clean(
    paths   => ['lib/'],
    options => Claude::Agent::Code::Refactor::Options->new(
        max_iterations  => 5,
        min_severity    => 'medium',
        categories      => ['bugs', 'security'],
        permission_mode => 'acceptEdits',
    ),
    loop    => $loop,
)->get;

if ($result->is_clean) {
    print "All issues resolved!\n";
} else {
    print "Remaining issues: ", $result->final_issues, "\n";
}

DESCRIPTION

Claude::Agent::Code::Refactor provides automated code refactoring using the Claude Agent SDK. It integrates with Claude::Agent::Code::Review to create a review-fix-re-review loop that automatically fixes issues until the code is clean (or max iterations reached).

EXPORTED FUNCTIONS

refactor

my $future = refactor(
    target  => $target,      # file, dir, or 'staged'
    options => $options,     # Claude::Agent::Code::Refactor::Options
    loop    => $loop,        # IO::Async::Loop
);
my $result = $future->get;

High-level refactor function that auto-detects the target type.

refactor_until_clean

my $future = refactor_until_clean(
    paths   => \@paths,      # files and/or directories
    options => $options,
    loop    => $loop,
);
my $result = $future->get;

Main refactoring loop: review -> fix -> re-review until clean or max iterations.

refactor_issues

my $future = refactor_issues(
    issues  => \@issues,     # Claude::Agent::Code::Review::Issue objects
    options => $options,
    loop    => $loop,
);
my $result = $future->get;

Fix a specific set of issues (single pass, no re-review).

SEE ALSO

AUTHOR

LNATION, <email at lnation.org>

LICENSE

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under The Artistic License 2.0 (GPL Compatible).