By Connect Digital World | Web Development Made Easy
Imagine you get a new helper at school. This helper is very fast and very smart, but it has never seen your classroom before. If you say, “Fix the mess,” it might clean the wrong desk, throw away your homework, or tidy a corner you did not want touched.
That is how an AI coding agent acts inside a real project when you give it no instructions. In this guide, you will learn how to use AI coding agents in real React projects the safe and smart way. We explain every step in simple words, with small examples you can copy.
Quick Summary: 8 Rules to Remember
- Give the agent a small, clear job.
- Write an AGENTS.md file so it knows your rules.
- Always work on a separate Git branch.
- Ask for a plan before any code.
- Make the agent run your tests.
- Read every change before you accept it.
- Never share secrets like passwords.
- Learn from what the agent writes, don’t just copy it.
What Is an AI Coding Agent?
You may already know AI chat tools. You ask a question, and they give an answer. An AI coding agent goes further. It can look inside your project, open files, write code, run commands and fix errors, almost like a junior teammate.
Tools such as Cursor, Claude Code, GitHub Copilot’s agent mode, Google Antigravity and others work like this. They are different products, but the safe habits you learn here work with all of them.
What Is React? (Quick Reminder)
React is a popular tool for building websites and apps. You build a page out of small pieces called components, a bit like building with LEGO bricks. A button can be one brick, a menu another, and a card another. Put them together and you have a full page.
Why Real Projects Are Different From Practice Projects
In a tiny practice app, an AI agent usually does fine. A real project is bigger and messier. It has many files, special rules, old code, other people’s work and customers who depend on it.
The agent does not automatically know:
- How your team names things.
- Which state tool you chose.
- Which command runs your tests.
- Which files are too important to change.
Without that knowledge, the agent guesses. Sometimes the guess is great. Sometimes it quietly breaks something. The steps below remove most of that guessing.
Step 1: Get Your Project Ready
Use Git Before Anything Else
Git is a tool that saves versions of your project, like save points in a video game. If the AI makes a mess, you can go back.
Before every AI task, make a new branch. A branch is a safe copy where you can experiment:
git checkout -b feature/add-search-box
Now, whatever the agent does, your main code stays untouched.
Make Sure the Project Runs
Check that your app starts and your tests pass before the agent touches anything. If the project is already broken, you will not know whether the agent caused a problem or it was there already.
Step 2: Write an AGENTS.md File
AGENTS.md is a plain text file, written in Markdown, that you place in the main folder of your project. Think of it as a welcome note for your robot helper. It tells the agent how to work in your project. AGENTS.md is an open format that many coding agents understand, and some tools, like Claude Code, also use a file called CLAUDE.md for the same job.
Your README is written for people. AGENTS.md is written for the agent, with exact commands and rules. Here is a simple example for a React project:
# Project Guidelines
## Commands
- `npm run dev` - start the app
- `npm test` - run the tests
- `npm run lint` - check code style
- `npm run build` - make the final version
## Tech stack
- React with TypeScript
- Vite for building
- Vitest and React Testing Library for tests
## Rules
- Use function components and hooks, not class components.
- Keep each component small, under about 150 lines.
- Put reusable components in `src/components/`.
- Write a test for every new component.
- Do not edit files in `.github/workflows/`.
- Do not add new packages without asking first.
## Before you finish
- All tests pass.
- Lint shows no errors.
Tips for a Good AGENTS.md
- Start with commands. Agents work best when they know how to run and test the project.
- Be specific. “Use Vitest” is better than “write good tests.”
- List things not to touch. This protects important files.
- Keep it short. A long file full of opinions is easy to ignore. Write only what the agent really needs.
- Update it. Whenever the agent makes the same mistake twice, add a rule.
Step 3: Give Small, Clear Tasks
This is the most important habit. A big, vague job leads to big, messy results. A small, clear job leads to code you can check in minutes.
A Bad Prompt
Make my app better.
A Good Prompt
Add a search box above the product list in src/components/ProductList.tsx.
It should filter products by name as the user types.
Use a controlled input and React hooks.
Add a test that checks the filtering works.
Do not change any other files.
See the difference? The good prompt says what to build, where to build it, how it should work, how to test it and what not to touch.
A Handy Prompt Recipe
- Goal: What should be different when finished?
- Place: Which files or folders?
- Rules: Any style or tools to use?
- Proof: How will we know it works?
- Limits: What must stay the same?
Step 4: Ask for a Plan First
Before the agent writes any code, ask it to explain what it will do:
Before writing code, list the files you will change
and explain your plan in simple steps. Wait for my approval.
This is like asking a builder to show you the drawing before cutting the wood. If the plan looks wrong, you can fix it in seconds. Fixing a wrong plan is much easier than untangling wrong code.
Step 5: Let Tests Be the Referee
Tests are small programs that check whether your code works. They are the best way to catch mistakes from an AI agent, because they do not care who wrote the code.
Here is a tiny React component and a test for it:
// src/components/Counter.tsx
import { useState } from "react";
export default function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Add</button>
</div>
);
}
// src/components/Counter.test.tsx
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import Counter from "./Counter";
test("adds one when the button is clicked", async () => {
render(<Counter />);
await userEvent.click(screen.getByText("Add"));
expect(screen.getByText("Count: 1")).toBeInTheDocument();
});
A great trick is to tell the agent: “Write the test first, then write the code until the test passes.” This keeps the agent honest, and you can see right away if the job is done.
Step 6: Read Every Change
This step is not optional. AI-written code often looks right even when it is wrong. Treat the agent like a new teammate whose work always needs a review.
What to Look For
- Changes you did not ask for. Did it edit extra files?
- New packages. Did it add something you do not need?
- Deleted code. Did something useful disappear?
- Fake or unsafe shortcuts. Did it hide an error instead of fixing it?
- Messy hooks. Look for missing dependencies in
useEffector state that is updated in the wrong place.
Use git diff to see exactly what changed:
git diff
If you do not understand a part, ask the agent: “Explain this code to me like I am ten years old.” That is a very good way to learn.
Step 7: Keep Secrets Safe
Agents can read files and run commands, so be careful about what they can reach.
- Never paste passwords, API keys or private tokens into a prompt.
- Keep secrets in a
.envfile and make sure that file is in.gitignore. - Be careful before letting an agent run commands you do not understand, especially ones that delete files or install things.
- Check the privacy settings of your tool if you work with a client’s private code.
- Be suspicious of any new package the agent suggests. Check that it is real and popular before installing it.
Step 8: Pick the Right Jobs for the Agent
Agents are brilliant at some tasks and weak at others.
Great Jobs for AI Agents
- Writing small components, like a card, a form or a button.
- Adding tests to code that has none.
- Fixing clear bugs when you can describe the problem.
- Renaming things and tidying repeated code.
- Explaining confusing old code.
- Converting JavaScript files to TypeScript, one file at a time.
- Writing documentation and comments.
Jobs That Need Extra Care
- Big changes to how the whole app is built.
- Login, payments and anything involving money or private data.
- Database changes.
- Anything you do not understand yourself.
For the careful jobs, the agent can still help, but you must review much more closely, or ask a more experienced developer to look.
A Real Example: Fixing a Bug Step by Step
Let us say your React app has a problem. When someone types in a search box, the page shows the wrong results. Here is how a smart developer would work with an agent.
- Create a branch:
git checkout -b fix/search-bug - Describe the bug clearly: “When I type ‘shoe’ in the search box, products with ‘shoes’ disappear. It should match partial words. The code is in ProductList.tsx.”
- Ask for a plan: The agent says it will make the filter ignore capital letters and match part of a word.
- Ask for a test first: The agent writes a test that fails today.
- Let it fix the code: The agent changes the filter and runs the tests.
- Review the diff: You see only a few lines changed.
- Run the app yourself: Try it in the browser.
- Commit: Save your work with a clear message.
The whole thing might take ten minutes, and you stayed in control from start to finish.
Common Mistakes to Avoid
- Asking for too much at once. Split big goals into small steps.
- Trusting without testing. “It looks fine” is not proof.
- Skipping Git. Without save points, one bad change can ruin hours of work.
- Letting the agent install anything. Extra packages can add bugs or security risks.
- Never updating AGENTS.md. Add a rule each time the agent repeats a mistake.
- Stopping learning. If you never read the code, you will not grow as a developer.
- Working in one giant chat. Long, messy conversations make agents forget details. Start fresh for new tasks.
Tips for Teams
If you work with other people, a few extra habits help everyone:
- Keep AGENTS.md in the repository so everyone, and every agent, follows the same rules.
- Mark AI-assisted work in your pull request notes, so reviewers know to look closely.
- Run tests and linting automatically in your CI pipeline, so mistakes get caught before they reach customers.
- Agree as a team about what agents are allowed to touch.
Simple Word List (Glossary)
- AI coding agent: An AI helper that can read your project, write code and run commands.
- React: A tool for building websites and apps from small pieces.
- Component: One small piece of a React page, like a button.
- Hook: A special React function, such as useState, that lets components remember things.
- Git: A tool that saves versions of your project.
- Branch: A safe copy of your project for trying new things.
- Test: A small program that checks your code works.
- Diff: A view that shows exactly what changed.
- AGENTS.md: A note that tells AI agents how to work in your project.
- Linting: An automatic check for messy or risky code.
Frequently Asked Questions (FAQ)
Can AI coding agents build a whole React app by themselves?
They can build a lot, but real projects still need a human to decide what to build, check the results and keep things safe. Treat the agent as a helper, not a replacement.
What is AGENTS.md and do I really need it?
It is a file that tells AI agents your commands, tools and rules. You do not strictly need it, but it saves a lot of mistakes and repeated explanations.
Which AI coding tool is best for React?
Several work well, including Cursor, Claude Code, GitHub Copilot and Google Antigravity. The habits in this guide work with all of them, so pick the one you enjoy most.
Is it safe to use AI agents on private company code?
It depends on the tool and its settings. Read the privacy terms, follow your company’s rules and never share secrets like passwords or keys.
How do I stop the agent from changing too many files?
Give a small task, name the exact files, and add a line such as “do not change any other files.” Then check git diff.
Should beginners use AI coding agents?
Yes, as a learning partner. Ask it to explain its code and try small changes yourself, so you actually learn React.
Do AI agents replace developers?
They make developers faster, but people are still needed to plan, review, test and make good decisions.
Final Thoughts
Using AI coding agents in real React projects is not about pressing a magic button. It is about teamwork. Give the agent a clear welcome note in AGENTS.md, hand it small jobs, let tests act as the referee and always read what it wrote.
Do that, and you will get the speed of AI without losing control of your project. Start small today: create a branch, write a short AGENTS.md and try one tiny task. You will be surprised how quickly you improve.
Which AI coding tool are you using with React? Tell us in the comments. For more easy tech guides, keep following Connect Digital World.
Sources and further reading: AGENTS.md documentation and community guides, plus public best-practice notes for React and AI coding tools. Tools and features change often, so check each tool’s official documentation.

