<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: shohei-ai-lab</title>
    <description>The latest articles on DEV Community by shohei-ai-lab (@shohei-ai-lab).</description>
    <link>https://dev.to/shohei-ai-lab</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4061461%2F954ff737-81e0-43ec-be67-8a98760eecc1.png</url>
      <title>DEV Community: shohei-ai-lab</title>
      <link>https://dev.to/shohei-ai-lab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shohei-ai-lab"/>
    <language>en</language>
    <item>
      <title>Stop Losing Context Mid-Session: A Practical Guide to Claude Code's /compact, /clear, and /context Commands</title>
      <dc:creator>shohei-ai-lab</dc:creator>
      <pubDate>Sat, 08 Aug 2026 07:38:12 +0000</pubDate>
      <link>https://dev.to/shohei-ai-lab/stop-losing-context-mid-session-a-practical-guide-to-claude-codes-compact-clear-and-context-jhi</link>
      <guid>https://dev.to/shohei-ai-lab/stop-losing-context-mid-session-a-practical-guide-to-claude-codes-compact-clear-and-context-jhi</guid>
      <description>&lt;p&gt;You're deep into a refactoring session. Claude Code has been reading files, running tests, and building features for an hour. Then suddenly — it asks you a question you already answered 20 minutes ago.&lt;/p&gt;

&lt;p&gt;Or worse: it suggests an approach that contradicts the design decision you both agreed on at the start of the session.&lt;/p&gt;

&lt;p&gt;The problem isn't that Claude is broken. It's that the &lt;strong&gt;context window is full&lt;/strong&gt;, and important information got silently compressed away.&lt;/p&gt;

&lt;p&gt;Every Claude Code user hits this wall eventually. Here's how to manage it deliberately instead of reactively.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Context Overflows Faster Than You Think
&lt;/h2&gt;

&lt;p&gt;Claude Code's context window accumulates everything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your prompts and Claude's responses&lt;/li&gt;
&lt;li&gt;Every file read (hundreds to thousands of tokens each)&lt;/li&gt;
&lt;li&gt;Command outputs (test results, build logs, error traces)&lt;/li&gt;
&lt;li&gt;Generated code diffs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A single &lt;code&gt;cat&lt;/code&gt; of a 200-line file can burn 500+ tokens. Read 10 files, run a test suite, and inspect the error output? You've easily consumed half your context budget before the real work begins.&lt;/p&gt;

&lt;p&gt;When the window fills up, Claude Code auto-compacts — summarizing older messages to free space. This is a safety net, not an optimization. The auto-compaction doesn't know which parts of your conversation are critical to preserve.&lt;/p&gt;




&lt;h2&gt;
  
  
  The 4 Commands You Need
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/context&lt;/code&gt; — Check Your Budget
&lt;/h3&gt;

&lt;p&gt;Before you act, know where you stand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This renders a colored grid showing how much context is consumed. It also flags optimization suggestions: tools consuming excessive tokens, memory bloat, and capacity warnings.&lt;/p&gt;

&lt;p&gt;Add &lt;code&gt;all&lt;/code&gt; for a per-item breakdown:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/context all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to use it&lt;/strong&gt;: Whenever responses feel slow or lower quality. Think of it as checking fuel level before a long drive.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/compact&lt;/code&gt; — Summarize and Continue
&lt;/h3&gt;

&lt;p&gt;This is the command you'll use most. It summarizes the conversation so far, freeing context while keeping the session alive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/compact
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key feature: &lt;strong&gt;you can tell it what to preserve&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/compact Keep the auth module design decisions and the list of remaining edge cases
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With focus instructions, Claude prioritizes retaining what you specify and aggressively compresses everything else (setup discussions, failed debug attempts, resolved issues).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to use it&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transitioning between work phases (design → implementation)&lt;/li&gt;
&lt;li&gt;After solving a bug (keep the fix, drop the trial-and-error)&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;/context&lt;/code&gt; shows 70%+ usage&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/autocompact&lt;/code&gt; — Tune the Safety Net
&lt;/h3&gt;

&lt;p&gt;Controls when auto-compaction triggers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/autocompact 500k
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets the threshold to 500k tokens. Use &lt;code&gt;auto&lt;/code&gt; to reset to the model-optimized default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/autocompact auto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The setting persists across sessions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to use it&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large refactoring (raise it — you need more info retained)&lt;/li&gt;
&lt;li&gt;Quick single-file fixes (leave at default)&lt;/li&gt;
&lt;li&gt;After switching models (different models have different optimal thresholds)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/clear&lt;/code&gt; — Full Reset
&lt;/h3&gt;

&lt;p&gt;Wipes everything and starts fresh. Unlike &lt;code&gt;/compact&lt;/code&gt;, no summary is kept.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Name the cleared session so you can resume it later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/clear auth-bugfix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can get back to that conversation anytime with &lt;code&gt;/resume auth-bugfix&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to use it&lt;/strong&gt;: Switching to a completely unrelated task where previous context adds zero value.&lt;/p&gt;




