OmniscioGuidesCLAUDE.md examplesTypeScript and Next.js
CLAUDE.md for TypeScript and Next.js
In a Next.js app the folder tree defines the routes, so a layout question and a URL question are usually the same question. The few exceptions are exactly the kind of thing a session gets wrong when it has only the code in front of it.
The file below writes the boundary down once: what renders on the server, what is allowed to run in the browser, and what a change to either costs. Each block is explained underneath, with the lines that were deliberately left out.
- The file, ready to copy.
- Why each block is there.
- What was left out, and why.
- Adapting it to a plain React or Vue app.
Checked against Anthropic's Claude Code documentation and the frameworks' own docs on November 25, 2026. By the Omniscio team. Updated .
The file
This one describes a site with public marketing pages and a signed-in dashboard, built on the App Router under src/app. Save it as ./CLAUDE.md or ./.claude/CLAUDE.md in the repository root.
# web Next.js App Router site: marketing pages and the signed-in dashboard. TypeScript in strict mode, pnpm. ## Commands pnpm install pnpm dev # http://localhost:3000 pnpm build pnpm test # vitest pnpm typecheck # tsc --noEmit pnpm lint # eslint ## Layout - src/app/ App Router. A folder is a URL segment; page.tsx makes a route public. - src/app/(dashboard)/ route group: shares a layout, adds no URL segment - src/components/ui/ design-system primitives; no data fetching - src/server/ data access; a server-only module, never imported by a client - src/lib/ small helpers with no side effects ## Rules - Server Components by default. Add "use client" only for state, effects, a browser API or a custom hook, and put it on the smallest leaf that needs it. - strict is on in tsconfig. No any, no @ts-ignore, no non-null assertion to silence a type error. Use unknown plus a type guard. - Data is fetched in src/server/ and passed down as props. Client-side fetching is the exception, and it needs a reason in the pull request. - Route handlers in src/app/**/route.ts serve webhooks and outside clients, and return Response.json(...), never a bare object. - Only NEXT_PUBLIC_ values reach the browser. A secret never goes in one; it stays in a server-only module. - Tailwind utility classes only. No CSS modules, and no inline style except a CSS variable. - Every exported component has a named props type, not an inline object. ## Testing - vitest for units, and the setup file in tests/setup.ts for anything touching fetch. - Test a component through the DOM, not through its internal state. - A bug fix starts with a test that fails before the fix. ## Traps - src/app/ is a router. Moving a file changes a URL, and renaming a folder breaks every link to it. - Every module under src/server/ starts with import 'server-only', so a client component that reaches for one fails the build instead of bundling secrets. - A "use client" file cannot import a server-only module. If it needs data, the data should arrive as a prop. - Never edit .next/ by hand, and never commit it. - Render anything that depends on the clock or a timezone from a fixed value. A value computed on the server and again in the browser disagrees on the first paint, and React reports a hydration mismatch.
That is 56 lines. Most of its rules are stated concretely enough to check in review, which is the shape Anthropic asks for.
Why each block is there
The title line
One line states the framework and the strict-mode setting, because both change what a correct diff looks like. A session that does not know the project is in strict mode writes code that compiles in its head and fails your type check.
The command block
Six commands, each one runnable from the project root. Typecheck is separate from build because it answers in seconds what a full build answers in minutes, and a session asked to "make sure it works" will run the cheapest command it can find unless the file names the one that matters.
The layout
In the App Router the folders are the URLs. Next.js's own documentation puts it plainly: folders define URL segments, nesting folders nests segments, and a route becomes public when a page or route file exists. That sentence is why the layout block here is shorter than in a Python project: the framework already explains the tree, and only the exceptions need writing down.
The (dashboard) line is one of those exceptions. A folder in parentheses groups routes under a shared layout without adding a segment, which is invisible from the name and surprising the first time somebody moves a page into it.
The rules
The first rule is the one this file exists for. Next.js documents that layouts and pages are Server Components by default, and lists the four things that justify a Client Component: state and event handlers, lifecycle logic, browser-only APIs, and custom hooks. Written as a rule, it stops the drift where a page becomes client-side because one button needed a click handler.
The strictness line names the escapes rather than the philosophy. TypeScript's documentation says the strict flag turns on a wide range of type checking that gives stronger guarantees of program correctness, and any, @ts-ignore and a non-null assertion each undo part of that locally. Naming the three is what makes the rule checkable in review.
"Data arrives as props" is the second half of the same boundary. Next.js documents using Server Components to fetch close to the source and passing the result down, so in this codebase a fetching client component is the exception the file routes around.
Testing
"Test through the DOM, not internal state" is concrete in the way Anthropic asks for. It rules out the test that asserts a component's private variable, which passes after a refactor and proves nothing to a reviewer.
Traps
The first trap follows directly from the router rule and is the most expensive mistake on the list: a tidy-minded rename silently changes a public URL. One sentence in a file Claude reads every session is cheaper than that.
The hydration line is the one people add only after they have debugged it once. A value computed during the first render runs on the server and again in the browser, and the two disagree the moment either the clock or the timezone differs.
The import 'server-only' line makes the folder boundary real. Next.js documents that a module can be shared by server and client components, so an accidental import is possible; the package turns that accident into a build-time error rather than a secret in the bundle.
What was left out, and why
- A rule that only matters in one folder. That belongs in a path-scoped rule under
.claude/rules/, which loads only when Claude touches a matching file. - The tsconfig itself. The compiler already enforces it, and a copy of the flags in prose goes stale the first time somebody changes one.
- The component library's API. It is discoverable in
src/components/ui, and a list of props in a CLAUDE.md is the kind of thing Claude can read faster than you can maintain it. - The deploy pipeline. A multi-step procedure belongs in a skill, not in context on every session.
- Personal preview URLs and test accounts. Those go in
CLAUDE.local.md, which is not committed. - "Write accessible, semantic HTML." If it matters, it is an ESLint rule or a review checklist; as a sentence in this file it is ignored.
Adapting it
- Plain React with Vite. Delete the Server Component rule, the route-handler rule and the
src/applayout lines, and replace the layout with yoursrc/tree. Keep the strictness rules, the props rule and the testing block. - The Pages Router. Replace the App Router layout with
pages/, and swap the server-component rule for whatever data-fetching convention your app uses. - Vue or Nuxt. The framework names change, the shape does not: commands, layout, the rules a reviewer enforces, the traps. What a CLAUDE.md is for does not change between frameworks.
Then prove it loaded. /context all lists the memory files read at launch, and a file that is missing from that list is not being ignored; it is not being seen.
How this page was written
The guidance on what belongs in a CLAUDE.md, how long it should be and how Claude treats it was read from Anthropic's Claude Code memory documentation on November 25, 2026. The statements about Next.js, the App Router and TypeScript were read from each project's own documentation the same day, and every claim about them is quoted from those pages.
The example file was written for this page and was not run against a live repository. Every line is meant to be checked against your own project before it is kept, which is why the adaptation steps below are worth working through before you keep it.
Sources
- Anthropic's How Claude remembers your project, for what belongs in a CLAUDE.md, the size target, the "concrete enough to verify" rule and the conflict rule, read November 25, 2026.
- Next.js, Project structure, for the folder-as-route rule, the
srcfolder and the route group convention, read November 25, 2026. - Next.js, Server and Client Components, for the default and the four reasons to use a Client Component, read November 25, 2026.
- TypeScript, strict, for what the flag turns on, read November 25, 2026.
Common questions
What should a CLAUDE.md for a Next.js project contain?
The commands (dev, build, test, typecheck, lint), the folders that double as routes, the server and client boundary your team enforces, and the traps: a moved file changing a URL, a client component importing a server-only module, and a date formatted in the browser that breaks hydration. Anthropic's target is under 200 lines, so the framework's own conventions stay out.
How do I stop Claude adding "use client" everywhere?
Say what the default is and what the exception is. Next.js documents that layouts and pages are Server Components by default, so write that line first, then list the four reasons a client component is legitimate: state and event handlers, lifecycle logic, browser-only APIs and custom hooks. Add that the directive goes on the smallest leaf, so a page does not become a client component to support one button.
Should the CLAUDE.md set TypeScript strict rules?
Name the setting and the three escapes you do not allow. TypeScript's own documentation says the strict flag turns on a wide range of type checking that gives stronger guarantees of program correctness, so the point of the line is that any, @ts-ignore and non-null assertions undo it locally. The compiler enforces the flag; the CLAUDE.md tells Claude which workarounds are not acceptable.
Does this file work for React without Next.js?
The rules mostly transfer and the layout does not. If your app does not use Server Components, drop the server and client sections, and replace the route-handler rule with whatever your data layer uses. The command block, the strictness rules and the testing block still apply.
One instructions file, every agent that reads one
Omniscio keeps your canonical CLAUDE.md or AGENTS.md mirrored to the filenames Codex, Gemini, Cursor and Copilot look for, and flags a copy that was edited outside it. Any model, any harness.
The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.