エージェント的リファクタリング:AIコーディングエージェントに関する実証的研究
Agentic Refactoring: An Empirical Study of AI Coding Agents
November 6, 2025
著者: Kosei Horikawa, Hao Li, Yutaro Kashiwa, Bram Adams, Hajimu Iida, Ahmed E. Hassan
cs.AI
要旨
OpenAI Codex、Claude Code、Cursorなどのエージェント型コーディングツールは、ソフトウェアエンジニアリングの風景を一変させつつある。これらのAI駆動システムは、複雑な開発タスクを自律的に計画・実行する自律的なチームメイトとして機能する。特に、外部から観測可能な動作を変更せずに内部的なコード品質を向上させる持続可能なソフトウェア開発の要であるリファクタリングにおいて、エージェントは能動的な参加者となった。しかしながら、その利用が広まる一方で、実践においてエージェントによるリファクタリングがどのように利用されているか、人間主導のリファクタリングと比較してどう異なるか、コード品質にどのような影響を与えるかについて、実証的な理解が決定的に欠如している。この実証的ギャップを埋めるため、本稿では実世界のオープンソースJavaプロジェクトにおけるAIエージェント生成リファクタリングに関する大規模調査を実施する。AIDevデータセットから得られた12,256のプルリクエストと14,988のコミットに含まれる15,451のリファクタリングインスタンスを分析した。実証分析の結果、この開発パラダイムにおいてリファクタリングが一般的かつ意図的な活動であり、エージェントがコミットの26.1%で明示的にリファクタリングを対象としていることが明らかになった。リファクタリングタイプの分析から、エージェントの作業は、変数型の変更(11.8%)、パラメータ名変更(10.4%)、変数名変更(8.5%)といった、低水準で一貫性志向の編集が支配的であり、人間のリファクタリングで一般的な高水準な設計変更よりも局所的な改善を好む傾向が示された。さらに、エージェントによるリファクタリングの動機は、保守性(52.5%)と可読性(28.1%)に集中しており、内部品質への関心が圧倒的である。加えて、コード品質メトリクスの定量的評価により、エージェントによるリファクタリングは、特に中規模の変更において、構造的メトリクスに統計的に有意ではあるが小幅な改善をもたらし、クラスサイズと複雑性を減少させることが示された(例:Class LOC 中央値 Δ = -15.25)。
English
Agentic coding tools, such as OpenAI Codex, Claude Code, and Cursor, are transforming the software engineering landscape. These AI-powered systems function as autonomous teammates capable of planning and executing complex development tasks. Agents have become active participants in refactoring, a cornerstone of sustainable software development aimed at improving internal code quality without altering observable behavior. Despite their increasing adoption, there is a critical lack of empirical understanding regarding how agentic refactoring is utilized in practice, how it compares to human-driven refactoring, and what impact it has on code quality. To address this empirical gap, we present a large-scale study of AI agent-generated refactorings in real-world open-source Java projects, analyzing 15,451 refactoring instances across 12,256 pull requests and 14,988 commits derived from the AIDev dataset. Our empirical analysis shows that refactoring is a common and intentional activity in this development paradigm, with agents explicitly targeting refactoring in 26.1% of commits. Analysis of refactoring types reveals that agentic efforts are dominated by low-level, consistency-oriented edits, such as Change Variable Type (11.8%), Rename Parameter (10.4%), and Rename Variable (8.5%), reflecting a preference for localized improvements over the high-level design changes common in human refactoring. Additionally, the motivations behind agentic refactoring focus overwhelmingly on internal quality concerns, with maintainability (52.5%) and readability (28.1%). Furthermore, quantitative evaluation of code quality metrics shows that agentic refactoring yields small but statistically significant improvements in structural metrics, particularly for medium-level changes, reducing class size and complexity (e.g., Class LOC median Δ = -15.25).