惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Y
Y Combinator Blog
T
Tailwind CSS Blog
G
Google Developers Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
爱范儿
爱范儿
博客园 - 【当耐特】
腾讯CDC
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
C
Check Point Blog
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Under 30-Minute Setup: AI Coding Guidelines for Your Next...
yunbow · 2026-05-05 · via DEV Community

Your Next.js project has an AI assistant. The question isn't whether to use AI — it's whether the code it generates follows your project's conventions.

This is a hands-on walkthrough. In under 30 minutes (10 via CLI, 20 manually), you'll install AI Dev OS into an existing Next.js project using Claude Code. By the end, your AI will consistently apply your naming conventions, security patterns, and architectural rules — without you reminding it every prompt.

All examples show before/after code so you can see exactly what changes.


What You're Installing (5 min)

AI Dev OS uses a 4-layer model. For a Next.js project, here's what goes where:

CLAUDE.md                     ← L1 + L2: Always loaded, project philosophy
.claude/guidelines/
  nextjs.md                   ← L3: App Router, Server Actions, Middleware
  typescript.md               ← L3: Type conventions, naming rules
  security.md                 ← L3: Auth patterns, input validation
.claude/commands/             ← L4: Reusable Skills for common tasks

Enter fullscreen mode Exit fullscreen mode

The rules you care about most day-to-day live in guidelines/. They're loaded when relevant — not every single prompt — so they don't dilute Claude's attention on your actual task.


Prerequisites

Node.js >= 18
Next.js >= 14 (App Router)
Claude Code CLI installed
TypeScript (strict mode strongly recommended)

Enter fullscreen mode Exit fullscreen mode

Already have a running Next.js project? Good — work from there. Starting fresh also works.


Option A: CLI Setup (10 min)

The fastest path:

npx ai-dev-os init --rules typescript --plugin claude-code

Enter fullscreen mode Exit fullscreen mode

This generates:

  • CLAUDE.md — guidelines index (3 directive lines + file references)
  • docs/ai-dev-os/ — rule submodule with L1–L3 guidelines for TypeScript/Next.js
  • .claude/plugins/ai-dev-os/ — Skills, Agents, and Hooks (L4)
  • Pre-commit hooks for automated rule verification

After it runs, open CLAUDE.md and add your project-specific guideline files to the ## Project-Specific Guidelines section (3 files is the recommended starting point).

Verify the setup:

npx ai-dev-os doctor

Enter fullscreen mode Exit fullscreen mode

Output should show all guideline files detected and no configuration conflicts.


Option B: Manual Setup (20 min)

Manual setup takes longer but gives you a clear mental model of what each file does. Recommended if you want to adapt the rules heavily.

Step 1: Add the rule submodule and copy the CLAUDE.md template

# Add L1–L3 rules for TypeScript/Next.js
git submodule add https://github.com/yunbow/ai-dev-os-rules-typescript.git docs/ai-dev-os
git submodule update --init

# Add Claude Code plugin (Skills, Agents, Hooks)
git submodule add https://github.com/yunbow/ai-dev-os-plugin-claude-code.git .claude/plugins/ai-dev-os

# Copy the CLAUDE.md template
cp docs/ai-dev-os/templates/nextjs/CLAUDE.md.template ./CLAUDE.md

Enter fullscreen mode Exit fullscreen mode

CLAUDE.md is an index file — 3 directive lines followed by references to guideline files in the submodule. Open it and fill in your project name, then add project-specific guideline files in the ## Project-Specific Guidelines section:

## Project-Specific Guidelines
- docs/guidelines/your-business-rule.md
- docs/guidelines/your-external-api.md
- docs/guidelines/your-compliance.md

Enter fullscreen mode Exit fullscreen mode

3 files is the recommended starting point. Create these files in docs/guidelines/ and document the rules specific to your project (auth provider choices, external service integrations, business constraints).

Step 2: Understand what the submodule provides

The docs/ai-dev-os/ submodule already contains comprehensive L3 guidelines. Key files for a Next.js project:

docs/ai-dev-os/03_guidelines/
  frameworks/nextjs/
    overview.md         ← App Router conventions, tech stack overview
    api.md              ← API route patterns (auth check, field selection)
    server-actions.md   ← ActionResult<T> pattern, Zod validation
    auth.md             ← NextAuth integration
    database.md         ← Prisma usage, no raw SQL
  common/
    security.md         ← Auth invariants, data exposure prevention
    validation.md       ← Zod schema placement and usage
    error-handling.md   ← Error patterns
    naming.md           ← Naming conventions

Enter fullscreen mode Exit fullscreen mode

These files contain the concrete rules with examples — including the patterns shown in the Before/After section below. You don't write these; they come with the submodule.

Step 3: Create the ActionResult type

If you don't have it already:

