arrow
Return

RefactorGPT: a ChatGPT-based multi-agent framework for automated code refactoring

delete2025-10-14
delete0
PRE
AI
M
Muhammed Abdulhamid Karabıyık *
DOI:10.7717/peerj-cs.3257delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
The rise of large language models has redefined what is computationally possible in code generation, yet their potential in systematic software refactoring remains largely untapped. This article introduces RefactorGPT, a ChatGPT-augmented sequential multi-agent framework that transforms refactoring from a monolithic, opaque process into a modular, explainable, and scalable workflow. The system orchestrates four specialized agents, Analyzer, Refactor, Refine, and Fixer, to sequentially analyse source code, apply structural refactoring, enhance code quality, and recover from potential generation errors. Unlike conventional rule-based tools or one-shot large language model (LLM) prompts, RefactorGPT leverages ChatGPT iteratively across clearly defined responsibilities, enabling controlled refactoring with functional guarantees. To evaluate the framework's effectiveness, we constructed a curated dataset encompassing nine classical refactoring techniques across three complexity levels. RefactorGPT demonstrated consistent improvements in code modularity, readability, and structural decomposition, while maintaining computational efficiency. Notably, the system achieved full execution correctness through autonomous error recovery, showcasing robustness in practical scenarios. This study contributes a reusable blueprint for LLM-integrated refactoring systems and presents a novel application of ChatGPT not merely as a code generator, but as a cooperative agent in intelligent software refactoring. The findings reveal a path forward for embedding language models into real-world developer workflows, not as assistants, but as collaborators in code evolution.
Keywords:
ChatGPT
Code refactoring
Multi-agent systems
Software automation

Journal

PeerJ Computer Science cover
PeerJ Computer Science
IF:
2.5
Papers:
3.4K
Citations:
6.9K

Organization

N
Nigde Omer Halisdemir University
Scholars:
1.3K
Papers: 1.7K
Citations: 8
Cited Papers

Cited Papers

Refining ChatGPT-Generated Code: Characterizing and Mitigating Code Quality Issues
err2024-06-04
err8
errOAAI
errLiu, Yue; Le-Cong, Thanh; Widyasari, Ratnadira; Tantithamthavorn, Chakkrit; Li, Li; Le, Xuan-Bach D.; Lo, David
errShare
errSave
Code generation by model transformation: a case study in transformation modularity
err2009-11-06
err0
errOAAI
errZef Hemel; Lennart C. L. Kats; Danny M. Groenewegen; Eelco Visser
errShare
errSave
Revisiting the refactoring mechanics
err2019-06-01
err20
PREAI
errOliveira, Jonhnanthan; Gheyi, Rohit; Mongiovi, Melina; Soares, Gustavo; Ribeiro, Marcio; Garcia, Alessandro
errShare
errSave
Sentiment analysis for software engineering
err2018-05-27
err0
PREAI
errBin Lin; Fiorella Zampetti; Gabriele Bavota; Massimiliano Di Penta; Michele Lanza; Rocco Oliveto
errShare
errSave
researcher View more