Try free

Last updated 13 October 2026

Set up Claude Code for a React project

Establish the project baseline with a clear environment setup

React projects often become difficult to manage because of the high number of files and complex dependencies. When you run the claude command in a fresh React repository, the agent needs to understand your specific build tools and code style immediately. You should start by ensuring your environment is clean and your local dependencies are installed using your preferred package manager. Claude Code relies on being able to execute shell commands to verify its work, so your terminal must have access to the correct node version and build paths before you start the session.

The first step is to use the /init command to create a basic configuration if one does not exist. This creates the necessary directory structure for the agent to store its own state. If you are working on a large monorepo with multiple React packages, you might need to use the /add-dir command to bring in relevant shared libraries or utility folders that sit outside your current working directory. This ensures the agent has the full context of how your components interact with global types or shared hooks.

A common point of friction is how the agent interacts with the node-modules folder. You do not need to worry about the agent trying to read every file in that directory because Claude Code respects your gitignore file by default. If your project has build artifacts or temporary files that are not ignored, you should add them to your gitignore before starting. This prevents the agent from wasting its context window on minified javascript or large map files that do not help it understand your source code.

Define component patterns and style guides in the project instructions

The CLAUDE.md file is the most important tool for keeping a React project consistent. You should place this file in your repository root and use it to document your preferred component patterns. If you use functional components with specific hook patterns, state this clearly. You should also define whether you prefer Tailwind CSS, CSS Modules, or another styling solution. When the agent uses the Edit tool to modify a component, it will refer to these instructions to ensure the new code matches your existing architecture.

Specific guidance on prop types or TypeScript interfaces belongs in this file as well. If you want the agent to always use named exports instead of default exports, or if you have a specific way of naming your test files, write those rules down. You can also include common shell commands for running your development server or your test suite. This allows the agent to use the Bash tool to verify its changes automatically after it finishes an edit. This reduces the number of times you have to manually check the browser for errors.

You might find that different parts of your React app have different requirements. For example, a shared UI library might have stricter styling rules than a dashboard page. You can place a separate CLAUDE.md file in any subdirectory to provide localized instructions. The agent will combine the instructions from the root and the subdirectory when it works on files in that part of the tree. This is useful for keeping your instructions modular and relevant to the specific code being edited.

Manage long sessions and context limits effectively

React development often involves deep file trees and many small modules. As you work, the agent uses the Read and Glob tools to explore your code, which fills the context window quickly. Every time the agent reads a large component or a complex test file, it uses up space that could be used for reasoning. You can monitor this by using the /usage or /cost commands to see how much of the context is being consumed and what the current session spend is. This helps you decide when it is time to refresh the conversation.

When the conversation becomes too long and the agent starts to lose track of recent changes, use the /compact command. This summarizes the history of the session and clears out unnecessary data while keeping the important progress you have made. If you are starting a completely new feature or a different bug fix, it is often better to use /clear to start fresh. This ensures the agent does not get confused by previous code snippets that are no longer relevant to your current task.

If you are managing multiple React features at once, adhdTerminal is the honest answer for keeping your work organized. It allows you to run many Claude Code sessions side by side as tiles on a wall. You can have one tile dedicated to a complex refactor of your state management while another tile handles small UI fixes in your component library. Each tile shows its status and the last few lines of conversation, so you can see if a build is failing or if a task is waiting for your input without switching terminal tabs constantly.

Use permission modes to speed up the development loop

The default permission mode requires you to approve every file change and shell command. In a fast paced React environment where you might be making dozens of small CSS or HTML adjustments, this can become a bottleneck. You can cycle through permission modes by pressing Shift and Tab together inside the session. Switching to the acceptEdits mode allows the agent to write files directly without asking for confirmation, which is great for repetitive styling tasks or updating many small components at once.

If you want to see what the agent intends to do before it makes any changes, the plan mode is the safest choice. In this mode, the agent will describe its intended steps but will not execute any tools until you give it permission to proceed. This is particularly useful for complex React logic changes where an accidental edit to a sensitive hook could break the entire application state. You can also configure specific tool permissions in your settings.json file if you want to always allow the Read tool but always prompt for the Bash tool.

