# Coding with AI - Tips

By [Ninad Naik](https://paragraph.com/@ninad-naik) · 2024-09-05

---

Last week, I talked about our experience at [@Mira\_Network](https://x.com/Mira_Network) with coding with [Claude](https://claude.ai/) and other programming tools, and several of you asked me for tips on using Claude more effectively. Here are a few approaches that have worked well for me. 👇🏽

Ask the model to propose a detailed plan before proceeding. Specifically, ask it to explain why the code (new or edits) is necessary, why it won’t cause regression to existing functionality, and to list all assumptions. This helps prevent the model from building on incorrect assumptions and helps you reduce the probability space of errors.

Remind it to constantly check its proposals against the Project Knowledge and to validate that the code it’s proposing won’t cause regressions. Keep Project Knowledge updated with the latest version of all files to ensure the model knows the current state of the program. This is less of an issue with [@cursor\_ai](https://x.com/cursor_ai) and such, but still worth keeping in mind.

To help maintain state on the program, create a plan.md file and a structure.md file. plan.md should contain a detailed plan for the program (as much as you can foresee) -- I co-develop this plan with the LLM. Ideally, this is a mix of functionality and hygiene. structure.md captures the file structure. Keep these updated in Project Knowledge and routinely remind the model to refer to these files.

Modularize early and often. Break the program into individual modules with clean interfaces. This helps minimize context length and ensures that regressions and bugs are easier to isolate and remedy.

Regularly ask the model to critique the code, and reflect on what’s going well and what isn’t. This helps identify and correct issues faster.

Always ask for the full code of the method that needs to change, rather than just delta snippets, to reduce the risk of unnecessary regressions from copy-paste errors (less of an issue with @cursor\_ai). This eats up more context and you'll run out of the chats faster, but it will save you a LOT of time debugging later.

When fixing bugs, ask the model for its hypothesis and what additional information it needs to validate the hypothesis. Ask whether it needs to clarify anything and help it acquire that information. Often, the model will proceed with incomplete information and take you down the wrong path so your number one job is to help it eliminate bad paths.

Focus on building a stable program rather than passing test cases. Sometimes the model might pass a test case but introduce regressions in the process. You must actively remind it that passing a test case is not the ultimate goal (unless that is the case for you). AI will always chase some objective function -- you have to define the objective function.

Frequently update doc strings and documentation, even though this can be tedious. It is crucial for maintaining clarity. Speaking of documentation, it is helpful to maintain a robust README file; this helps you and the model get grounded on the program faster. Alternatively, instruct the model to add documentation every time.

    Include documentation such as doc strings. 
    

A simple heuristic that has worked well for me is to compare the length of the updated file with the length of the previous version of the line. \*Usually\* if the file's length changes by more than 5-7 lines, it is because the model inadvertently removed a method or some functionality. Here’s the specific instruction that works for me; it results in the model comparing file length and explaining why the the length differs; resulting in fewer regressions.

    After writing the code, do a check on file length (lines) and compare it to the current length of the file in Project Knowledge. If the file length varies by more than 5 lines, then check to make sure that you have not caused a regression.
    

Lastly, regularly back up your code. LLMs can build on top of mistakes, so having the ability to revert to previous versions is essential.

Happy coding!

---

*Originally published on [Ninad Naik](https://paragraph.com/@ninad-naik/coding-with-ai-tips)*