&lt;h2&gt;
  
  
  Practical Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pattern 1: Phase-Based Compaction
&lt;/h3&gt;

&lt;p&gt;For multi-hour sessions, compact at every phase transition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Design discussion (30 min)
  └── /compact Keep design conclusions and open questions

Implementation phase 1 (60 min)
  └── /context → /compact if &amp;gt; 70%

Debug session (45 min)
  └── /compact Keep: root cause was X, fix is Y. Drop: failed attempts

Implementation phase 2 (60 min)
  └── final push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trial-and-error from phase N is rarely useful in phase N+1.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 2: Task Switching
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Task A: Fix login bug
  └── Done → /clear login-fix

Task B: Dashboard redesign
  └── Done → /clear dashboard-v2

Task C: New API endpoint
  └── Working...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zero context overlap between tasks = use &lt;code&gt;/clear&lt;/code&gt;. Name them for future reference.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 3: Debug Cleanup
&lt;/h3&gt;

&lt;p&gt;Debugging is a context hog. Error traces, stack dumps, hypothesis testing — it all piles up.&lt;/p&gt;

&lt;p&gt;Once you find the fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/compact Root cause: race condition in auth middleware.
Fix: added mutex lock in handleRequest.
Hypotheses A and B were dead ends — discard.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You keep the conclusion, drop the journey.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Mistake 1: Compacting Too Often
&lt;/h3&gt;

&lt;p&gt;Over-compacting loses the "why" behind decisions. Claude starts making suggestions that contradict earlier agreements because the reasoning was compressed away.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;: Put persistent design decisions in CLAUDE.md. It's re-read on every compaction — nothing in that file gets lost.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 2: Using /compact When You Need /clear
&lt;/h3&gt;

&lt;p&gt;Compacting a session about login bugs before starting dashboard work = leftover login context polluting your dashboard session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule of thumb&lt;/strong&gt;: If zero information from the previous task helps the next one, &lt;code&gt;/clear&lt;/code&gt;. If there's any thread connecting them, &lt;code&gt;/compact&lt;/code&gt; with focus.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 3: Never Checking /context
&lt;/h3&gt;

&lt;p&gt;You only discover the problem when auto-compaction silently fires and drops something important.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;: Check &lt;code&gt;/context&lt;/code&gt; before reading large files or running verbose commands. If you're at 70%+, compact first.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 4: Compacting Without Focus Instructions
&lt;/h3&gt;

&lt;p&gt;Without guidance, Claude decides what's important on its own. Its priorities may not match yours.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;: Always add a one-liner. Focus on: "what's next", "what constraints must survive", "what's the current state". Takes 5 seconds, saves you from repeating yourself later.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Reference
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;th&gt;Session&lt;/th&gt;
&lt;th&gt;When&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/context&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Show usage&lt;/td&gt;
&lt;td&gt;Continues&lt;/td&gt;
&lt;td&gt;Quality feels off&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/context all&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Detailed breakdown&lt;/td&gt;
&lt;td&gt;Continues&lt;/td&gt;
&lt;td&gt;Need to find what's consuming tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/compact&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Summarize conversation&lt;/td&gt;
&lt;td&gt;Continues&lt;/td&gt;
&lt;td&gt;Phase transition, 70%+ usage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/compact [focus]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Summarize with priority&lt;/td&gt;
&lt;td&gt;Continues&lt;/td&gt;
&lt;td&gt;Keep specific info alive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/autocompact [size]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Set auto-trigger threshold&lt;/td&gt;
&lt;td&gt;Persists&lt;/td&gt;
&lt;td&gt;Adjust safety net timing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/clear&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Full reset&lt;/td&gt;
&lt;td&gt;New session&lt;/td&gt;
&lt;td&gt;Switching to unrelated task&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/clear [name]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Named reset&lt;/td&gt;
&lt;td&gt;New session&lt;/td&gt;
&lt;td&gt;Might need to return later&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;Context management is the difference between a productive 4-hour session and a frustrating one that degrades after 45 minutes.&lt;/p&gt;

&lt;p&gt;The shift is simple: move from &lt;strong&gt;reactive&lt;/strong&gt; (waiting for auto-compaction to save you) to &lt;strong&gt;proactive&lt;/strong&gt; (compacting deliberately, with intent, at natural breakpoints).&lt;/p&gt;

