Free AI Agents for Code Refactoring: Setup and Testing
The average developer can integrate LLMs into their daily workflow at no cost by using agents with free quotas. Qwen offers 1,000 daily requests, compatible with popular tools like Claude Code and Kilo Code. This enables local testing of code refactoring and generation via API.
Agents interact with models over the internet, editing files directly in the IDE or console. The focus is on free options: OpenRouter, built-in Kilo Code models, and Qwen without a subscription.
Choosing Agents and Providers
Let's examine key free options:
- Claude Code (Anthropic): A console agent, a top performer in coding benchmarks.
- Kilo Code: A plugin for VS Code/IDEA/CLI, supporting multiple models.
- OpenCode, Cline: Open-source agents for custom models.
- Qwen Code (Alibaba): 1,000 free requests/day, a token usable with any agent.
Agent installation is standard: follow guides in their repositories. Qwen is the primary provider for testing due to its generous quota and the qwen3-coder-plus model.
Obtaining a Qwen Token
Install Qwen Code, run qwen, and authorize: _/auth_ → Qwen OAuth. Create an account on the website, then retrieve the token from ~/.qwen/oauth_creds.json (the access_token field).
This token is inserted into other agents' configurations. Limitations include RPM and daily limits, sufficient for trial tasks (refactoring, debugging).
Integration with Kilo Code
Install the Kilo Code plugin in VS Code. In settings, select Qwen as the provider and paste the access_token. Switch profiles to qwen3-coder-plus in all modes (default, background, think).
// Example of switching profiles in the UI
// Dropdown menu → qwen3-coder-plus
The agent is ready to edit files: highlight code, provide a prompt—changes are applied automatically.
Configuring Claude Code via Router
Claude Code requires a proxy for Qwen: install claude-code and claude-code-router. Create ~/.claude-code-router/config.json:
{
"Providers": [
{
"name": "qwen",
"api_base_url": "https://portal.qwen.ai/v1/chat/completions",
"api_key": "your_access_token",
"models": ["qwen3-coder-plus"]
}
],
"Router": {
"default": "qwen,qwen3-coder-plus"
}
}
Run ccr restart, then ccr code. The agent uses Qwen under the hood while maintaining the familiar interface.
Testing on Java Code Refactoring
The source code is a monolithic DataProcessor handling data processing, discounts, and categorization. Task: split into classes, add exceptions, Javadoc, and explain changes.
import java.util.*;
public class DataProcessor {
public List<Map<String, Object>> processData(List<Map<String, Object>> data, Map<String, Object> options) {
// ... (full code as in the original)
}
// main method with test data
}
Prompt for agents:
Perform a refactoring of the following "spaghetti code" in DataProcessor.java. Requirements:
1. Break down the monolithic method into logical classes with proper separation of concerns (e.g., a separate class for calculations, another for data processing).
2. Add error handling (use exceptions instead of printing to console).
3. Write Javadoc for each new class and method.
4. Briefly explain the architectural changes you made and why.
Both agents (Kilo Code, Claude Code + Qwen) completed the task in 1.5–2 minutes. Results varied: one created PriceCalculator, ItemValidator; the other—DataProcessorService with DiscountApplicator. Quality is assessed separately via benchmarks.
Scaling and Alternatives
For intensive work, combine providers:
- OpenRouter: 10+ free models (not top-tier).
- Local models: If quotas run out, switch to Ollama/LM Studio.
- AI-first IDE: Cursor, Zed—with native AI integration.
Monitor rankings (LMSYS, HuggingFace)—models are updated weekly.
Key Takeaways
- Qwen: 1,000 free requests/day, qwen3-coder-plus model for coding.
- Agents edit local files via API, no copy-paste needed.
- Token from
oauth_creds.jsonworks universally for Kilo/Claude. - Refactoring time: 90–120 seconds for an average task.
- Limitations: RPM/daily—suitable for testing, not production.
— Editorial Team
No comments yet.