Lesson

Working with Code (Basics)

You’ve probably seen the demos of AI building entire snake games in 30 seconds. It looks like magic. But when you try it yourself on your actual company codebase, it usually spits out something that doesn't compile.

Why? Because generating a standalone, isolated script (like a snake game) is easy. Modifying an existing, complex system is hard.

Start Small

When you are first using Claude for code, don't ask it to build a full application. Ask it to build small, isolated functions.

Good Prompt:

"Write a TypeScript function that takes a date string and returns 'X days ago'. Handle edge cases like future dates (return 'In the future') and invalid formats."

Claude will nail this perfectly, provide the types, and likely write some basic unit tests for it if you ask. You can then copy-paste this function safely into your codebase.

The 'Refactor' Prompt

One of my favorite uses for Claude is cleaning up ugly code. We all write spaghetti code when we're rushing to meet a deadline.

Prompt:

"I wrote this function in a rush. It works, but it's nested too deeply (callback hell) and the variable names are terrible. Refactor it to use modern async/await, flatten the logic, and use more descriptive variable names."

// your ugly code here

Claude won't just clean it up; it will usually explain why the new version is better.

Explaining Weird Code

Sometimes you inherit a codebase written by a developer who loved using obscure one-liners. If you stare at a line of code and have no idea what it does, just ask.

Prompt:

"What exactly is this line of code doing? Break it down step-by-step." const result = arr.reduce((acc, val) => (acc[val] = (acc[val] || 0) + 1, acc), {});

Claude will explain that it's counting the frequency of elements in an array and will likely offer a much more readable alternative.

Treat Claude as a pair programmer. You are the architect making the big decisions; Claude is the fast typist who knows all the syntax.

Ready to test your understanding? Take the quiz to reinforce what you learned.

© 2026 Ant Skillsv.26.07.07-23:01