Back to blog
·6 min read

How to Structure a Next.js 15 App with Claude Code Without Hitting Token Limits

Claude Code is powerful but token-hungry. This guide shows you how to structure a Next.js 15 project so Claude Code stays useful throughout your development session—without switching tools or waiting for limits to reset.

The Claude Code Token Problem Is Real

If you've been using Claude Code for serious Next.js development, you've hit this wall: the quality is exceptional, but the usage limits kill your flow. You start a session, Claude Code handles architectural decisions and complex file edits beautifully, and then—mid-refactor—you're capped.

The frustration is sharp because Claude Code's context management actually is superior. It understands your codebase faster and reasons through architectural problems better than other AI coding assistants. But that reasoning depth burns tokens faster. You can't use it like Codex as an always-available tool. You have to be strategic.

The answer isn't switching tools. The answer is structuring your Next.js project so Claude Code sessions are focused, bounded, and token-efficient. When your project structure matches how Claude Code actually works, you stop fighting the tool and start leveraging its strengths.

Why Next.js 15 Project Structure Matters Now

Next.js 15 changed fundamentals that most older structure guides ignore. The App Router is now default. React Server Components handle data fetching. Server Actions replaced API route mutations. Turbopack changed how you think about local dev performance.

This isn't pedantic. These changes directly affect how efficiently Claude Code can help you.

When your project structure respects these patterns, Claude Code needs less context to understand your app. Fewer files to read. Clearer boundaries between server and client logic. Smaller semantic chunks to reason about. That means the same token budget goes further, and you stay productive longer.

The developers who stay in Claude Code sessions the longest aren't the ones prompting better. They're the ones whose projects are structured so Claude Code encounters smaller, self-contained problems.

The Token-Efficient Next.js 15 Structure Pattern

Here's the structure that works:

```

my-app/

├── app/

│ ├── layout.tsx (root layout, metadata)

│ ├── page.tsx (home page)

│ ├── (auth)/

│ │ ├── login/page.tsx

│ │ ├── signup/page.tsx

│ │ └── layout.tsx (auth layout wrapper)

│ ├── (dashboard)/

│ │ ├── dashboard/page.tsx

│ │ ├── projects/page.tsx

│ │ ├── projects/[id]/page.tsx

│ │ └── layout.tsx (dashboard layout wrapper)

│ └── api/

│ └── (only for webhooks or external integrations)

├── lib/

│ ├── db.ts (database client, Supabase)

│ ├── auth.ts (auth utilities)

│ ├── server-actions/ (Server Actions only)

│ │ ├── projects.ts

│ │ └── users.ts

│ └── utils.ts (shared helpers)

├── components/

│ ├── ui/ (reusable UI, client-only)

│ ├── forms/ (form wrappers, mostly client)

│ └── shared/ (shared components)

├── hooks/

│ ├── useUser.ts

│ └── useProjects.ts

├── types/

│ └── index.ts (all TypeScript types)

└── env.ts (environment validation)

```

Three principles drive this:

  • Nest routes by feature, not by HTTP method. The (auth) and (dashboard) groups are feature domains. Claude Code understands "implement the auth feature" better than "implement these 5 API routes."
  • Keep Server Actions in lib/server-actions/, not scattered in route handlers. Claude Code can review all mutation patterns in one place and maintain consistency.
  • Never put business logic in route handlers. Route handlers should be thin wrappers around Server Actions. This boundary is critical because Claude Code can focus on the logic once, then reuse it everywhere.
  • How This Reduces Token Burn

    When Claude Code works on a feature, it now encounters:

  • One route file (the page.tsx or layout.tsx)
  • One or two components (the UI)
  • One Server Action file (the mutation logic)
  • Shared types and utilities
  • That's maybe 200-300 lines of context per feature. Claude Code can reason through the entire feature, suggest improvements, and even implement new ones without needing to re-read your whole project.

    Compare that to a project without structure: Claude Code has to parse route handlers, API files, middleware, utility functions scattered across folders, and unclear patterns. It burns tokens just understanding what you built.

    The token savings compound. First feature costs 20k tokens. Second similar feature costs 8k (Claude Code recognizes the pattern). By the tenth feature, you're at 3k per feature. A well-structured project lets Claude Code amortize its context investment.

    Server Actions: The Token-Efficient Mutation Pattern

    This deserves emphasis because it's where most developers leak tokens.

    In older Next.js, you'd create API routes for mutations:

    ```

    api/

    ├── projects/route.ts (POST for create, PUT for update)

    ├── projects/[id]/route.ts

    ├── projects/[id]/delete/route.ts

    ```

    Claude Code has to understand routing conventions, HTTP method handling, error patterns—and you repeat it for every endpoint.

    Server Actions collapse this:

    ```

    lib/server-actions/projects.ts:

    'use server'

    export async function createProject(name: string) {

    // Validate

    // Call DB

    // Return result

    }

    export async function updateProject(id: string, name: string) {

    // Validate

    // Call DB

    // Return result

    }

    ```

    Then call them from components:

    ```

    'use client'

    import { createProject } from '@/lib/server-actions/projects'

    export function NewProjectForm() {

    async function handleSubmit(formData) {

    const result = await createProject(formData.get('name'))

    }

    // ...

    }

    ```

    Claude Code sees the pattern once, applies it everywhere. No routing layer to parse. No HTTP method handling. Just: input → validation → database → result. Token efficiency skyrockets.

    Pair This Structure with Focused Claude Code Sessions

    Token limits become manageable when sessions are scoped:

  • Session 1: "Implement the auth feature. Create login, signup, forgot password flows."
  • Session 2: "Implement the projects CRUD. Create, read, update, delete with proper permissions."
  • Session 3: "Build the dashboard layout and data visualization."
  • Each session stays in one feature domain. Claude Code doesn't need to load your entire app. You're not fighting context limits. And you can return to Claude Code multiple times throughout the day because you're not expecting unlimited usage—you're expecting focused, high-value sessions that solve specific architectural pieces.

    Where ZipBuild Fits

    If you're starting a new Next.js 15 app and want this structure baked in from day one, that's exactly what ZipBuild generates. Instead of building the folder structure, types, auth patterns, and database integration manually, you get a production-ready scaffold that already respects these token-efficient patterns.

    More importantly, when you onboard Claude Code, you're not explaining your project structure—it already follows conventions Claude Code expects. Your first session is solving problems, not establishing patterns.

    Implementation Checklist

  • Use route groups (auth), (dashboard)) to organize features
  • Keep all Server Actions in lib/server-actions/ with consistent naming
  • Never put business logic in route handlers or middleware
  • Store all types in types/index.ts for single source of truth
  • Validate environment variables at app start with a lib/env.ts file
  • Write one feature per Claude Code session
  • Keep session scope to roughly 2-4 files when asking for implementations
  • Structure isn't glamorous, but it's the difference between Claude Code being unusable and being your best developer tool.

    Try the free discovery chat at zipbuild.dev to see how a properly scaffolded codebase accelerates development.

    Written by ZipBuild Team

    Ready to build with structure?

    Try the free discovery chat and see how ZipBuild architects your idea.

    Start Building