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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
罗磊的独立博客
S
Secure Thoughts
Schneier on Security
Schneier on Security
博客园 - Franky
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
爱范儿
爱范儿
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
S
Security Affairs
SecWiki News
SecWiki News
博客园 - 聂微东
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
H
Heimdal Security Blog
S
Security @ Cisco Blogs
Engineering at Meta
Engineering at Meta
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cloudbric
Cloudbric
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Visual Studio Blog
P
Proofpoint News Feed
Project Zero
Project Zero
T
Threat Research - Cisco Blogs
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
W
WeLiveSecurity
Last Week in AI
Last Week in AI
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
S
Securelist
GbyAI
GbyAI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
CERT Recently Published Vulnerability Notes
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyberwarzone
Cyberwarzone
B
Blog RSS Feed
P
Palo Alto Networks Blog
H
Hacker News: Front Page
D
Docker
雷峰网
雷峰网
Latest news
Latest news
Microsoft Security Blog
Microsoft Security Blog

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 Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Cursor Rules vs CLAUDE.md — A Deep Dive into Context Injection Patterns for AI Coding Tools
LazyDev_OH · 2026-04-30 · via DEV Community

I run Cursor and Claude Code together on the same projects. Both tools see the same codebase, but they inject rules in fundamentally different ways. Early on I didn't know this and copy-pasted the same markdown to both sides. One side followed it well, the other slowly forgot. After a month of confusion I landed on the conclusion that "these two are different species when it comes to context injection."

This post unpacks that difference from a solo dev's perspective. On the surface they're both just one markdown file, but crack them open and Cursor Rules has four modes, while CLAUDE.md has three layers plus an import system. Use them without knowing this and the same rule ends up injected twice per message eating tokens, or the file exists but the model never reads it.

I run 16 iOS apps and a few SaaS products as a solo indie. Mixing two or more tools is daily life for me. I hate writing the same rule twice, and I hate even more spending time debugging rules that don't get followed. That's the motivation for this post — how AI coding tool context injection patterns differ, how to split things when running both, and five common traps.

TL;DR

  • Cursor Rules is injected per inline edit. CLAUDE.md is loaded once at session start, with child-dir files added on demand.
  • Cursor's .mdc has 4 modes (Always Apply / Apply Intelligently / Apply to Specific Files / Apply Manually). CLAUDE.md has 5 locations (~/.claude/, project root, CLAUDE.local.md, parent dirs, child dirs) + @import.
  • For the same rule across both, short imperative for Cursor and descriptive context for Claude makes them stick.
  • Never commit globals to git. Project CLAUDE.md gets committed, CLAUDE.local.md goes in gitignore.
  • The 2026 trend is AGENTS.md as the single source of truth + Cursor/Claude/Codex/Copilot all importing from it.
  • When rules don't stick, it's almost always either "the file wasn't actually read" or "two rules contradict each other."

At a glance

Item Cursor Rules CLAUDE.md
Location .cursor/rules/*.mdc or .cursorrules ~/.claude/CLAUDE.md + project root
Injection timing Per inline edit / chat Once at session start
Splitting File-level + conditional globs Chained via @import syntax
Modes Always / Auto / Agent / Manual Always injected (only layered)
Global area App settings screen (no text file) Separate markdown file

Why Cursor Rules and CLAUDE.md are different species

Surface-level, both are markdown. But the tools' usage patterns differ. Cursor's main mode is inline edit. You fix short blocks of code on the spot. Claude Code's main mode is the agent session. Once you start, it autonomously runs dozens of tool calls. That difference is reflected directly in how each rule file is structured.

Cursor builds a fresh system prompt for every inline edit request. So it injects the rules every time. Token cost every time. That's why Cursor Rules works best with short, forceful imperatives. One-line rules like "use Tailwind only" or "App Router only" — the model re-reads them every request.

Claude Code sessions are long. Once you start, it carries the same system prompt all the way through. So CLAUDE.md works better with background context than short commands. Things like "this is why the codebase is structured this way," "here are the danger zones," "here's who I am" — descriptive prose. Material the model references when making its own judgment calls.

When I didn't know this and copy-pasted the same rules to both sides, Claude got annoyed by the imperative tone and started routing around the rules. Cursor was too long, so it only listened to the first 30 lines and skimmed the rest. Just splitting the tone alone visibly improved rule compliance on both tools.

The 4 modes of Cursor Rules

.cursor/rules/*.mdc files are markdown with frontmatter. The frontmatter field combination determines the mode. Early on I didn't read this and just slapped alwaysApply: true on everything, wasting all the efficiency.

---
description: SwiftUI iOS work rules
globs: "**/*.swift"
alwaysApply: false
---

- Swift 6, async/await
- Prefer @Observable macro, no ObservableObject
- No completion handlers
- Split long Views with ViewBuilder

Enter fullscreen mode Exit fullscreen mode

Always mode (alwaysApply: true) is forcibly injected on every request. Same as the old .cursorrules file. I put danger rules here (no production touches, no force push). Only items where forgetting causes accidents.

Auto mode (alwaysApply: false + globs filled in) auto-injects only when globs match. The example above only injects when touching a .swift file. I split stack-specific conventions into this mode.

Agent-requested mode (only description filled, both globs and alwaysApply empty) lets the model decide whether to pull it in. If the description looks relevant, the model fetches it. I keep things like occasional code review checklists or migration procedures here.

Manual mode (just the name, all auto-triggers off) only loads when explicitly called via @rulename in chat. For templates I don't want forced but want to summon on demand.

After a year of running this, my settled ratio is Always 20%, Auto 60%, Agent 15%, Manual 5%. Stuff too much into Always and per-request token cost balloons while the model's attention drops.

CLAUDE.md's 3 layers and @import system

CLAUDE.md doesn't have modes — it has layers. It reads from three places. ~/.claude/CLAUDE.md (global), <project root>/CLAUDE.md (project), and CLAUDE.md inside subfolders. All three get pasted whole at the front of the system prompt at session start.

Global is my personal identity. Name, tone, my regular stack, hard-banned actions. My global is about 50 lines.

Project root is for that codebase only. Stack structure, folder conventions, danger zones. If something contradicts the global, this is where I explicitly override. For example if global says "TypeScript strict" but some legacy project says "any allowed for now," I write in the project CLAUDE.md: "override the global strict rule for this project."

Sub-directory applies only inside that folder. SwiftUI conventions go in apps/ios/CLAUDE.md, Next.js conventions in apps/web/CLAUDE.md. Works well for monorepos.

There's also @import syntax. Write @docs/conventions.md inside CLAUDE.md and it pulls that file in too. My project CLAUDE.md is about 50 lines and imports two files: @docs/stack.md and @docs/danger.md.

Context injection timing — every time vs once

This is the most important difference. Cursor and Claude inject rules at fundamentally different moments.

Cursor rebuilds the system prompt every request. Rules get injected every time. Token cost every time. Upside: add a new rule and the next request applies it instantly.

Claude Code reads once at session start. It carries the same system prompt until that session ends. Token cost is small thanks to prompt cache. Downside: changing a rule doesn't apply to the existing session. You need a new session for the new rule to land.

Add a rule in Cursor and the next inline edit picks it up. Same scenario in Claude requires /clear to reset the session, or opening a new conversation. I once spent 30 minutes confused about "why isn't it picking up the new rule" before I figured this out.

globs matching vs @import — file-splitting pattern

Cursor Rules splits by file via globs. Touch a .swift and only iOS rules come in; touch a .tsx and only Next.js rules come in. No noise in the model context.

.cursor/rules/
├── always-danger.mdc        # alwaysApply: true
├── nextjs-stack.mdc         # globs: "**/*.{tsx,ts}"
├── ios-swiftui.mdc          # globs: "**/*.swift"
├── tailwind.mdc             # globs: "**/*.{tsx,jsx,html}"
└── pr-template.mdc          # manual

Enter fullscreen mode Exit fullscreen mode

CLAUDE.md splits via @import. The main file acts as the entrypoint and imported files trail along. Downside: no globs matching, so everything loads regardless of work context. Every import behaves like alwaysApply: true.

# Project: apsity

@docs/stack.md
@docs/conventions.md
@docs/danger.md

## Extra notes
- Add new routes under app/
- DB schema changes always via migration files

Enter fullscreen mode Exit fullscreen mode

For Cursor I split fine by stack, for Claude I bundle into bigger chunks. Since everything loads on Claude anyway, fine-grained splitting is meaningless. But I never let an imported file go past 200 lines — model attention drops past that line.

Token cost and noise control

Stuffing too many rules in is the trap indie devs fall into most. I crammed 200 lines into a single page. The result was the model dutifully followed the first 30 lines and "is that even there?" the rest.

On Cursor this also hits as direct token cost. Rules go in every request, so a 200-line ruleset is 200 lines of tokens per inline edit. If I do 50 inline edits a day, that's 10,000 lines of tokens per day. Split with globs and usually only 30-50 lines load — 1/4 the tokens.

The rule-writing guide I've settled on has three parts:

  1. Write in measurable form. "Write clean code" doesn't land — "split functions over 50 lines" does.
  2. One rule per line, one command per rule.
  3. Attach a short "why." Claude generalizes when it knows the reason.

Strategy for running both tools together

Area Location Tone Example
Danger rules Both Short imperative "no .env, no force push"
Stack conventions Cursor (per glob) Imperative "Tailwind utils only, no styled-components"
Codebase background Claude (CLAUDE.md) Descriptive "App Router migration done, new code goes under app/"
Personal identity Claude global only Descriptive "solo indie, Korean, ship-fast first"
PR/review checklist Cursor (manual) Steps "Call via @pr-template"

Only danger rules duplicate across both. Stack conventions go heavily on the Cursor side. Codebase background goes heavily on the Claude side. Personal identity only goes in Claude global.

Debugging order when rules don't stick

I debug "this rule isn't sticking" more often than I write new rules. Almost every case falls into these 4 steps.

Step 1, confirm the file actually got read. On Claude Code, in the first message of a session, ask "list 3 of the danger rules I put in CLAUDE.md." If the answer is accurate, it read it.

Step 2, recheck the rule mode. In Cursor, if alwaysApply: false and both globs and description are empty, that rule will never auto-inject. Always check the frontmatter first.

Step 3, check for rule contradictions. When global vs project, or .cursorrules vs .cursor/rules/*.mdc conflict, the model follows whichever is more strongly worded.

Step 4, check whether the rule is too abstract. "Write clean code" doesn't land. "Split functions over 50 lines" lands. Has to be measurable.

One more thing. Cursor's .cursorrules (old format) and .cursor/rules/*.mdc (new format) both apply when both exist. Keeping both around duplicates rules and confuses the model. Migrate and delete the old file immediately.

Security and git commit policy

Project-level files always get committed, globals never.

<project>/CLAUDE.md, .cursorrules, .cursor/rules/*.mdc are part of the codebase. New collaborators or future-me need the same rules. Don't put them in .gitignore.

The opposite for ~/.claude/CLAUDE.md, ~/.gemini/GEMINI.md and other globals — those are personal identity. Email, tone preferences, even names of apps I run. Pushing this to git causes accidents. I keep them in a separate private dotfiles repo.

Watch for secrets inside rule files. I once accidentally put a Supabase project ID in CLAUDE.md. After that I don't put env var names or identifier-style things in rule files. I stop at "env vars live in .env.local."

Real example — my SaaS setup

Project root CLAUDE.md (descriptive context):

# Project: apsity

## Stack
- Next.js 15 App Router, TypeScript strict
- Supabase (PostgreSQL + Auth + Storage)
- Vercel deploy, Tailwind v4

## Structural decisions
- Prefer Server Components, 'use client' only for interactions
- Data fetching: call Supabase directly from Server Components
- API routes only for webhooks and external calls
- Auth via RLS, no backend if-statements

@docs/danger.md
@docs/conventions.md

Enter fullscreen mode Exit fullscreen mode

Same folder's .cursor/rules/nextjs-stack.mdc (imperative, auto via globs):

---
description: Next.js + TypeScript work rules
globs: "**/*.{ts,tsx}"
alwaysApply: false
---

- App Router only. Don't write Pages Router code.
- Minimize 'use client'. Branch at the top of the component tree.
- Tailwind utils only. No styled-components.
- No `as` casting. If unsure, unknown then narrow.
- Split functions over 50 lines.

Enter fullscreen mode Exit fullscreen mode

And .cursor/rules/always-danger.mdc (every-request injection):

---
description: Danger zone guards
alwaysApply: true
---

- Confirm with user before editing supabase/migrations/.
- Never print production env vars.
- DB schema changes always via migration files.
- No git push --force.
- Never read or modify .env files.

Enter fullscreen mode Exit fullscreen mode

Same ruleset, but Cursor gets short commands and Claude gets background + reasoning. They don't conflict.

AGENTS.md — the 2026 single-source-of-truth trend

Pinning the same rule in two files is obviously inefficient. So starting late 2025, AGENTS.md rose as a standard. OpenAI Codex defined it first, and in December 2025 it was donated to Linux Foundation/AAIF. As of 2026, Cursor, Claude Code, Codex CLI, GitHub Copilot, Devin, Windsurf, and Gemini CLI all read AGENTS.md.

My ops pattern got simpler. Keep AGENTS.md as the source of truth, then @AGENTS.md import via a single line in .cursor/rules/index.mdc, @AGENTS.md import in CLAUDE.md, same for other tools. Edit one file and every tool reflects it.

That said, Claude Code's global (~/.claude/CLAUDE.md) and Cursor's user rules (app settings screen) can't be sync'd outside the tool — personal identity, voice — so they stay out of the AGENTS.md source. The source holds project conventions, codebase rules, and danger rules only.

Wrap-up

Cursor Rules and CLAUDE.md look similar on the surface — both markdown — but inside they're entirely different systems. Cursor is short rulesets injected per inline edit; CLAUDE.md is descriptive context pinned at session level. When writing the same rule in both places, you have to match the tone too for both to listen.

My one-year conclusion is simple. Don't pin both files from the start — start with one tool, one file. When that file goes past 80 lines, then split via globs or @import. When you adopt the second tool, that's when you extract AGENTS.md as the source. Build everything up front and you'll just have rules that go unfollowed.

Official sources

This post is current as of 2026-04-30. Both Cursor and Claude Code update their rule systems quickly — six months out, this may need a recheck. The SaaS I run, apsity, is built for solo developers.