&lt;p&gt;Your context window is a resource. Manage it like you manage memory in production code.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;For more Claude Code configuration tips, check out our free starter templates:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📦 &lt;a href="https://mairevenue.gumroad.com/l/free-config-starter" rel="noopener noreferrer"&gt;Claude Code Config Starter Pack (Free)&lt;/a&gt; — 3 ready-to-use CLAUDE.md templates&lt;/li&gt;
&lt;li&gt;📦 &lt;a href="https://mairevenue.gumroad.com/l/tmtke" rel="noopener noreferrer"&gt;AI Coding Prompt Toolkit (52 prompts)&lt;/a&gt; — Structured prompts for common dev workflows&lt;/li&gt;
&lt;li&gt;📦 &lt;a href="https://mairevenue.gumroad.com/l/mgiiam" rel="noopener noreferrer"&gt;Claude Code Config Pack (20 templates)&lt;/a&gt; — Project-type-specific configurations&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Write a Different CLAUDE.md for Every Project Type — Web, API, CLI, and Library Configs Compared</title>
      <dc:creator>shohei-ai-lab</dc:creator>
      <pubDate>Wed, 05 Aug 2026 18:57:58 +0000</pubDate>
      <link>https://dev.to/shohei-ai-lab/how-to-write-a-different-claudemd-for-every-project-type-web-api-cli-and-library-configs-pf0</link>
      <guid>https://dev.to/shohei-ai-lab/how-to-write-a-different-claudemd-for-every-project-type-web-api-cli-and-library-configs-pf0</guid>
      <description>&lt;p&gt;You have one CLAUDE.md template. You copy it into every new project. But your CLI tool doesn't need UI component rules, your API server doesn't need routing conventions, and your npm library doesn't care about database access patterns.&lt;/p&gt;

&lt;p&gt;A single template can't cover everything. Different project types need different instructions.&lt;/p&gt;

&lt;p&gt;After configuring CLAUDE.md across 20+ projects in our &lt;a href="https://zenn.dev/shohei_ai_lab" rel="noopener noreferrer"&gt;AI Autonomous Revenue Project&lt;/a&gt;, we developed a clear framework: identify your project type, then prioritize accordingly.&lt;/p&gt;




&lt;h2&gt;
  
  
  The 3 Things Every CLAUDE.md Needs (Regardless of Type)
&lt;/h2&gt;

&lt;p&gt;Before we diverge by project type, every CLAUDE.md shares this skeleton:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Stack&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; [Language] + [Primary framework/library]
&lt;span class="p"&gt;-&lt;/span&gt; [Package manager]

&lt;span class="gh"&gt;# Commands&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Build: [build command]
&lt;span class="p"&gt;-&lt;/span&gt; Test: [test command]  
&lt;span class="p"&gt;-&lt;/span&gt; Lint: [lint command]

&lt;span class="gh"&gt;# Critical Rules (3-5 max)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; [Your most important constraint — with a "why" clause]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is your universal foundation. Everything below builds on top of it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Type A: Web Application (Frontend + Backend)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What Makes It Different
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Heavy UI component generation&lt;/li&gt;
&lt;li&gt;Many structural decisions (routing, state management, auth)&lt;/li&gt;
&lt;li&gt;File placement rules are critical&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Priority Sections
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Architecture&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Rendering: Server Components by default, "use client" only when needed
&lt;span class="p"&gt;-&lt;/span&gt; Data fetching: Server Actions for mutations, fetch() for queries
&lt;span class="p"&gt;-&lt;/span&gt; State: URL params for shareable state, React state for ephemeral UI

&lt;span class="gh"&gt;# File Placement&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Pages: app/[route]/page.tsx
&lt;span class="p"&gt;-&lt;/span&gt; Components: src/components/[feature]/
&lt;span class="p"&gt;-&lt;/span&gt; Server Actions: app/[route]/actions.ts

