International Research Journal of Engineering and Technology (IRJET)
e-ISSN: 2395-0056
Volume: 13 Issue: 10 | Oct 2026
p-ISSN: 2395-0072
www.irjet.net
CleanCode: An Autonomous On-Device IDE Refactoring Framework Using Tree-Sitter and Local Large Language Models Mr. Vishwanath1, Sriya Nag Yazali2, S. Hemanth Kumar3, T. Indu4, T. Nitish Kumar5 1Assistant Professor, Dept. of Computer Science and Engineering, Hyderabad Institute of Technology and
Management (HITAM), Hyderabad, Telangana, India
2,3,4,5B.Tech Student, Dept. of Computer Science and Engineering, Hyderabad Institute of Technology and
Management (HITAM), Hyderabad, Telangana, India ----------------------------------------------------------------------***---------------------------------------------------------------------
Abstract - Modern engineering teams are often
reporting, these traditional analyzers lack automated remediation capabilities, requiring developers to manually refactor complex code blocks.
challenged with technical difficulties, which include bloated functions, high structural complexity and heavy nests. Standard tools only point out code bugs without fixing them, while using basic online AI to fix them can leak private data and break your code. To resolve these issues, this project introduces CleanCode, which can be described as an experimental autonomous framework packaged as a native extension on Visual Studio Code, whose prime intent is to automate the technical debt within multi-file workspaces. Rather than viewing source code as plain, flat text, CleanCode employs a Tree-sitter to construct ‘Concrete Syntax Trees’ across multiple languages, such as Python, Java, and C++. This is done to identify programming bottlenecks, restrict context boundaries, and route isolated code snippets to a localized Large Language Model running via Ollama, utilizing the Qwen Coder architecture for the semantic refactoring of the code. Essentially, the system bypasses string replacement by enforcing syntactic as well as semantic refactoring, and by utilizing version control primitives to generate secure patches. CleanCode is presented through a side-by-side Webview dashboard which is present in the editor environment. This delivers a secure, deterministic and language-agnostic paradigm for enterprise-grade maintenance of software programs.
Recently, generative Artificial Intelligence (AI) and Large Language Models (LLMs) have emerged as candidates for automated code transformation. However, direct integration of cloud-hosted LLM APIs into development environments introduces critical operational challenges:
1.1 Background and Technical Debt Remediation Technical debt remediation involves identifying, isolating, and restructuring inefficient code constructs without altering external runtime behavior. Manual refactoring requires significant developer time and risk of regression. CleanCode automates this workflow by extracting highcomplexity syntax nodes, bounding the prompt context to local scope, and utilizing local AI models to rewrite code safely.
Key Words: Code Refactoring, Technical Debt, Static Code Analysis, Tree-sitter, Large Language Models, Local LLM Inference, Cyclomatic Complexity, Visual Studio Code Extension
1. INTRODUCTION
1.2 Need for an On-Device Refactoring System
Continuous modification and rapid evolution of modern enterprise software systems often lead to software degradation, commonly categorized as technical debt. Technical debt manifests as excessive cyclomatic complexity, deeply nested conditional structures, redundant code paths, and bad code smells. If left unaddressed, technical debt severely degrades code maintainability, complicates unit testing, and increases regression bug incidence rates during feature additions.
Enterprise environments require air-gapped security protocols where sensitive code cannot leave the local workstation. CleanCode addresses this need by running local model inference on Ollama. Combined with pre- and post-refactoring AST verification and cyclomatic complexity checking, CleanCode provides automated code maintenance with zero data leak risk.
2. LITERATURE REVIEW
Static program analysis tools (such as SonarQube, ESLint, and Pylint) are widely utilized to identify complexity hotspots and bad code smells. While effective at diagnostic
© 2026, IRJET
|
Impact Factor value: 8.601
Data Privacy & Compliance Risks: Uploading proprietary codebases to external cloud servers violates data privacy regulations and enterprise security policies. Scope Distortion & Context Pollution: Flat-text prompt engineering lacks structural AST awareness, causing LLMs to modify unaffected global scope or hallucinate missing dependencies. Syntactic Corruption: Unchecked generative outputs frequently introduce syntax errors or break existing function signature contracts.
Automated code transformation and program analysis have been extensively studied across software engineering
|
ISO 9001:2008 Certified Journal
|
Page 1165
International Research Journal of Engineering and Technology (IRJET)
e-ISSN: 2395-0056
Volume: 13 Issue: 10 | Oct 2026
p-ISSN: 2395-0072
www.irjet.net
disciplines. Recent research spans rule-based static metrics, neural code generation, and parser-guided AST transformations. 2.1 Static Analysis and Complexity Metrics McCabe [1] established Cyclomatic Complexity V(G) based on control flow graphs as a standard metric for software maintainability. Fowler [2] defined bad code smells (such as Long Method and Deep Nesting) as primary targets for refactoring. Standard static tools automate metric computation but lack generative capabilities for automated fixes.
AST Parser
Tree-sitter
Incremental CST parsing & node extraction
Inference Host
Ollama (Local)
Air-gapped model execution (QwenCoder)
Communication Protocol
REST / JSON APIs
Local IPC communication
Validation Engine
Cyclomatic Syntax verification & Metrics & AST complexity calculation
3.1 Requirement Analysis
2.2 Neural Code Models and Context Limitations
Functional requirements include automatic detection of high-complexity functions (V(G) > 10), AST node context isolation, local LLM generation, pre/post syntax validation, cyclomatic complexity reduction checking, and interactive side-by-side diff display. Security requirements mandate zero external cloud communication to ensure total data confidentiality.
Transformer-based models (Vaswani et al. [3]) and code LLMs (Chen et al. [4], Rozière et al. [5]) have shown strong capabilities in code completion. However, studies show that unconstrained prompt approaches on raw source files lead to scope distortion, variable hallucination, and broken syntax contracts.
3.2 System Design and Workflow
2.3 Local Inference and Parser-Guided Refactoring
The system architecture follows a decoupled, pipelinedriven execution flow as illustrated in Fig -1:
Local execution runtimes like Ollama enable privacypreserving 7B to 14B parameter model execution on local workstations. Research by Brunel et al. [6] highlighted the benefits of utilizing Concrete Syntax Trees (CST) via Treesitter to guide neural program repair, maintaining structural validity during automated edits. 2.4 Research Gap While static analyzers identify bugs and cloud LLMs attempt automated generation, there is a lack of an integrated, air-gapped IDE tool that combines incremental AST context extraction, local LLM execution, and strict pre/post metric validation. CleanCode addresses this research gap.
3. METHODOLOGY
Fig -1: CleanCode System Architecture and Autonomous Refactoring Pipeline
The methodology followed for developing CleanCode focuses on modular architecture, AST isolation, local inference, and metric validation. Table -1 outlines the core software and technology specifications of the system.
3.3 Tree-sitter Concrete Syntax Tree Isolation CleanCode intercepts the active file buffer and constructs an incremental CST using language-specific Tree-sitter parsers (Python, JS, C++). Target function nodes exceeding complexity thresholds are extracted along with local variable scope and type declarations, preventing context window pollution.
Table -1: Software and Technology Requirements Component
Technology / Tool
Purpose
Development IDE
Visual Studio Code
Host editor & extension environment
Extension Frontend
TypeScript & React
UI interaction & Webview dashboard
© 2026, IRJET
|
Impact Factor value: 8.601
3.4 Local AI Inference via Ollama The isolated code node is sent via HTTP REST payload to Ollama running Qwen-Coder at 127.0.0.1:11434. Qwen-
|
ISO 9001:2008 Certified Journal
|
Page 1166
International Research Journal of Engineering and Technology (IRJET)
e-ISSN: 2395-0056
Volume: 13 Issue: 10 | Oct 2026
p-ISSN: 2395-0072
www.irjet.net
Coder generates structurally optimized code candidates locally without transmitting data over external networks.
4.1 Quantitative Performance Metrics • Mean Cyclomatic Complexity: Reduced from 18.4 (Pre-refactoring) to 6.2 (Post-refactoring), achieving a 66.3% reduction. • Syntax Validation Success Rate: Achieved 98.6% validity with Tree-sitter parser validation compared to 74.1% with naive cloud LLM prompts. • Context Memory Footprint: Bounding context to isolated AST nodes reduced request size from 16.4 KB to 2.1 KB. • Average Inference Latency: 1.84 seconds per function on a standard local developer workstation.
3.5 Dual-Phase Validation Engine To guarantee correctness, CleanCode subjects the refactored candidate code to two strict validation checks: • (i) Syntactic Verification: Tree-sitter parses the candidate snippet. If ERROR or MISSING syntax nodes are detected, the output is rejected. • (ii) Metric Verification: Cyclomatic complexity is recalculated (Vpost). The patch is accepted only if Vpost < Vpre.
5. DISCUSSION
3.6 VS Code Webview Interface
The results demonstrate that CleanCode successfully resolves technical debt while maintaining total air-gapped operational security. By isolating AST nodes prior to prompting, CleanCode eliminates context pollution and prevents LLM scope hallucinations. Furthermore, the inclusion of Tree-sitter pre/post validation ensures that syntax-corrupted LLM outputs are caught and discarded prior to developer presentation.
Validated code patches are rendered inside a side-by-side diff editor within VS Code, allowing developers to review changes, inspect complexity savings, and apply or discard patches with one click.
4. RESULTS CleanCode was evaluated across a benchmark suite of 50 open-source repositories written in Python, JavaScript, and C++. Table -2 summarizes the functional validation test cases executed across the core refactoring pipeline.
5.1 Limitations Current limitations include single-file context scoping (cross-file class dependency resolution is under active development) and reliance on workstation GPU capabilities for Ollama execution speed.
Table -2: Functional Test Cases and Results Test Case
Input / Action
Expected Result Result
6. CONCLUSIONS
Select complex CST node AST Node function (V(G) > extracted with Pass Isolation 10) local scope
CleanCode introduces an autonomous, deterministic, and privacy-preserving code refactoring engine for IDEs. By coupling Tree-sitter incremental parsing with local QwenCoder inference on Ollama, CleanCode eliminates technical debt safely without cloud data leak risks. Empirical tests validate a 66.3% complexity reduction and a 98.6% syntax pass rate.
Complexity Scan multi-file High-complexity Pass Detection workspace functions flagged Context Bounding
Extract variables types
local Global & excluded payload
Refactored Local LLM Send isolated returned Inference node to Ollama REST
scope from Pass code via Pass
Syntactic Validation
Zero ERROR or Parse candidate MISSING AST Pass with Tree-sitter nodes
Syntax Error Rejection
Inject Invalid candidate malformed LLM Pass rejected safely output
6.1 Future Scope Future enhancements include workspace-wide multi-file dependency resolution, automated unit test generation to verify runtime behavioral equivalence, and model quantization for sub-second inference speeds.
REFERENCES [1] T. J. McCabe, "A Complexity Measure," IEEE Transactions on Software Engineering, vol. SE-2, no. 4, pp. 308-320, 1976.
Metric Compare Vpost Accepted only if Pass Verification against Vpre Vpost < Vpre Webview Trigger side-by- Interactive diff Pass Diff Display side preview rendered in IDE
[2] M. Fowler, Refactoring: Improving the Design of Existing Code, 2nd ed. Boston, MA, USA: AddisonWesley, 2018.
Patch Approve Source buffer Pass Application refactored patch updated cleanly
© 2026, IRJET
|
Impact Factor value: 8.601
|
ISO 9001:2008 Certified Journal
|
Page 1167
International Research Journal of Engineering and Technology (IRJET)
e-ISSN: 2395-0056
Volume: 13 Issue: 10 | Oct 2026
p-ISSN: 2395-0072
www.irjet.net
[3] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, L. Kaiser, and I. Polosukhin, "Attention is all you need," in Advances in Neural Information Processing Systems (NeurIPS), vol. 30, pp. 5998-6008, 2017. [4] M. Chen et al., "Evaluating large language models trained on code," arXiv preprint arXiv:2107.03374, 2021. [5] B. Rozière et al., "Code Llama: Open foundation models for code," arXiv preprint arXiv:2308.12950, 2023. [6] E. Brunel et al., "Concrete syntax trees as structured prompts for neural program repair," Journal of Systems and Software, vol. 208, p. 111890, 2024.
© 2026, IRJET
|
Impact Factor value: 8.601
|
ISO 9001:2008 Certified Journal
|
Page 1168