Skip to content

The Deska blog

Running Agents on a Rails App: A Technical Stack Guide

Learn how to integrate AI agents for Rails projects into your workflow using tools like Claude Code and Deska to automate testing and refactoring safely.

12 min read

Modern web development increasingly relies on automated assistance to manage complex business logic and legacy codebases. When you are running agents on a rails app, the primary challenge is not just generating code but ensuring that the agent understands the strict conventions of Ruby on Rails and the state of your database. A successful integration requires a combination of reliable inference, context management, and a robust execution environment that prevents the agent from making destructive changes to your local environment.

The Architecture of AI Agents in Ruby on Rails

An AI agent differs from a standard LLM chat because it possesses the ability to execute actions within your file system and terminal. In a Rails context, this means the agent can run migrations, execute RSpec or Minitest suites, and interact with the Rails console.

The stack typically consists of three layers. The first layer is the model itself, such as Claude 3.5 Sonnet or GPT 4o. The second layer is the agentic framework, which translates your natural language requests into specific shell commands. The third layer is the workspace, where these commands are executed. Because Rails is a highly integrated framework, the agent needs access to the entire directory structure to understand how a change in a model affects a corresponding controller or view.

Popular Agents for Rails Development

Several tools currently lead the market for autonomous coding. Each takes a different approach to how they interact with your Ruby code.

  • Claude Code: A command line agent from Anthropic that excels at complex reasoning and adheres well to the "Convention over Configuration" philosophy of Rails.
  • Codex CLI: A utility focused on quick terminal operations and small script generation.
  • OpenCode: An open source alternative that allows for more granular control over the prompts and tools provided to the agent.

These tools differ in approach when it comes to context window management. Some agents attempt to index your entire app/ and lib/ folders, while others rely on a "rag" approach to pull in only the most relevant snippets based on your current task.

Setting Up a Workspace for Agents

For developers who prefer a visual representation of their work, running agents inside a terminal emulator is sometimes insufficient. This is where an infinite canvas becomes useful. Instead of switching between tabs, you can place your agent terminal, your source code, and your development server side by side.

Deska provides a desktop application for Mac, Windows, and Linux that facilitates this specific layout. It allows you to run Claude Code, Codex CLI, and OpenCode as individual panels within a single workspace. This local-first approach ensures that your sensitive Rails credentials, such as master.key or .env files, never leave your machine to be processed on a third party server for indexing.

Tool Comparison for Rails Integration

FeatureClaude CodeOpenCodeGitHub Copilot
Terminal AccessFullFullLimited
Rails KnowledgeHighMediumHigh
Execution EnvironmentLocal ShellLocal ShellIDE Extension
Multi-file EditingNativeNativeLimited

While GitHub Copilot is excellent for autocomplete, it often struggles with tasks that require running rails generate or fixing failing tests across multiple files. Dedicated agents are generally more capable for these complex, multi-step operations.

Implementing a Test-Driven Workflow

One of the most effective ways to use agents for Rails projects is to delegate the "Red-Green-Refactor" cycle. You can provide the agent with a failing test and ask it to modify the necessary models and controllers until the test passes.

  1. Open a terminal panel and run your test suite to confirm the failure.
  2. Direct the agent to read the error output and the relevant files.
  3. Allow the agent to propose and apply changes to the code.
  4. Run the tests again automatically to verify the fix.

Inside the Deska environment, you can use coding agents to handle these tasks in the background while you monitor the output in a separate terminal panel. If you need to step away from your desk, the mobile app allows you to monitor the progress of long running test suites or agent tasks through a secure relay that does not require exposing your local ports to the internet.

Security and Privacy Considerations

Giving an agent access to your terminal is a powerful but risky move. Rails applications often contain sensitive data in the development database. When using coding agents, it is critical to use a tool that respects your privacy. Deska allows you to use your own API keys, meaning you maintain a direct relationship with the model provider.

The workspace itself is designed to keep your files local. By using agent threads, you can isolate different tasks, ensuring that the history and context of a refactoring job do not leak into a separate feature implementation.

Voice Control and Automation

Sometimes, explaining a complex Rails bug is easier through speech than typing. The voice features in modern tools allow for a more fluid interaction. For instance, the Ask Deska assistant can drive the workspace by opening the necessary panels or terminals when you describe a problem. You might tell the assistant to "open the logs and the User model," and it will arrange the workspace for you, saving the time spent on manual window management.

FAQ

how to run claude code on rails

To run Claude Code on a Rails project, you first need to install the Claude CLI tool. Once installed, navigate to your Rails root directory in a terminal. If you are using Deska, you can open a new panel, select Claude Code, and begin issuing commands like "fix the N+1 query in the index action."

best ai agent for ruby on rails

The best agent depends on your specific needs, but Claude Code is currently highly regarded for its ability to handle Ruby syntax and Rails conventions. OpenCode is a strong alternative if you prefer an open source foundation. Using these side by side in a unified workspace helps in comparing their output.

are ai agents safe for private code

Safety depends on the implementation. A local-first approach is generally the safest for private Rails applications. Ensure that the tool you choose does not upload your entire codebase to a remote server for training. Using your own API keys with a secure workspace helps maintain control over your data.

Getting Started with Deska

If you want to optimize your Rails development workflow with multiple AI agents, you can download the Deska desktop app for free. It provides the necessary infrastructure to run your favorite tools in an organized, visual environment. By keeping your data and storage local, you gain the benefits of AI without compromising the security of your Rails application.