&lt;span class="gh"&gt;# UI Rules&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Use shadcn/ui from src/components/ui/
&lt;span class="p"&gt;-&lt;/span&gt; Styling: Tailwind utility classes only (no CSS modules)
&lt;span class="p"&gt;-&lt;/span&gt; Responsive: mobile-first (sm:/md:/lg: breakpoints)
&lt;span class="p"&gt;-&lt;/span&gt; Accessibility: all interactive elements need aria labels
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Skip These
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Publishing config (no npm publish needed)&lt;/li&gt;
&lt;li&gt;SemVer rules (apps typically don't version this way)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Type B: API Server (No Frontend)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What Makes It Different
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Endpoint design is the core activity&lt;/li&gt;
&lt;li&gt;Request/response type definitions matter most&lt;/li&gt;
&lt;li&gt;Error handling must be consistent across all routes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Priority Sections
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# API Design&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Response format: { data: T | null, error: { code, message } | null }
&lt;span class="p"&gt;-&lt;/span&gt; Status codes: 200 (ok), 400 (validation), 401 (auth), 404 (missing), 500 (server)
&lt;span class="p"&gt;-&lt;/span&gt; Validation: Zod at route entry. Never trust req.body directly
&lt;span class="p"&gt;-&lt;/span&gt; Auth: Bearer token, validated by middleware before handlers

&lt;span class="gh"&gt;# Error Handling&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Never expose internals (no stack traces, no SQL in responses)
&lt;span class="p"&gt;-&lt;/span&gt; All errors logged via structured logger (src/lib/logger.ts)
&lt;span class="p"&gt;-&lt;/span&gt; Unexpected → 500 with generic message + full internal log

&lt;span class="gh"&gt;# Database&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; All queries through repository pattern (src/repositories/)
&lt;span class="p"&gt;-&lt;/span&gt; Never raw SQL in route handlers
&lt;span class="p"&gt;-&lt;/span&gt; Multi-table writes use db.transaction()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Skip These
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;UI rules, component structure, styling&lt;/li&gt;
&lt;li&gt;Detailed routing conventions (framework handles this)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Type C: CLI Tool
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What Makes It Different
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;stdin/stdout/stderr separation matters&lt;/li&gt;
&lt;li&gt;Argument parsing and help message consistency&lt;/li&gt;
&lt;li&gt;Error messages are user-facing (not developer-facing)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Priority Sections
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# CLI Conventions&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Entry point: src/cli.ts
&lt;span class="p"&gt;-&lt;/span&gt; Argument parsing: use commander/yargs — NOT manual process.argv
&lt;span class="p"&gt;-&lt;/span&gt; Output: normal → stdout, errors → stderr, progress → stderr
&lt;span class="p"&gt;-&lt;/span&gt; Exit codes: 0 = success, 1 = user error, 2 = system error

&lt;span class="gh"&gt;# User-Facing Output&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Errors: explain what's wrong + how to fix it
&lt;span class="p"&gt;-&lt;/span&gt; No stack traces unless --debug flag is set
&lt;span class="p"&gt;-&lt;/span&gt; Colors: only when stdout is TTY (check isTTY)
&lt;span class="p"&gt;-&lt;/span&gt; Progress bars: for operations &amp;gt; 2 seconds

&lt;span class="gh"&gt;# Configuration&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Config: ~/.config/[tool-name]/config.toml (XDG)
&lt;span class="p"&gt;-&lt;/span&gt; CLI flags override config file
&lt;span class="p"&gt;-&lt;/span&gt; Env vars: [TOOL_NAME]_[OPTION] format
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Skip These
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Database rules&lt;/li&gt;
&lt;li&gt;Auth/session management&lt;/li&gt;
&lt;li&gt;UI/styling&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Type D: Library / Package
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What Makes It Different
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Public API stability is the #1 concern&lt;/li&gt;
&lt;li&gt;Backward compatibility and SemVer are non-negotiable&lt;/li&gt;
&lt;li&gt;Documentation (JSDoc/docstrings) is mandatory, not optional&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Priority Sections
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Public API Rules&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; All exports through src/index.ts (barrel file). No deep imports
&lt;span class="p"&gt;-&lt;/span&gt; Every public function: JSDoc with @param, @returns, @example
&lt;span class="p"&gt;-&lt;/span&gt; Breaking changes = major version bump (SemVer strict)
&lt;span class="p"&gt;-&lt;/span&gt; Internal helpers: underscore prefix or src/internal/

&lt;span class="gh"&gt;# Compatibility&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Support: Node &amp;gt;= 18 (or your minimum)
&lt;span class="p"&gt;-&lt;/span&gt; No platform-specific code without fallback
&lt;span class="p"&gt;-&lt;/span&gt; Dependencies pinned to exact versions

&lt;span class="gh"&gt;# Testing (stricter than app projects)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; 100% coverage for public API
&lt;span class="p"&gt;-&lt;/span&gt; Edge cases: null, undefined, empty, large inputs
&lt;span class="p"&gt;-&lt;/span&gt; Type tests with tsd or expect-type

&lt;span class="gh"&gt;# Publishing&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; CHANGELOG.md updated with every PR
&lt;span class="p"&gt;-&lt;/span&gt; Pre-publish: full test + build + type check
&lt;span class="p"&gt;-&lt;/span&gt; Version: use npm version / bump2version / cargo release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Skip These
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Deploy procedures (CI/CD handles this)&lt;/li&gt;
&lt;li&gt;Framework routing/middleware&lt;/li&gt;
&lt;li&gt;Database access&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Quick Decision Chart
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does the project have a UI?
  ├─ Yes → Type A (Web App)
  └─ No
       ├─ Does it serve HTTP? → Type B (API Server)
       ├─ Do users run it from terminal? → Type C (CLI Tool)
       └─ Do other projects import it? → Type D (Library)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For hybrid projects (CLI + API, monorepo), apply the right type to each sub-package independently.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Focus On&lt;/th&gt;
&lt;th&gt;Safe to Skip&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A: Web App&lt;/td&gt;
&lt;td&gt;File placement, UI rules, routing&lt;/td&gt;
&lt;td&gt;Publishing, SemVer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B: API Server&lt;/td&gt;
&lt;td&gt;Response format, error handling, DB&lt;/td&gt;
&lt;td&gt;UI, styling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C: CLI Tool&lt;/td&gt;
&lt;td&gt;Output targets, exit codes, UX&lt;/td&gt;
&lt;td&gt;DB, auth, UI&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;D: Library&lt;/td&gt;
&lt;td&gt;Public API, compatibility, docs&lt;/td&gt;
&lt;td&gt;Deploy, DB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Start With a Template
&lt;/h2&gt;

&lt;p&gt;If you want to skip the setup from scratch:&lt;/p&gt;

&lt;p&gt;🎁 &lt;strong&gt;&lt;a href="https://mairevenue.gumroad.com/l/free-config-starter" rel="noopener noreferrer"&gt;Claude Code Config Starter Pack (FREE)&lt;/a&gt;&lt;/strong&gt; — 3 templates (Next.js, TypeScript Library, Python FastAPI) covering Types A, B, and D.&lt;/p&gt;

&lt;p&gt;🛠️ &lt;strong&gt;&lt;a href="https://mairevenue.gumroad.com/l/mgiiam" rel="noopener noreferrer"&gt;Claude Code Config Pack — 20 Templates ($5)&lt;/a&gt;&lt;/strong&gt; — All 4 types covered across 20 project configurations including Go, Rust, Flutter, Terraform, Django, and more.&lt;/p&gt;

&lt;p&gt;📘 &lt;strong&gt;&lt;a href="https://mairevenue.gumroad.com/l/tmtke" rel="noopener noreferrer"&gt;The AI Coding Prompt Toolkit ($5)&lt;/a&gt;&lt;/strong&gt; — 52 prompts for project setup, implementation, testing, and refactoring.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;What project types do you use CLAUDE.md with? I'd love to hear about configurations for project types I haven't covered — data pipelines, mobile apps, embedded systems, etc.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>5 CLAUDE.md Mistakes That Make Claude Code Ignore Your Rules (and How to Fix Them)</title>
      <dc:creator>shohei-ai-lab</dc:creator>
      <pubDate>Tue, 04 Aug 2026 20:34:08 +0000</pubDate>
      <link>https://dev.to/shohei-ai-lab/5-claudemd-mistakes-that-make-claude-code-ignore-your-rules-and-how-to-fix-them-1hhb</link>
      <guid>https://dev.to/shohei-ai-lab/5-claudemd-mistakes-that-make-claude-code-ignore-your-rules-and-how-to-fix-them-1hhb</guid>
      <description>&lt;p&gt;You wrote a CLAUDE.md. You dropped it in your project root. But Claude Code still uses &lt;code&gt;any&lt;/code&gt;, still picks Express when you wanted Next.js, and still ignores your naming conventions.&lt;/p&gt;

&lt;p&gt;Sound familiar? You're not alone.&lt;/p&gt;

&lt;p&gt;In our &lt;a href="https://dev.to/shohei-ai-lab/5-essential-system-prompt-rules-to-stop-your-ai-agents-from-going-rogue-39mp"&gt;previous article&lt;/a&gt;, we covered 5 rules for designing system prompts. Today we zoom in on a specific file — CLAUDE.md — and the mistakes that make it ineffective.&lt;/p&gt;

&lt;p&gt;After setting up CLAUDE.md configurations across multiple projects in our &lt;a href="https://zenn.dev/shohei_ai_lab" rel="noopener noreferrer"&gt;AI Autonomous Revenue Project&lt;/a&gt;, we identified 5 common failure patterns that explain why your CLAUDE.md "doesn't work" — and how to fix each one.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 1: Writing Aspirations Instead of Instructions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Philosophy&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Clean code is important
&lt;span class="p"&gt;-&lt;/span&gt; We value readability over cleverness
&lt;span class="p"&gt;-&lt;/span&gt; Tests should be comprehensive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reads like a team manifesto, not an instruction set. "Clean code is important" gives Claude Code zero actionable information. What counts as clean? How do you measure it?&lt;/p&gt;

&lt;p&gt;Human teammates can infer meaning from cultural context. AI cannot. It interprets text literally.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Coding Rules&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Functions must be under 30 lines. Extract into smaller functions if longer
&lt;span class="p"&gt;-&lt;/span&gt; Variable names: camelCase, minimum 3 characters (single-letter only for loop counters)
&lt;span class="p"&gt;-&lt;/span&gt; Every public function needs JSDoc with @param and @returns
&lt;span class="p"&gt;-&lt;/span&gt; No nested ternary operators — use if/else or early return
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Principle&lt;/strong&gt;: Write rules that can be evaluated as pass/fail. If you can't check whether it was followed, Claude Code can't follow it either.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Corollary&lt;/strong&gt;: Don't restate what your linter or compiler already enforces. &lt;code&gt;"No any"&lt;/code&gt; belongs in &lt;code&gt;tsconfig.json&lt;/code&gt; with &lt;code&gt;"strict": true&lt;/code&gt; — not in CLAUDE.md. Save your CLAUDE.md context budget for rules that &lt;em&gt;no existing tool can check&lt;/em&gt;: architecture boundaries, cross-file intent, and domain-specific constraints.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 2: Too Much Content (Important Rules Get Buried)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;Your CLAUDE.md is 200+ lines covering everything: stack details, all commands, every directory explained, 80 coding rules, Git workflow, deploy instructions...&lt;/p&gt;

&lt;p&gt;When everything is important, nothing is important. Long configuration files dilute the weight of critical rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# CRITICAL (always follow these)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; TypeScript strict mode. No &lt;span class="sb"&gt;`any`&lt;/span&gt; type ever
&lt;span class="p"&gt;-&lt;/span&gt; Server Components by default. "use client" only with explicit directive
&lt;span class="p"&gt;-&lt;/span&gt; All DB access through src/lib/db/ — never direct Prisma calls in components (RLS is enforced in the db layer)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each CRITICAL rule benefits from a one-clause &lt;strong&gt;"why"&lt;/strong&gt;. The model generalizes better to unseen cases when it understands the &lt;em&gt;reason&lt;/em&gt; behind a constraint — not just the constraint itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Stack&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Next.js 14+ (App Router), TypeScript, Tailwind CSS, Prisma

&lt;span class="gh"&gt;# Commands&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Dev: &lt;span class="sb"&gt;`pnpm dev`&lt;/span&gt; | Build: &lt;span class="sb"&gt;`pnpm build`&lt;/span&gt; | Test: &lt;span class="sb"&gt;`pnpm test`&lt;/span&gt;

&lt;span class="gh"&gt;# Conventions (see docs/ for full details)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Named exports only (except page.tsx/layout.tsx)
&lt;span class="p"&gt;-&lt;/span&gt; Zod schemas in src/schemas/, validated at API boundary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Principle&lt;/strong&gt;: Use a 3-layer structure:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;CRITICAL&lt;/strong&gt; (3–5 rules at the top — these are non-negotiable. Add a short "why" to each)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reference info&lt;/strong&gt; (Stack, Commands — things Claude needs to know)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Details elsewhere&lt;/strong&gt; (link to docs/ for comprehensive conventions)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Key insight&lt;/strong&gt;: Tooling owns everything mechanically checkable (&lt;code&gt;tsconfig&lt;/code&gt;, ESLint, CI). CLAUDE.md owns cross-file intent and architecture boundaries that no default linter knows about.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 3: Listing Tech You Don't Actually Use
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Stack&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Next.js 14 with App Router
&lt;span class="p"&gt;-&lt;/span&gt; NextAuth.js v5 for authentication    ← not installed yet
&lt;span class="p"&gt;-&lt;/span&gt; Prisma + PostgreSQL                   ← actually using Drizzle + SQLite
&lt;span class="p"&gt;-&lt;/span&gt; Redis for caching                     ← planned but not implemented
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claude Code treats CLAUDE.md as ground truth. If you list libraries that don't exist in your project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It imports modules that aren't installed&lt;/li&gt;
&lt;li&gt;It writes code against APIs that aren't available&lt;/li&gt;
&lt;li&gt;It generates structures that contradict your actual setup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This usually happens when you copy a template and forget to customize it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Stack (ACTUALLY INSTALLED — verify against package.json)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Next.js 14 with App Router
&lt;span class="p"&gt;-&lt;/span&gt; Drizzle ORM + SQLite (src/lib/db/schema.ts)
&lt;span class="p"&gt;-&lt;/span&gt; Tailwind CSS + shadcn/ui

&lt;span class="gh"&gt;# NOT AVAILABLE (do not use or suggest these)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; No auth library yet (login handled by basic middleware)
&lt;span class="p"&gt;-&lt;/span&gt; No caching layer (all queries hit DB directly)
&lt;span class="p"&gt;-&lt;/span&gt; No state management library (use React state + URL params)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Principle&lt;/strong&gt;: Only list what's actually installed. Explicitly state what's NOT available — this prevents Claude from suggesting it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 4: Constraints Without Alternatives
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Rules&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Do NOT use any type
&lt;span class="p"&gt;-&lt;/span&gt; Do NOT add new dependencies
&lt;span class="p"&gt;-&lt;/span&gt; Do NOT use class components
&lt;span class="p"&gt;-&lt;/span&gt; Do NOT modify .env files
&lt;span class="p"&gt;-&lt;/span&gt; Do NOT use default exports
&lt;span class="p"&gt;-&lt;/span&gt; Do NOT write inline styles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A list of "don'ts" tells Claude what to avoid, but not what to use instead. If &lt;code&gt;any&lt;/code&gt; is banned, should it use &lt;code&gt;unknown&lt;/code&gt; with type guards? Generics? Explicit type definitions?&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Type Safety&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Never use &lt;span class="sb"&gt;`any`&lt;/span&gt;. Instead:
&lt;span class="p"&gt;  -&lt;/span&gt; External API responses → define with Zod schema, use &lt;span class="sb"&gt;`z.infer&amp;lt;typeof schema&amp;gt;`&lt;/span&gt;
&lt;span class="p"&gt;  -&lt;/span&gt; Unknown runtime values → &lt;span class="sb"&gt;`unknown`&lt;/span&gt; with type guard functions in src/lib/guards/
&lt;span class="p"&gt;  -&lt;/span&gt; Generic containers → TypeScript generics with constraints

&lt;span class="gh"&gt;# Styling&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; No inline styles. Instead:
&lt;span class="p"&gt;  -&lt;/span&gt; Standard styling → Tailwind utility classes
&lt;span class="p"&gt;  -&lt;/span&gt; Conditional styles → &lt;span class="sb"&gt;`clsx()`&lt;/span&gt; or &lt;span class="sb"&gt;`cn()`&lt;/span&gt; from src/lib/utils
&lt;span class="p"&gt;  -&lt;/span&gt; Animations → Tailwind's built-in animation utilities

&lt;span class="gh"&gt;# Dependencies&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; No new deps without justification. Use what's already available:
&lt;span class="p"&gt;  -&lt;/span&gt; Date handling → native Date (no moment/dayjs)
&lt;span class="p"&gt;  -&lt;/span&gt; HTTP → native fetch (no axios)
&lt;span class="p"&gt;  -&lt;/span&gt; Validation → existing Zod setup in src/schemas/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Principle&lt;/strong&gt;: Pair every "don't" with a "do instead". This eliminates ambiguity and gives Claude a clear path forward.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 5: Writing It Once and Never Updating
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;Your CLAUDE.md was written 3 months ago when the project started. Since then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Package manager changed from npm → pnpm&lt;/li&gt;
&lt;li&gt;Test framework switched from Jest → Vitest&lt;/li&gt;
&lt;li&gt;Directory structure was reorganized&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Claude Code now runs &lt;code&gt;npm test&lt;/code&gt; (fails), writes Jest syntax (wrong), and creates files in directories that no longer exist.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fix
&lt;/h3&gt;

&lt;p&gt;Add an update trigger section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Meta&lt;/span&gt;
Last updated: 2026-08-01
Update this file when:
&lt;span class="p"&gt;-&lt;/span&gt; [ ] package.json dependencies change
&lt;span class="p"&gt;-&lt;/span&gt; [ ] Directory structure changes
&lt;span class="p"&gt;-&lt;/span&gt; [ ] New coding conventions are adopted
&lt;span class="p"&gt;-&lt;/span&gt; [ ] CI/CD pipeline changes
&lt;span class="p"&gt;-&lt;/span&gt; [ ] Test framework or build tools change
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Principle&lt;/strong&gt;: CLAUDE.md is a living document. Review it monthly or whenever your project setup changes. Outdated instructions are worse than no instructions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Checklist: Does Your CLAUDE.md Actually Work?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Rules are concrete and pass/fail testable (not aspirational)&lt;/li&gt;
&lt;li&gt;[ ] CRITICAL section exists with ≤5 rules at the top of the file&lt;/li&gt;
&lt;li&gt;[ ] Every tech in Stack section is actually installed (check package.json)&lt;/li&gt;
&lt;li&gt;[ ] Every "don't" has a corresponding "do instead"&lt;/li&gt;
&lt;li&gt;[ ] File was reviewed within the last 30 days&lt;/li&gt;
&lt;li&gt;[ ] Total length is under 100 lines (details are in separate docs)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;If you want to skip the trial-and-error of writing CLAUDE.md from scratch:&lt;/p&gt;

&lt;p&gt;🎁 &lt;strong&gt;&lt;a href="https://mairevenue.gumroad.com/l/free-config-starter" rel="noopener noreferrer"&gt;Claude Code Config Starter Pack (FREE)&lt;/a&gt;&lt;/strong&gt; — 3 templates (Next.js, TypeScript Library, Python FastAPI) that follow all the principles above.&lt;/p&gt;

&lt;p&gt;🛠️ &lt;strong&gt;&lt;a href="https://mairevenue.gumroad.com/l/mgiiam" rel="noopener noreferrer"&gt;Claude Code Config Pack — 20 Templates ($5)&lt;/a&gt;&lt;/strong&gt; — Docker-verified configurations for 20 project types including Go, Rust, Flutter, Terraform, and more.&lt;/p&gt;

&lt;p&gt;📘 &lt;strong&gt;&lt;a href="https://mairevenue.gumroad.com/l/tmtke" rel="noopener noreferrer"&gt;The AI Coding Prompt Toolkit ($5)&lt;/a&gt;&lt;/strong&gt; — 52 structured prompts for project setup, feature implementation, testing, and refactoring.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;What CLAUDE.md mistakes have you encountered? Drop a comment below — I'd love to hear about patterns I missed.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>5 Essential System Prompt Rules to Stop Your AI Agents from Going Rogue</title>
      <dc:creator>shohei-ai-lab</dc:creator>
      <pubDate>Tue, 04 Aug 2026 00:01:40 +0000</pubDate>
      <link>https://dev.to/shohei-ai-lab/5-essential-system-prompt-rules-to-stop-your-ai-agents-from-going-rogue-39mp</link>
      <guid>https://dev.to/shohei-ai-lab/5-essential-system-prompt-rules-to-stop-your-ai-agents-from-going-rogue-39mp</guid>
      <description>&lt;p&gt;We are in the era of autonomous AI agents. Tools like Claude Code, Cline, Cursor, and other agentic coding frameworks are replacing simple Q&amp;amp;A chat interfaces. They can read your workspace, run shell commands, write code, and execute tests.&lt;/p&gt;

&lt;p&gt;However, with great power comes great chaos. Every developer using AI agents eventually faces these frustrating moments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;The Loop of Doom&lt;/strong&gt;: Your agent gets stuck in a compilation-error loop, burning your API credits.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The Overzealous Refactor&lt;/strong&gt;: The agent rewrites unrelated files, breaking your main branch.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The Hallucination&lt;/strong&gt;: The agent claims "all tests passed" when they didn't even run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These issues are not failures of the AI models themselves—they are &lt;strong&gt;system prompt failures&lt;/strong&gt;. Just like human developers, AI agents need clear boundaries, explicit constraints, and rigorous execution rules to perform at their best.&lt;/p&gt;

&lt;p&gt;Based on our ongoing experiment, &lt;strong&gt;AI Autonomous Revenue Project&lt;/strong&gt; (where we build and iterate on web products using AI agent workflows with structural verification), we compiled 5 core rules for designing system prompts for AI agents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Rule 1: Tighten the Role and Grant Specific Authority
&lt;/h2&gt;

&lt;p&gt;Instead of a generic role like &lt;em&gt;"You are a world-class software engineer,"&lt;/em&gt; define a highly specialized domain expert with distinct behavioral boundaries.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Weak&lt;/strong&gt;: &lt;em&gt;"You are a senior full-stack developer."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Strong&lt;/strong&gt;: &lt;em&gt;"You are a strict, no-nonsense senior backend engineer specializing in Next.js, Prisma, and PostgreSQL. Your coding style is minimal, avoiding any unnecessary helper libraries or duplicate imports."&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Rule 2: Explicitly Restrict File System Mutability
&lt;/h2&gt;

&lt;p&gt;AI agents have powerful file-writing tools. If left unrestricted, they will modify configuration files, GitHub actions, or package dependencies in unexpected ways. You must establish write-protected zones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;### Write-Protected Files (Read-Only)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`package.json`&lt;/span&gt; and &lt;span class="sb"&gt;`package-lock.json`&lt;/span&gt; (Any dependency update requires explicit human approval)
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`.github/workflows/`&lt;/span&gt; (Never modify CI pipelines)
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`tsconfig.json`&lt;/span&gt; and linter configurations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Rule 3: Design for Non-Determinism (Stochastic Behavior)
&lt;/h2&gt;

&lt;p&gt;Large Language Models are probabilistic. Never assume the agent's action will succeed on the first try. Your system prompt must define a &lt;strong&gt;fallback protocol&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Bad&lt;/strong&gt;: &lt;em&gt;"Fetch the API data and save it to the database."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Good&lt;/strong&gt;: &lt;em&gt;"When calling the external API, write error-handling logic with exponential backoff up to 3 retries. If the call still fails, write the complete error payload to &lt;code&gt;logs/error.log&lt;/code&gt; and stop the task."&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Rule 4: Mandate Automated Evidence Preservation (No Verbal Claims)
&lt;/h2&gt;

&lt;p&gt;Agents are prone to hallucinating task completion. Do not allow them to just say &lt;em&gt;"Everything is working!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Force the agent to execute real tests and &lt;strong&gt;preserve the output files&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Require the agent to output shell execution logs, test suite status codes, and built artifact hashes to a designated folder (e.g., &lt;code&gt;verification/results/&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;  The system prompt should state: &lt;em&gt;"A task is only considered done when the corresponding test runner output file is generated and matches the expected schema."&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Rule 5: Enforce Tool-specific Multi-Line Editing
&lt;/h2&gt;

&lt;p&gt;When editing multiple non-contiguous lines of code, agents often break code files using simple single-line replacements. Instruct them to use multi-replace tools or structural parsers specifically designed for non-adjacent lines. This preserves file integrity and prevents syntax breakage.&lt;/p&gt;




&lt;h2&gt;
  
  
  Further Reading &amp;amp; Resources
&lt;/h2&gt;

&lt;p&gt;We put these 5 rules into practice in our daily workflow. If you want to dive deeper into agent instruction design or jumpstart your agentic workflow with structurally verified prompts, here are some resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Free: AI Agent Config Starter Pack&lt;/strong&gt; — A free starter set of agent configuration files, format-checked and ready for customization. Grab it on &lt;a href="https://mairevenue.gumroad.com/l/free-config-starter" rel="noopener noreferrer"&gt;Gumroad&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Zenn Book (Japanese): AI Agent Instruction Design&lt;/strong&gt; — A comprehensive guide covering instruction architecture for AI coding agents, with practical examples. Read it on &lt;a href="https://zenn.dev/shohei_ai_lab/books/7ba75032da798d" rel="noopener noreferrer"&gt;Zenn&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The AI Coding Prompt Toolkit&lt;/strong&gt; — A curated collection of 50+ system prompts and templates for coding, testing, and system design, structurally verified via automated format checks. Available on &lt;a href="https://mairevenue.gumroad.com/l/tmtke" rel="noopener noreferrer"&gt;Gumroad&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We'll keep sharing what we learn as we iterate on autonomous agent workflows. Follow along and let us know what rules have worked for you!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
