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

推荐订阅源

A
About on SuperTechFans
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
月光博客
月光博客
美团技术团队
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
爱范儿
爱范儿
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
I
InfoQ
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
F
Fortinet All Blogs

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
2026年版:AIエージェントに渡すNext.js用ルールファイルの実...
スシロー · 2026-06-15 · via DEV Community

スシロー

なぜルールファイルが必要なのか

Claude CodeやCursor、GitHub Copilot Workspaceなどのエージェントは、会話ごとにコンテキストをリセットする。「App RouterではServer Componentを優先して」「anyは禁止」といった方針を毎回伝えるのは非現実的だ。CLAUDE.md・.cursorrules・AGENTS.mdはその解決策で、リポジトリに置くだけでエージェントが読み込み、ルールを前提として動くようになる。

ただし「書けば万能」ではない。ルールが長すぎると無視されやすく、矛盾した指示があると挙動がぶれる。実用上は短く・具体的に・優先順位つきで書くのが原則だ。

ファイルの使い分け

ファイル 読み込むツール
CLAUDE.md Claude Code
.cursorrules Cursor
AGENTS.md OpenAI Codex系、汎用

内容はほぼ共通化できる。プロジェクトルートにCLAUDE.mdを置き、.cursorrulesからそれを参照する形にすると管理が楽だ。

Next.js App Router向けの実例

# Project Rules

## Stack
- Next.js 15 App Router / TypeScript strict mode
- Tailwind CSS v4 / Prisma / Zod

## Component rules
- デフォルトは Server Component。クライアント操作が必要な場合のみ `"use client"` を追加する
- `app/` 配下のファイルは page.tsx / layout.tsx / loading.tsx / error.tsx のみ
- 共有UIは `components/` に置き、ロジックは `lib/` に分離する

## TypeScript
- `any` 禁止。不明な型は `unknown` + 型ガードで処理する
- Prismaの返り値は必ず Zod スキーマで検証してからAPIレスポンスに使う

## API Routes (Route Handlers)
- `app/api/` の Route Handler は必ず `NextRequest` / `NextResponse` を使う
- 認証チェックは `lib/auth.ts``requireSession()` を必ず先頭で呼ぶ
- エラーは `{ error: string }` 形式で返し、HTTPステータスを明示する

## 禁止事項
- `pages/` ディレクトリへの新規ファイル追加
- `console.log` のコミット(デバッグは `logger.ts` 経由)
- `fetch` の直書き(`lib/api-client.ts` のラッパーを使う)

## コード生成時の優先順位
1. 既存の型定義・ユーティリティを再利用する
2. 新規ファイルを作る前にコンポーネントの分割を検討する
3. テストは Vitest + React Testing Library で書く

運用Tips

短く保つ: 500行を超えたルールファイルはエージェントのコンテキスト消費を圧迫する。「なぜそうするか」は省略し、ルールだけを箇条書きにする。

禁止事項を明示する: 「推奨」より「禁止」のほうがエージェントは従いやすい。pages/への追記禁止やany禁止のように、ネガティブルールを必ず書く。

定期的に削除する: Next.jsのバージョンアップやリファクタ後に古いルールが残ると、エージェントが矛盾した判断をする。git blameでルールの追加日を確認し、半年ごとに棚卸しする。

チームで合意してからコミットする: エージェントへの指示はそのままコーディング規約になる。個人の好みで追加せず、PRレビューと同じ合意フローを踏むとチーム全体の一貫性が保てる。

ルールファイルはあくまで「エージェントへの継続的な指示書」だ。万能薬ではないが、積み重ねれば指摘の繰り返しが確実に減る。


5フレームワーク分の実例をまとめたキット

Next.js/React/FastAPI/Godot/Express のルールファイル実例集を用意しました。👉 詳細・入手はこちら