Machine Learning

How to Code with Claude's Code

they are amazing for quickly executing lots of code. However, if you've worked a lot with coding agents, you'll notice that they start to struggle after a while. Maybe you spent a few days coding with AI. Everything went smoothly and quickly, and then you start to notice that tasks are taking too long, and the AI ​​is making too many mistakes.

This is a clear sign that you need to start refactoring the code. I believe that refactoring your codebase will become routine after you've coded a lot with coding agents. Coders make mistakes and don't write perfect code. Also, if you don't follow best practices in existing code, the AI ​​will continue to not follow best practices in the new code it creates. Therefore, you need to recreate your repositories continuously.

In this article, I discuss how to know when you need to redo your code, what the signs are, and how to do it effectively using Claude Code or other coding agents.

This infographic highlights the main content of this article. I will be discussing how to refactor your code using Claude Code or other coding agents. I'll take you through the steps of why you should refactor, how to know when to refactor, what signs to look for, and how to successfully refactor your code. Finally, I'll discuss why it's so important to refactor your code, highlighting that it will make your coding agents more effective at implementing implementations in your code repository. Image via ChatGPT.

Why did you refactor your code?

First, I'd like to cover why you should care about the topic I'm discussing. Refactoring code sounds like a chore, and in fact, it was a chore to do every now and then. A few years ago, people had to manually go into the code repository to see what needed to be refactored and start refactoring the code.

This will usually happen once, shortly after multiple uses of the code, because code naturally moves from an optimal state to a critical state very easily by people interacting with the codebase and working on it. This happens whether humans are working on it or if AI agents are working on the codebase.


You need to refactor your code because if the code is good, it just takes more time to implement, and you tend to have errors.

Let me give a specific example. Let's say we have a chatbot design implementation in your app where users can write to an AI bot and get a response. This is just a discussion forum where you show AI responses and user responses. A good code base can ensure that you have one component called a dialog, and this component is used in all the different places in the application where you display the dialog. A poorly designed code base may have one version of this dialog for each different location in the application.

The problem then occurs when you want to make a change in the chat interface. For example, you want to update the color of a dialog box or an AI icon. Naturally, you'd want to update this in every place in the app where you're displaying the chat, but that means the human or AI editing the code has to edit the code in several different places.

If the code, however, was well written, you would only need to update the code in one place because that is the central code of how the dialog should look. This is just a simple example of how well-written code can make it easier to use and less prone to errors.

When to rebuild your codebase

First, I'll cover when you should redo your codebase and what signs to look for.

To put it simply, you should refactor your code when coding agents are slow to execute and when you start noticing agents that cause a lot of bugs during execution. If you see problems appearing in unexpected places, or in code you haven't touched, it's a clear sign that you should start refactoring.

In addition, I recommend that you start remodeling early. Yes, working with code that needs to be refactored is time-consuming and error-prone, but it's also very frustrating because you'll notice that you're starting to make changes, and the coding agents can't do what you tell them to do.


There is no set time when this need to reapply comes into play. It doesn't happen after x number of days or x number of lines of code written. It's more than just something that happens over time. The need to redo the state only occurs after a lot of work has been done in the repository.

My theory is that this happens because a small part of the code starts drifting away from the correct state, which can be for many different reasons. Continued work in this area of ​​code will increase the effects of drift, and after a while, it will become apparent when coding agents or people cannot code there effectively.

Of course, you should try to avoid this as much as possible; however, I believe that recycling is not something you should strive to eliminate completely. I believe it's a natural part of codebase evolution. Instead you just have to accept the fact that you will have to do refactoring every now and then, and you should be aware of the signs of when you should start refactoring your code.

How to recode with Claude Code

Now that you know when to refactor your codebase, I'll start discussing how to refactor your codebase with Claude Code or any coding agent of your choice.

There are a few simple rules I follow whenever I start a remodel.

  • Use the most advanced thinking and the most effort you can use. Remodeling is a craft that requires a lot of creativity, and you don't want to make mistakes here. Example: Use the workflow feature from Claude Code, or xhigh logic in GPT-5.5
  • Only perform one redo at a time on your repository. It's okay to redo while you're doing other uses as well, but you don't want to have multiple redo jobs running at once.
  • If you're not sure about the correct folder structure, compare or give the encoding agent access to another code repository with a good structure you like, and tell it to emulate that.
  • Remodeling takes time. Just have it as a background task while you work on other things

Usually, when I start to recode, I use the following setup: I open my Claude Code in a new project tree in the repository, and spin it with the maximum effort available in Claude Code, which is Ultracode.

When I know what I need to redo, I tell Ultracode and Claude as much information as possible about what needs to be redone and why I'm redoing it. You might think that saying why is unnecessary, and in some cases, it's not, but I find it really useful because the AI ​​understands why I'm doing what I'm doing, which helps it adapt to what I want to use.

I then give the agent plenty of time to go through the entire archive, especially the part I want to redo, and come up with a detailed plan on how to redo it. I do this in program mode in Claude Code.

Then I read the whole program to make sure it was as I expected. Generally, agents are better at reworking than I am, so I find that programs are usually right on the first try.


An important piece of information I use whenever I'm doing refactoring is telling the model to run the tests it should run before and after. Tests must, of course, run in advance, and must, of course, all run again once completed. This helps the model to validate its work and ensure that it doesn't introduce new bugs when it does refactoring.

I have done a lot of rework using Claude Code, and I can say that it is almost perfect for doing the work of rework. When I used the setup I described above, I didn't encounter any problems, and there was almost always a noticeable increase in how well the coding agents were able to work in my storage environment.

Simply put: Recoding with Claude Code works very well.

The conclusion

In this article, I discussed how to recode using Claude Code. I discussed why you should care about refactoring, highlighting how it can make your scripting agents more efficient for use in a code repository. Then I covered how to know when you need to refactor and how to refactor the code, which are two of the most important points to know when it comes to refactoring.

With AI and coding agents, I believe that code refactoring is something you should simply do continuously in your code repository. Usually you have to have an agent go through your code, check if something needs to be redone, and start refactoring right away. Usually, the agent will be able to do this fully on its own, and you won't have to follow up much about it, but it's very easy to do. It's something you should keep doing to make coding agents as successful as possible in your endpoint.

👋 Touch

👉 My Free eBook and Webinar:

🚀 10x Your Engineering with LLMs (Free 3-Day Email Course)

📚 Get my free ebook Vision Language Models

💻 My webinar on Vision Language Models

👉 Find me on social media:

💌 Stack

🔗 LinkedIn

🐦 X / Twitter

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button