The Art of System Prompts: Turning Claude into a Senior Dev
A practical guide to writing precise System Prompts. Ensure Claude codes in your style, aligns with project rules, and generates clean code.

TL;DR: A practical guide to writing precise System Prompts. Ensure Claude codes in your style, aligns with project rules, and generates clean code.
Here is a script familiar to almost every AI coding beginner:
You ask Claude: "Write me a React Button component." Claude returns code that works fine. You copy it into your project. However, the component uses Tailwind CSS v2 while your project runs on v4. It uses a different className convention. It lacks TypeScript strict types. And the code format looks entirely out of sync with the rest of your codebase.
You spend 15 minutes manual-patching the component.
The issue isn't Claude — it's that you haven't given Claude the context of your project. Claude operates in an information vacuum and fills it with the "most common averages" from its training data — not what you actually need.
A System Prompt is how you fill this void — transforming Claude from a generic developer into a specialized Senior Developer tailored to your codebase.
1. What is a System Prompt and Why Does It Matter?
A System Prompt (also called System Instructions) is a block of rules you feed to the AI before the conversation begins. It defines:
- Role: What character is the AI playing? Developer? Designer? Security Auditor?
- Context: What is the active tech stack? What coding conventions are in place? What lifecycle phase is the project in?
- Constraints: What libraries are blocked? Must we use strict types? Are global variables forbidden?
- Output Style: How should code be formatted? Should comments be in English or Vietnamese?
With Cursor IDE, you place your system prompt in a .cursorrules file or inside folder .cursor/rules/. In Claude.ai, you input it into Custom Instructions. In the Claude Code CLI, it belongs in CLAUDE.md.
Here is the difference between coding with and without a defined System Prompt:
| Without a System Prompt | With a System Prompt |
|---|---|
| Claude guesses your tech stack | Claude knows the exact versions |
| Inconsistent code styles emerge | Code aligns perfectly with your codebase |
| You must re-explain rules in every chat | You only describe the immediate task |
| High rate of back-and-forth debugging | Fast, direct deliveries |
| High risk of receiving deprecated APIs | Adheres to modern codebase conventions |
2. Anatomy of a High-Quality System Prompt
An effective System Prompt contains 5 core components:
Component 1: Role Declaration
You are a Senior Full-Stack Developer specialized in Next.js 16 (App Router) and TypeScript.
You prioritize clean, type-safe, and highly performant code.
Component 2: Tech Stack Context
## Tech Stack
- Framework: Next.js 16 (App Router) — DO NOT use Pages Router
- Styling: Tailwind CSS v4 — use inline `@import "tailwindcss"`, DO NOT use old `@tailwind` directives
- Language: TypeScript strict mode
- Database: None (file-based storage only)
- Package Manager: npm
Component 3: Coding Conventions
## Conventions
- Component names: PascalCase (e.g., Button, UserCard)
- File names: kebab-case (e.g., user-card.tsx)
- Use Interfaces instead of Types where extendable
- NEVER use `any` — use `unknown` if types are unclear
- Default to React Server Components — use 'use client' only for active hooks/events
Component 4: Project-Specific Rules
## Project Specific Rules
- Images: use raw HTML <img> with ESLint-disable comments for blog covers (Next Image conflicts with dynamic MDX sources)
- Blog access: query posts exclusively via src/lib/mdx.ts
- Environment: pull variables from .env.local, NEVER hardcode credentials
Component 5: Output Format Constraints
## Output Format
- Declare which files need modifications before outputting code blocks
- Output complete file contents (do not truncate code with "// ... existing code")
- List all affected files first when executing multi-file edits
3. Real-world Example: CLAUDE.md for Next.js Projects
Here is the actual CLAUDE.md context file I use for the toilatung-platform project:
# Claude Code Rules — toilatung-platform
## Role
Senior Next.js Developer. Priorities: correctness > performance > terseness.
## Required Stack
- Next.js 16 App Router (DO NOT use Pages Router)
- TypeScript strict mode — zero `any`, zero `@ts-ignore`
- Tailwind CSS v4 — `@import "tailwindcss"` only
- MDX parsed via next-mdx-remote
- Node.js 20+
## File Structure
src/app/ → Route handlers + page components
src/components/ → Shared UI components
src/lib/ → Core utilities (mdx.ts, utils.ts)
src/content/ → MDX resource files (read-only)
public/images/ → Static assets
## Immutable Rules
1. Server Components are the default.
2. DO NOT import client components directly into server components.
3. Define generateStaticParams() for all dynamic routes.
4. coverImage paths in MDX frontmatter must target .webp files.
5. Slugs: kebab-case, lowercase, no Vietnamese accents.
## Code Style
- Trailing commas: yes
- Semicolons: yes
- Quotes: double quotes
- Comments: brief inline English comments, longer logic explanations in Vietnamese
Pinning this file to my workspace sessions guarantees Claude never loses track of the project parameters.
4. 5 Advanced System Prompting Techniques
Technique 1: Persona Layering
Instead of defining a single generic role, stack the AI's roles based on actions:
When reviewing code changes: Act as a Security Auditor, hunting for vulnerabilities.
When writing new features: Act as a Senior Developer, prioritizing maintainability.
When refactoring code: Act as a Tech Lead, balancing system risk with cleanup rewards.
Technique 2: Negative Instructions (Defining What NOT to Do)
AI models process negative boundaries very effectively:
NEVER:
- Use useEffect for data fetching (use Server Components or query models).
- Write custom CSS files (use Tailwind classes).
- Import 'React' explicitly unless typing components.
- Use raw anchor tags <a href> (always use next/link <Link>).
Technique 3: Example-Driven Context
Provide the AI with explicit samples of "correct" code:
## Standard Component Sample:
// ✅ CORRECT:
export default function BlogCard({ post }: { post: Post }) {
return <article className="...">...</article>;
}
// ❌ INCORRECT:
const BlogCard = (props: any) => {
return <div>...</div>;
};
Technique 4: Output Templates
Instruct the AI on code layout rules:
When creating new components, always layout the file:
1. Type definitions
2. Constants / local parameters
3. Main component function
4. Export statement
Every component file must begin with a single-line JSDoc comment describing its purpose.
Technique 5: Checkpoint Prompts
For long, complex refactoring tasks, build in validation gates:
After completing each development phase:
1. List what modifications were made.
2. Outline what steps remain.
3. Stop and ask for developer approval before moving to the next file.
5. Common Mistakes in System Prompts
Mistake 1: Bloated, Unstructured Prompts
A 5,000-word block of rules without headers or hierarchy causes the AI to experience "Lost in the Middle" syndrome — forgetting instructions in the middle of the text.
Fix: Use clean headers, markdown tables, lists, and bold text to highlight critical rules. Keep system instructions under 1,500 words.
Mistake 2: Conflicting Rules
Rule 1: "Write extremely terse, short code."
Rule 2: "Always write comprehensive try/catch block error handlers."
Fix: Define a clear priority scale, for example: "Priorities: Correctness > Readability > Conciseness."
Mistake 3: Stale Context
If you upgrade your dependencies (e.g., migrating from Tailwind v3 to v4) but forget to update your rules files, the AI will continue outputting legacy code.
Fix: Treat your system prompt and rules files as living documents. Update them alongside dependency updates.
6. Copy-Pasteable System Prompt Template
Use this blueprint to build a rule file for your workspace:
# [Project Name] — Claude / AI Guidelines
## Role
Senior [Framework] Developer. Priorities: [correctness / performance / terseness].
## Tech Stack
- Framework: [e.g., Next.js / React / Vue]
- Styling: [e.g., Tailwind / CSS Modules / Styled Components]
- Language: [e.g., TypeScript / JavaScript]
- State: [e.g., Zustand / Redux / Context]
- Database: [e.g., Prisma / Drizzle / None]
## Project Directory Map
[Insert key folders and their purposes here]
## Core Rules (Must Not Break)
1. [Rule 1]
2. [Rule 2]
## NEVER Do
- [Prohibited action 1]
- [Prohibited action 2]
## Code Conventions
- Semicolons: [yes / no]
- Quotes: [single / double]
- Comments: [Vietnamese / English / mixed]
7. Conclusion
Writing a System Prompt is not a magic spell — it is a 30-minute investment that pays back hours of manual developer debugging every week.
Once Claude understands the exact scope, stack, and conventions of your codebase, it transitions from a generic chatbot to an integrated team member. You don't have to explain your environment from scratch in every thread.
Create a CLAUDE.md rules file in your workspace today. It will yield the highest ROI in your Vibe Coding workflow.
To learn advanced prompting strategies alongside real-world templates tested across dozens of production projects, check out Claude Code Mastery Pro.
To improve your workflow efficiency and system thinking, read: Comprehensive Guide to Vibe Coding to apply it directly to your business.
Tải Playbook Vibe Coding: Setup Cursor & Claude Code Chuẩn
SOP hướng dẫn thiết lập Brain file (.cursorrules / CLAUDE.md) tối ưu token và cách chia nhỏ bài toán để AI sinh code không lỗi.