// types/action.ts
export type ActionResult<T = void> =
  | (T extends void ? { success: true } : { success: true; data: T })
  | { success: false; error: string }

Enter fullscreen mode Exit fullscreen mode

This conditional type handles the common void case — Server Actions that return no data can use return { success: true } without a data field, while actions that return data get a fully typed { success: true; data: T }.


Verification: Test Before/After

The best way to confirm your setup is working: ask Claude the same task twice — before applying guidelines, after.

Test prompt:

Create an API route at app/api/profile/route.ts that returns 
the current user's profile data from the database.

Enter fullscreen mode Exit fullscreen mode

Before (no guidelines, typical output):

import { prisma } from '@/lib/prisma'

export async function GET(request: Request) {
  const userId = request.headers.get('x-user-id')
  const user = await prisma.user.findUnique({ where: { id: userId } })
  return Response.json(user)
}

Enter fullscreen mode Exit fullscreen mode

Problems: takes user ID from a header (trivially spoofable), returns the entire user object including password hash and tokens, no error handling if user not found. Also note the import uses prisma from @/lib/prisma — in the conventions we're setting up, the db client is exposed as db from @/lib/db for consistency.

After (with guidelines loaded):

import { auth } from '@/lib/auth'
import { db } from '@/lib/db'

export async function GET(): Promise<Response> {
  const session = await auth()
  if (!session) {
    return Response.json({ error: 'Unauthorized' }, { status: 401 })
  }

  const user = await db.user.findUnique({
    where: { id: session.user.id },
    select: {
      id: true,
      name: true,
      email: true,
      image: true,
      createdAt: true,
    },
  })

  if (!user) {
    return Response.json({ error: 'Not found' }, { status: 404 })
  }

  return Response.json({ data: user })
}

Enter fullscreen mode Exit fullscreen mode

Auth from session (not headers). Explicit field selection. Error cases handled. Consistent response shape.


Before / After: Server Action

Test prompt:

Create a Server Action to update the current user's display name.

Enter fullscreen mode Exit fullscreen mode

Before:

'use server'
import { prisma } from '@/lib/prisma'

export async function updateDisplayName(name: string) {
  await prisma.user.update({
    where: { id: 'user_id_here' },
    data: { name },
  })
}

Enter fullscreen mode Exit fullscreen mode

Problems: hardcoded placeholder ID, no validation, no auth, no return value.

After:

'use server'
import { z } from 'zod'
import type { ActionResult } from '@/types/action'
import { auth } from '@/lib/auth'
import { db } from '@/lib/db'

const UpdateNameSchema = z.object({
  name: z.string().min(1, 'Name is required').max(100, 'Name too long'),
})

export async function updateDisplayName(
  formData: FormData
): Promise<ActionResult<void>> {
  const session = await auth()
  if (!session) return { success: false, error: 'Unauthorized' }

  const parsed = UpdateNameSchema.safeParse({ name: formData.get('name') })
  if (!parsed.success) return { success: false, error: parsed.error.message }

  await db.user.update({
    where: { id: session.user.id },
    data: { name: parsed.data.name },
  })

  return { success: true }
}

Enter fullscreen mode Exit fullscreen mode


Loading Guidelines in Practice

The Skills bundled with ai-dev-os-plugin-claude-code handle contextual loading automatically. For example, the /api skill loads the relevant framework and security guidelines before generating code.

You can also reference guidelines directly in your prompt:

@docs/ai-dev-os/03_guidelines/frameworks/nextjs/server-actions.md
Create a Server Action to update the current user's display name.

Enter fullscreen mode Exit fullscreen mode

Or add a project-specific skill in .claude/commands/api.md that loads your project-specific rules alongside the framework guidelines:

Load the API and security guidelines, then complete the task:

@docs/ai-dev-os/03_guidelines/frameworks/nextjs/api.md
@docs/ai-dev-os/03_guidelines/common/security.md
@docs/guidelines/your-business-rule.md

Task: $ARGUMENTS

Enter fullscreen mode Exit fullscreen mode

Now in Claude Code: /api Create a route for updating user preferences


Next Steps

Add your project-specific rules. The submodule provides the framework-level rules. Create docs/guidelines/ files for your project's business logic, external API integrations, and compliance requirements — these go in the ## Project-Specific Guidelines section of CLAUDE.md.

Commit the submodule reference to git. Team members who clone the repo run git submodule update --init --recursive and get the full guideline set automatically.

Keep the submodule updated. Run git submodule update --remote docs/ai-dev-os to pull the latest rules, or pin to a specific version with git checkout v1.x.x inside the submodule.


The full ruleset (with Python/FastAPI support) is at github.com/yunbow/ai-dev-os.

What Next.js patterns does your team enforce that keep slipping through AI-generated code? I'm collecting edge cases to improve the default ruleset.