How to Install and Configure Roo Code (Cline) in VS Code: Turning AI into an Autonomous Teammate

Artificial Intelligence tutorial - IT technology blog
Artificial Intelligence tutorial - IT technology blog

The Gap Between Autocomplete and an AI Coding Agent

GitHub Copilot or Cursor Tab are convenient when you need to quickly whip up a helper function or boilerplate. But when faced with real-world challenges — like refactoring five service files simultaneously, syncing a Prisma schema with migration scripts, or running tests and fixing code until they pass — autocomplete tools quickly hit their ceiling.

The old workflow was tedious: copy code into the chat window, copy terminal errors back out, then paste each diff into the editor. You essentially acted as a human relay between your terminal and the LLM.

Autonomous Coding Agents completely eliminate this friction. Roo Code, a prominent open-source fork of Cline, has direct access to your VS Code workspace: inspecting directory trees, reading file contents, generating git diffs to apply changes, and launching terminal commands to run builds or tests in an autonomous repair loop.

Install Roo Code in VS Code in 1 Minute

Roo Code builds upon Cline with key improvements: dedicated modes (Code, Architect, Ask), support for Custom Modes, and optimized context token usage. Here is how to install it:

  1. Press Ctrl + Shift + X (or Cmd + Shift + X on macOS) to open Extensions.
  2. Search for Roo Code.
  3. Select the extension published by RooVeterinaryInc and click Install.

Once installed, a kangaroo icon will appear in the Activity Bar on the left. Click it to open the Roo Code panel.

Configure Providers and Optimize Your Token Budget

Unlike flat-rate models charging $20/month, Roo Code uses a BYOK (Bring Your Own Key) model. You pay strictly for the API tokens you consume. Without proper configuration, costs can spiral quickly, and you also risk letting the AI run destructive commands across your workspace.

1. Set Up Your API Provider via OpenRouter

Click the gear icon (Settings) in the top corner of the Roo Code panel. Under the Provider section, select OpenRouter rather than connecting directly to individual vendors. OpenRouter lets you prepay $5–$10 via credit card and seamlessly switch models depending on task complexity:

  • Complex tasks, architectural shifts, and multi-file logic refactoring: Use Claude 3.5 Sonnet or Claude 3.7 Sonnet. Both models generate remarkably accurate diffs with minimal hallucinations, and prompt caching cuts re-read context costs by 80–90%. A complex refactoring session typically costs around $0.20 – $0.60.
  • Everyday tasks (writing unit tests, generating mock data, code lookup): Switch to DeepSeek V3 or Gemini 2.5 Flash. At around $0.14 – $0.30 per million tokens, they are over 10x cheaper than Claude while handling isolated tasks smoothly.

2. Guide the Agent with a .clinerules File

Every repository has its own conventions. Rather than repeating guidelines like “no any types” or “use Vitest instead of Jest” in every prompt, create a .clinerules file in your project’s root directory.

Here is an example configuration for a Node.js/TypeScript project:

# Project Rules for Roo Code

## Tech Stack
- Runtime: Node.js 20 LTS
- Framework: Fastify with TypeScript
- Testing: Vitest
- ORM: Prisma

## Coding Standards
- Prefer functional programming; avoid classes except for service adapters.
- Strictly avoid the `any` type; always define explicit interfaces or types.
- When modifying business logic, always add unit tests in `tests/`.
- Preserve existing business logic comments in files.

## Terminal Restrictions
- Only run tests on specific files: `npx vitest run <path-to-test>`.
- Do not run the entire test suite unless explicitly requested.
- Never run `npm install` to add new packages without asking first.

Roo Code automatically injects the contents of this file into the system prompt for every turn. The agent adheres to your team’s standards right from the first file.

3. Safely Configure Auto-Approval Permissions

Roo Code can execute bash commands and edit code directly on your machine. While this is its greatest strength, it is a double-edged sword if you grant unrestricted access. Navigate to Auto-Approve in Settings to tighten permissions:

  • Read files & Directory listing: Set to Always allow. Reading files and inspecting directories is safe and allows the agent to scan your codebase quickly without constant approval prompts.
  • Edit files: Keep on Manual Approve. Make it a habit to review the git diff in the panel before allowing the AI to overwrite files on disk.
  • Execute Terminal Commands: Never enable full auto-approval. Only whitelist safe commands such as git status, git diff, and npx vitest*. Commands affecting infrastructure like prisma migrate, git push, or deletion commands like rm and del must always require manual confirmation.

Controlling the Loop and Managing Real-World Context

To prevent the agent from getting stuck in loops, making bad edits, and burning through API credits, follow this control workflow:

1. Start with a Scoped Prompt

Avoid vague instructions like: “Write an auth API for me.” Instead, break it down into concrete objectives:

# Example prompt with clear acceptance criteria:
"Read src/utils/jwt.ts. Write a verifyToken(token: string) function that handles TokenExpiredError.
Then create a corresponding test in tests/jwt.test.ts and run `npx vitest run tests/jwt.test.ts` to verify."

The agent will call read_file, generate a diff to implement the function, and open the terminal to run Vitest. If tests fail, it will read the stack trace and iterate on the code until the tests pass.

2. Monitor Context Size to Avoid Unnecessary Costs

Check the bottom status bar in the Roo Code panel for two key metrics:

  • Context: The number of tokens stored in the current session memory. When this exceeds 60,000–70,000 tokens, request costs spike because the LLM must re-read the entire history on every turn. The model is also more likely to lose track of initial instructions.
  • Cost: Real-time cumulative cost for the current task.

The solution is simple: once a task is finished, click New Task (+) to clear the context. Keep each session focused on a single task.

Finally, before handing off large tasks to the agent, create a safe checkpoint using Git:

git checkout -b chore/agent-refactor-auth
git add . && git commit -m "checkpoint before roo code session"

If the agent goes off track and breaks the codebase, you are just two seconds away from running git reset --hard HEAD to return everything to a clean state.

Share: