8/10/2025

From Hours to Minutes: Using Claude Code to Automate RuboCop Formatting

Hey everyone, hope you’re doing great. Today, I want to talk about something that's been a HUGE game-changer for me & my team's Ruby development workflow: automating RuboCop formatting. If you’ve ever spent what feels like a lifetime cleaning up style offenses, you're going to want to stick around for this. We’re going to dive into how you can use the magic of Claude Code to turn a tedious, time-sucking task into something that happens automatically, in the background, without you even thinking about it. Seriously, this is one of those things that, once you set it up, you'll wonder how you ever lived without it.

The Never-Ending Story of Code Formatting

Let's be real for a second. We all know that consistent code style is important. It makes code easier to read, easier to maintain, & easier for new developers to onboard. In the Ruby world, RuboCop is the undisputed king of keeping our code in check. It's a static code analyzer & formatter that enforces the community-driven Ruby Style Guide. It’s an incredibly powerful tool that not only points out what’s wrong but can also automatically fix a ton of issues for you.
But here's the thing: running it manually is a pain. You write some code, you’re in the zone, & then you have to remember to run
1 rubocop -a
before you commit. Or, even worse, you push your code & the CI pipeline fails because of some silly formatting issue you missed. It's a constant cycle of write, check, fix, commit, & it breaks your flow. I can't tell you how many hours I've collectively lost to this process. It’s a necessary evil, but an evil nonetheless.
This is where things get interesting. What if you could have all the benefits of RuboCop without the manual overhead? What if your code could just... format itself as you work? That’s the dream, right? Well, it turns out that dream is now a reality, thanks to a pretty incredible tool called Claude Code.

Enter Claude Code: Your New AI Coding Partner

For those who haven't heard of it yet, Claude Code is an AI coding assistant from Anthropic that lives right in your terminal. Think of it as a junior developer who’s always there to help, but one that can read your entire codebase, understand its patterns, & even take action on your behalf. It can build features from plain English descriptions, debug tricky issues, & automate the kind of tedious tasks that we all hate doing.
One of the most powerful features of Claude Code, & the one we’re going to focus on today, is its ability to use "Hooks." Claude Code Hooks are basically user-defined shell commands that you can set up to run automatically at specific points in Claude's workflow. For example, you can have a hook that runs before a tool is used (
1 PreToolUse
) or after a tool has been used (
1 PostToolUse
). This opens up a world of possibilities for automation, & it's the key to solving our RuboCop problem.

The Magic Combination: Claude Code Hooks & RuboCop

So, how do we put these two things together? The idea is simple: we'll create a Claude Code Hook that automatically runs
1 rubocop -a
(or
1 bundle exec rubocop -a --autocorrect-all
for the newer versions) every time a Ruby file is created or edited. This means that the moment you or Claude makes a change to a Ruby file, our hook will fire & instantly clean up any formatting issues. No more manual checks, no more failed CI builds (at least, not for formatting). It’s all handled for you, in the background. Pretty cool, right?
Now, let's get into the nitty-gritty of how to set this up. It might seem a little intimidating at first, but I promise it's easier than it looks.

Step 1: Getting Your Environment Ready

First things first, you need to have RuboCop & Claude Code installed. If you're a Ruby developer, you probably already have RuboCop set up. If not, you can install it with a simple
1 gem install rubocop
. You'll also want to add it to your project's
1 Gemfile
:

Copyright © Arsturn 2025