When the agent is performing a large task, you can stop its progress at any time by pressing the Escape key. If it has made a mistake in its logic, pressing Escape twice allows you to go back to an earlier message in the conversation and try again. This undo capability is vital when working on React components where one wrong edit can lead to a cascade of linting errors. It allows you to maintain control over the codebase while still benefiting from the speed of an agent.

Automate testing and validation with bash tools

One of the biggest advantages of using Claude Code for React is its ability to run your test suite independently. You should ensure your CLAUDE.md file includes the exact command to run your tests, such as npm test or vitest. When the agent uses the Edit tool to fix a bug, you can instruct it to use the Bash tool to run the relevant tests immediately afterward. This creates a tight feedback loop where the agent can self correct if its initial fix breaks an existing test case.

You can also use the /hooks command to set up automation around specific events. For example, you can configure a hook that runs a linter after every tool use to ensure the generated code follows your project formatting rules. This prevents the agent from submitting code that will fail your continuous integration pipeline later. Using these hooks effectively turns the agent into a more disciplined developer that adheres to your project standards without being told every time.

If you encounter a bug that is hard to reproduce, use the /bug command to help the agent gather information about the issue. The agent can then use the Grep tool to search your codebase for patterns that might be causing the problem. In a React app, this is often useful for finding every instance of a specific prop or identifying where a global state variable is being modified incorrectly. The agent can then propose a fix and verify it by running the build command in the background.

Structure complex tasks with subagents and specialized commands

For very large React features, a single session can sometimes feel overwhelmed. You can define subagents in the .claude/agents directory as markdown files to handle specialized tasks. For example, you could create an agent specifically for accessibility audits or for writing unit tests for your hooks. By delegating these tasks to a subagent, the main session stays focused on the primary architecture while the subagent handles the details using its own specialized instructions.

You can also create custom slash commands by adding markdown files to the .claude/commands directory. A custom command could be designed to scaffold a new React component with all the necessary files, including the stylesheet, the test file, and the component logic. This saves time and ensures that every new file in your project follows the same structure. These commands act as templates that the agent can fill out based on your specific needs for a given component.

If you find yourself frequently switching between your editor and the terminal, use the /ide command to integrate the session more closely with your development environment. This allows the agent to better understand your current context within the IDE. For developers who prefer to stay in the terminal, the /vim command enables a familiar editing mode for making quick manual adjustments to files without leaving the Claude Code interface.

Coordinate mobile and desktop workflows with encrypted mirroring

Development does not always happen at the desk. If you use adhdTerminal on your macOS or Windows machine, you can mirror your entire wall of React coding sessions to your iPhone. The connection is secured with an end to end encrypted link, meaning your source code and conversation history remain private. This is useful when you are away from your computer but want to check if a long running build or a complex refactor has finished.

The mobile app allows you to see if a tile has moved from a working state to a waiting or idle state. You can send a quick prompt to the session or assign the next task directly from your phone. This is particularly helpful for developers who like to step away while the agent processes a large batch of component updates. You can monitor the progress of your React project from anywhere and provide guidance to the agent whenever it hits a point that requires human decision making.

Each tile in adhdTerminal remembers its position and session state. If you have to restart your computer, your React sessions will reopen exactly where they were, resuming the same conversation. This persistence is a significant advantage when working on long term React features that span several days. You never have to worry about losing the context of a complex debugging session or having to re explain your project structure to the agent.

Questions people ask

How can I prevent the agent from editing my build folders or node modules?

Claude Code automatically respects your gitignore file, so as long as your build folders and node modules are listed there, the agent will not touch them. If you need to be more specific, you can add rules to your project settings.json file to explicitly deny the Write tool for certain paths. This ensures the agent only operates on your source code.

What is the best way to handle large React state changes across multiple files?

Use the /compact command regularly to keep the conversation focused and use the plan mode to see exactly how the agent intends to modify your state logic. It is often helpful to have the agent use the Grep tool first to identify every component that consumes a specific state before it starts making edits. This prevents missing a critical update in a deeply nested component.

Can the agent help me migrate my React project to a new library or tool?

Yes, the agent is very effective at migration tasks when given clear instructions in CLAUDE.md. You should define the mapping between the old library and the new one in your project instructions. Using the acceptEdits mode can speed this up, but you should always run your test suite via the Bash tool after the agent finishes a migration to verify that the application still functions correctly.

Read next

More on claude code basics·All posts