gen-aiclaude-codeanthropictutorialreact

Claude Code in Action: Building a Next.js App from Scratch Entirely in the Terminal

Wed Apr 22 2026

Anthropic’s Claude Code is dramatically changing how software is built. By integrating the Claude 3.5 Sonnet reasoning engine directly into your terminal, it completely eliminates the tedious copy-pasting cycle of traditional web chat UIs. It reads your local files, executes your CLI tools securely, and writes code straight into your repository.

While many overviews touch on basic file editing, we’re going to dive into a real-world, end-to-end practical scenario. We will use Claude Code to autonomously scaffold a brand-new Next.js web application, implement complex React state management, and style it beautifully with Tailwind CSS—acting as a true highly-skilled pair programmer.


Phase 1: Bootstrapping the Project

Instead of running the boilerplate commands ourselves, let’s let Claude Code do the heavy lifting from an empty directory.

Create a blank folder and start the agent:

mkdir weather-dashboard && cd weather-dashboard
claude

You are now inside the interactive agent shell. Let’s command it to build the foundation of our app.

Command:

> Initialize a new Next.js project in this directory using TypeScript, Tailwind CSS, and the App Router. Use `npx create-next-app@latest .` and pass all necessary flags to complete it autonomously without interactive prompts.

The Tool Calling Process

Claude Code immediately maps out the plan. It recognizes it needs shell access to run NPX commands.

  1. It proposes the bash command: npx create-next-app@latest . --ts --tailwind --eslint --app --src-dir --import-alias "@/*"
  2. It prompts you (the human) for permission to execute this shell command.
  3. You hit y for yes.

Within seconds, you have a fully functional Next.js environment ready to go.


Phase 2: Generating Complex React Components

Now that our framework is set up, let’s build the actual application: a dynamic Weather Dashboard that fetches mock API data and manages state using custom React hooks.

Instead of writing step-by-step logic, we provide Claude with architectural constraints.

Command:

> We need to build a Weather Dashboard. 
> 1. Create a custom hook `useWeather.ts` that manages loading, error, and weather data state for a given city.
> 2. Implement a `WeatherCard.tsx` component to display the temperature, humidity, and an appropriate weather icon.
> 3. Update the main `page.tsx` file to feature a modern, Tailwind-styled search bar that lets users type in a city and renders the `WeatherCard`. 
> 4. Ensure it is fully responsive on mobile screens.

Claude gets to work reading your project structure, deciding where to put files, and writing the code:

  1. Create /src/hooks/useWeather.ts (Implements useState and simulated setTimeout fetch logic).
  2. Create /src/components/WeatherCard.tsx (Builds out a sleek, glass-morphism designed card using Tailwind utility classes).
  3. Edit /src/app/page.tsx (Integrates the hook and standardizes the layout layout).

Right inside the terminal, you’ve just engineered a full-stack feature block without writing a single line of TypeScript manually.


Phase 3: The Autonomous Debugging Loop

Inevitably in modern web development, things break. Perhaps Claude generated a useState hook inside a server component (a very common Next.js App Router error!).

We can force the AI into a closed execution loop by having it read its own errors.

Command:

> Run the development server with `npm run build`. If there are any build errors or Next.js hydration issues, intercept the stack trace, modify the source code to fix the root cause, and re-run the build until it completes successfully.

What happens here?

  1. Claude executes the shell command npm run build.
  2. It encounters an error output: Error: Event handlers cannot be passed to Client Component props... or useState only works in Client Components.
  3. Claude parses the terminal output automatically.
  4. It realizes it forgot to add the "use client"; directive at the top of the WeatherCard.tsx file.
  5. It edits the file to inject the missing directive.
  6. It automatically runs npm run build again.
  7. The build succeeds perfectly!

The agent effectively acts as its own QA engineer, identifying React-specific rendering issues and patching them instantly.


Best Practices for Frontend Teams

When utilizing Claude Code for frontend architecture and web apps:

  1. Keep Component Focus: Instead of asking Claude to “Build a whole Dashboard,” isolate requests to specific component boundaries. Create the UI library first, then wire the state.
  2. Context Compression: Use the /compact command after long coding sessions. Generating thousands of lines of React code can bloat the context window and slow down response times.
  3. Use UI Libraries: You can instruct Claude to install and utilize external libraries seamlessly. For instance: “Install framer-motion and add a smooth fade-up animation to the WeatherCard.” It will handle the NPM install and write the animation logic simultaneously.

Conclusion

Browser-based AI chat tools require you to be the “middleman” moving files between your IDE and the LLM. Claude Code eliminates this entirely. By bridging top-tier reasoning capabilities directly into your filesystem and build tools, you can rapidly iterate, prototype, and build complex web applications faster than ever before.