Bulk Fixing AI-Generated Code Errors with Reasoning Models and Cursor Composer

AI-generated code often comes riddled with errors, especially TypeScript errors. Trying to fix these one by one with in-editor AI tools (like Cursor's "Fix with AI") can be slow, frustrating, and sometimes even introduce new problems. The fixes can be too localized, missing the bigger picture.

This lesson demonstrates a more efficient workflow: leveraging the power of reasoning models (like those found in AI Studio or advanced ChatGPT models) to fix errors in bulk.

Here's the process:

  1. Identify All Errors: Use the "Problems" panel in your editor to get a comprehensive list of all errors in the file. Don't try to fix them individually yet! (Use Cmd/Ctrl + Shift + P, then type "problems".)
  2. Gather Context:
    • Copy the entire file's code.
    • Copy the entire list of errors from the Problems panel.
  3. Prompt the Reasoning Model: Paste both the code and the error list into a reasoning model. Your prompt should be something like: "Please fix all of these errors and rewrite the entire file with the corrections." The key is to give the AI the full context. Wrap your code with XML tags to help the AI recognize it.
  4. Iterate (if needed): Copy the corrected code back into your editor. If a few errors remain, now it's time to use in-editor AI tools (like Cursor's Composer or "Fix with AI") for the final cleanup. These tools are better suited for small, isolated issues.
  5. Provide Additional Context (for Stubborn Errors): If a specific error persists (e.g., related to a library like yargs), provide even more context to the AI:
    • Include links to the library's documentation (NPM page, official docs).
    • Use Cursor's @ feature to add specific files or documentation to the context.
  6. Make sure to test! Run npm test or whichever testing command you're using for this project.

Why this works:

  • Holistic Understanding: Reasoning models excel at understanding the relationships between different parts of the code. They can see how a change in one place affects others, leading to more consistent and correct fixes.
  • Efficiency: Fixing multiple errors in a single pass is much faster than addressing them individually.
  • Reduced "Whack-a-Mole": Fixing one error often reveals another. Bulk fixing with a reasoning model minimizes this frustrating cycle.

This lesson teaches you a practical, powerful technique to tame AI-generated code and get it working quickly, even when it arrives full of errors. By combining the strengths of reasoning models and in-editor AI, you'll become a more efficient and confident developer.

Share with a coworker

Transcript

[00:00] When you get some AI generated code and you see a lot of red on your sidebar and it looks like there's a ton of TypeScript issues or whatever kind of issues, if you hit Command-Shift-P and type in problems, you can focus on the list of all the problems in the file. So this has a whole bunch of TypeScript issues. Now in a lot of cases you can right-click on these and say fix with AI, fix with AI, and go one by one and attempt to let cursor fix them as kind of standalone issues. My personal workflow is to grab the entire file to drop it into the smartest AI you have access to. I use O3 MiniHi all the time so I'll paste in this file and then just as a habit I always wrap sections with XML tags.

[00:43] I'll swap back over to cursor, hit command-a, select all of these and copy and swap back and paste and then end the problem section and then just say please fix all of these problems and write out the entire file with the problems fixed. You can say that however you want. Then we'll submit this and let it go to work so that essentially everything is done in a single pass. So this actually took quite a while, two minutes, but from my experience I have a lot more trust in reasoning models than I do in one-shot fixes inside of Cursor. So we can go ahead and take this entire file, It's almost done actually generating the text of it.

[01:17] So we can go ahead and copy the result, click copy, switch back, select all, paste, and you'll see we have a few more errors. We'll just select all, copy, swap back, paste it in, and since this looks like they're all just on like line 68, 498, 541. We'll just say there are a few errors remaining, just give me the minimal code snippets that I can copy paste in to fix these. And then once this is done I'll copy the result, swap back over. I'm actually going to ask Composer to fix this, so I'll drop that in.

[01:46] Please apply the fixes we made above, hit enter here, and then just let it go to work. Again with the end goal of just me being as lazy as possible. We'll accept the changes. We only have a couple left. I'll just try right-clicking and fix with AI on these.

[01:59] We'll accept, fix with AI. Looks like that's still not fixed. We'll try it again. I doubt we'll have to go to a reasoning model for this, but that definitely introduced a lot of issues. Let's skip this one for a second and fix this with AI.

[02:15] Except Let's try copying both of these in, creating a new session, and see if Claude can do this. Please fix these issues. And because this seems to be YARG-specific, I'm going to grab in the YARG's URL from npm and paste this in. And there's even a YARGS docs and I'll just go ahead and add that to docs while I'm here. So I'll say docs add new, paste the link, hit enter, call it YARGS, confirm, and then now we have yargs or yargs or however you say it and maybe now this will help it out.

[02:52] So let this do its work. Let's go ahead and accept. Let's add this line to Composer and right-click copy the message, paste it in, please fix. Hopefully this should take care of it. We'll hit accept here and now the only thing to do is to pray that our tests still pass.

[03:09] And it looks like I do have one test that failed around the text used to help the user when they look to see how to use it. So we can go ahead and select all of this and say add to composer. You broke this test, please fix it. And then it's just the usage string. Looks up the changes and then I imagine we're good to go now.

[03:27] So with everything passing at this point I would still take this entire file, drop it in a reasoning model, see what sort of types it could extract. This file is definitely getting to the size where I need to start pulling out functions, pulling out types, and making this more than just a single file utility. But for now I cleared out all of the TypeScript issues without ever really having to think about TypeScript.