<?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: Osaka_WebDeveloper</title>
    <description>The latest articles on DEV Community by Osaka_WebDeveloper (@osaka_dx_engineer).</description>
    <link>https://dev.to/osaka_dx_engineer</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%2F4260765%2Fa24d21b4-2892-4557-a1d6-12e2763d1659.png</url>
      <title>DEV Community: Osaka_WebDeveloper</title>
      <link>https://dev.to/osaka_dx_engineer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/osaka_dx_engineer"/>
    <language>en</language>
    <item>
      <title>One CLAUDE.md Doesn't Fit Every Project: Split Your Templates by Situation, Not by Stack</title>
      <dc:creator>Osaka_WebDeveloper</dc:creator>
      <pubDate>Mon, 23 Nov 2026 14:12:07 +0000</pubDate>
      <link>https://dev.to/osaka_dx_engineer/one-claudemd-doesnt-fit-every-project-split-your-templates-by-situation-not-by-stack-1jfi</link>
      <guid>https://dev.to/osaka_dx_engineer/one-claudemd-doesnt-fit-every-project-split-your-templates-by-situation-not-by-stack-1jfi</guid>
      <description>&lt;p&gt;Most CLAUDE.md templates you'll find are organized by stack: one for React, one for Laravel, one for Rails. When I started using Claude Code for freelance client work, I collected a few of those — and then barely used them.&lt;/p&gt;

&lt;p&gt;The problem wasn't the stack sections. It was that the &lt;em&gt;working rules&lt;/em&gt; I actually needed had almost nothing to do with the framework. They depended on the situation the project was in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Am I &lt;strong&gt;building something new&lt;/strong&gt;, where the conventions are mine to set?&lt;/li&gt;
&lt;li&gt;Am I &lt;strong&gt;maintaining code I didn't write&lt;/strong&gt;, where the priority is not breaking a live system?&lt;/li&gt;
&lt;li&gt;Is this &lt;strong&gt;billable client work&lt;/strong&gt;, where scope, approvals, and handover matter as much as the code?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same stack, three completely different rule sets. So I reorganized my templates around situations instead. This post walks through what changes between them, and then covers a second, more mechanical safeguard: a hook that stops &lt;code&gt;.env&lt;/code&gt; files from leaking into the session through Bash.&lt;/p&gt;

&lt;h2&gt;
  
  
  Situation 1: Greenfield — the rules are yours, so state them
&lt;/h2&gt;

&lt;p&gt;On a new project, Claude Code will happily invent conventions if you don't provide any — a different error-handling style in every file, tests for some features and not others. The template's job is to be opinionated early, while decisions are still cheap:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Set the conventions explicitly.&lt;/strong&gt; Directory layout, naming, how errors are raised and logged, configuration only through environment variables. Vague rules ("write clean code") do nothing; concrete ones get followed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decide what's reversible and what isn't.&lt;/strong&gt; My greenfield template tells Claude: reversible decisions, just make them and note what you chose. Lasting ones — data model, public API shape, auth approach — present the options and trade-offs and ask first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing is part of "done."&lt;/strong&gt; Every new feature ships with tests for its core behavior, and the full suite runs before anything is called finished.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the file alive.&lt;/strong&gt; When a convention changes, the CLAUDE.md changes in the same commit. A stale rule is worse than a missing one, because it teaches the agent to ignore the file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Situation 2: Legacy maintenance — assume everything weird is weird for a reason
&lt;/h2&gt;

&lt;p&gt;Inherited codebases flip most of that on its head. Here the expensive mistake isn't inconsistency, it's breaking something that was working in production. The rules get defensive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Assume every odd-looking piece of code is odd for a reason&lt;/strong&gt; until proven otherwise. Before "cleaning up" something strange, find out what breaks without it — history, comments, the people who use the system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Change one thing at a time.&lt;/strong&gt; Bundled changes make incidents impossible to attribute.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No opportunistic refactoring.&lt;/strong&gt; If a fix requires touching shared code, say so and get the scope agreed &lt;em&gt;before&lt;/em&gt; starting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production is approval-gated.&lt;/strong&gt; Present the scope of impact and the rollback plan first. Verify in staging, confirm today's backup exists, then deploy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understand before touching.&lt;/strong&gt; For an unfamiliar area, the first deliverable is a map — what calls this, what it writes to, what depends on it — and ideally a characterization test that captures current behavior before anyone changes it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that none of this mentions a framework. A legacy Laravel app and a legacy Next.js app need almost identical rules, because the risk profile is the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Situation 3: Client projects — the engagement rules live here too
&lt;/h2&gt;

&lt;p&gt;Billable work adds a layer that has nothing to do with code at all, and it's the layer where freelancers actually lose money. My client-project template carries it alongside the technical rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope discipline.&lt;/strong&gt; When a request arrives that isn't in the estimate, don't quietly absorb it. Summarize the request, estimate its size, and draft the message asking for approval — before starting. (Drafts only: the template also says never send client messages from a tool. Sending is a human action.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Surface size problems early.&lt;/strong&gt; If something in scope turns out to be much larger than estimated, stop and report as soon as that's clear — not at the deadline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep a work log as you go.&lt;/strong&gt; Date, hours, what was done. Reconstructing hours at invoice time is where billable time quietly evaporates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Define "delivered" up front.&lt;/strong&gt; What the client receives at handover — code, a handover summary, account and ownership info, renewal dates for domains and certificates — is written down at the start, not negotiated at the end.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client material stays in the folder.&lt;/strong&gt; Anything the client provided is confidential and doesn't get reused in other projects or examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Making the templates usable
&lt;/h2&gt;

&lt;p&gt;A few habits that made this work in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fill in every placeholder.&lt;/strong&gt; Anything left in &lt;code&gt;&amp;lt;angle brackets&amp;gt;&lt;/code&gt; is a rule Claude can't act on yet. Project name, actual build/test commands, where backups live — the specifics are the point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete sections that don't apply.&lt;/strong&gt; A shorter CLAUDE.md that matches reality beats a complete one that doesn't. Stale rules get ignored along with the good ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Layer your personal rules separately.&lt;/strong&gt; Claude Code also reads &lt;code&gt;~/.claude/CLAUDE.md&lt;/code&gt;. Rules that are about &lt;em&gt;you&lt;/em&gt; — communication style, commit habits, "always ask before deploying" — belong there, not copied into every project file. Project files should hold project facts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The mechanical half: keeping .env out of Bash
&lt;/h2&gt;

&lt;p&gt;CLAUDE.md is instruction, not enforcement — it guides judgment, but it isn't a lock. Secrets are the clearest example of why that distinction matters.&lt;/p&gt;

&lt;p&gt;The obvious safeguard is permission rules in &lt;code&gt;.claude/settings.json&lt;/code&gt;: deny &lt;code&gt;Read&lt;/code&gt; and &lt;code&gt;Edit&lt;/code&gt; on &lt;code&gt;.env&lt;/code&gt; files. That covers the file tools. It does &lt;strong&gt;not&lt;/strong&gt; cover Bash. Secrets leak through shell commands all the time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat .env
grep -r &lt;span class="s2"&gt;"API_KEY"&lt;/span&gt; .
cp .env /tmp/backup/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A PreToolUse hook can watch the Bash tool specifically and block any command that touches &lt;code&gt;.env&lt;/code&gt;-style files. Here's the one I use, in full:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# PreToolUse hook: keep .env files and credential files out of Claude's hands.&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;# Why a hook in addition to the Read/Edit deny rules in settings.json:&lt;/span&gt;
&lt;span class="c"&gt;#   Permission rules govern the file tools, but secrets also leak through Bash —&lt;/span&gt;
&lt;span class="c"&gt;#   `cat .env`, `grep -r KEY .`, `cp .env somewhere`. This hook watches Bash commands&lt;/span&gt;
&lt;span class="c"&gt;#   that touch .env-style files and blocks them.&lt;/span&gt;
&lt;span class="c"&gt;# How .env.example is handled:&lt;/span&gt;
&lt;span class="c"&gt;#   The example file (dummy values, meant to be shared) is stripped from the command&lt;/span&gt;
&lt;span class="c"&gt;#   string before matching, so `cat .env.example` passes. Anything left that still&lt;/span&gt;
&lt;span class="c"&gt;#   mentions a real .env file is blocked — including `cp .env.example .env`. That one&lt;/span&gt;
&lt;span class="c"&gt;#   is a legitimate first-run setup step; run it manually in your own terminal.&lt;/span&gt;
&lt;span class="c"&gt;#   Creating the real secrets file is a human moment anyway.&lt;/span&gt;
&lt;span class="c"&gt;# How it works:&lt;/span&gt;
&lt;span class="c"&gt;#   Same pattern as block-dangerous-bash.sh — JSON on stdin, .tool_input.command,&lt;/span&gt;
&lt;span class="c"&gt;#   exit code 2 blocks execution.&lt;/span&gt;
&lt;span class="c"&gt;# Requires: jq must be installed.&lt;/span&gt;
&lt;span class="c"&gt;# How to adjust: if your project stores secrets under a different name (.envrc,&lt;/span&gt;
&lt;span class="c"&gt;#         credentials.json, service-account.json), add it to the pattern list below.&lt;/span&gt;

&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail

&lt;span class="nv"&gt;input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;cat&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;tool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s'&lt;/span&gt; &lt;span class="s2"&gt;"$input"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; jq -r &lt;span class="s1"&gt;'.tool_name // empty'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# Only Bash needs this hook; the file tools are covered by settings.json deny rules.&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$tool"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Bash"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 0

&lt;span class="nv"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s'&lt;/span&gt; &lt;span class="s2"&gt;"$input"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; jq -r &lt;span class="s1"&gt;'.tool_input.command // empty'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# Remove the shareable template name before matching, so it alone never triggers a block.&lt;/span&gt;
&lt;span class="nv"&gt;rest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"${command//.env.example/}"&lt;/span&gt;

&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"$rest"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
  *&lt;span class="s2"&gt;".env"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;".envrc"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;"credentials.json"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;"service-account"&lt;/span&gt;*.json* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;".npmrc"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;".aws/credentials"&lt;/span&gt;*&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Blocked by hook (possible secret access): ${command}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Commands that touch .env / credential files are blocked. If you need a value from one, ask the user to provide it another way; if you were creating .env from .env.example, run that one command manually."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;exit&lt;/span&gt; 2
    &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;

&lt;span class="nb"&gt;exit&lt;/span&gt; 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wire it up in &lt;code&gt;.claude/settings.json&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Bash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/guard-env-files.sh"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the script under &lt;code&gt;.claude/hooks/&lt;/code&gt;, &lt;code&gt;chmod +x&lt;/code&gt; it, and make sure &lt;code&gt;jq&lt;/code&gt; is installed. Exit code 2 from a PreToolUse hook blocks the tool call and feeds the stderr message back to Claude, so it understands &lt;em&gt;why&lt;/em&gt; it was stopped and can suggest an alternative instead of retrying blindly.&lt;/p&gt;

&lt;p&gt;Two design choices worth pointing out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.env.example&lt;/code&gt; stays readable.&lt;/strong&gt; It's the shareable template with dummy values, so the hook strips that exact name from the command string before matching. &lt;code&gt;cat .env.example&lt;/code&gt; passes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;cp .env.example .env&lt;/code&gt; is blocked on purpose.&lt;/strong&gt; It's a legitimate setup step — but creating the real secrets file is a moment a human should own, so you run that one command yourself in your own terminal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And when you genuinely need to know what's in an &lt;code&gt;.env&lt;/code&gt; — usually it's &lt;em&gt;which keys exist&lt;/em&gt;, not their values — read it yourself and paste the key names into the conversation. The values rarely need to enter the chat at all.&lt;/p&gt;

&lt;p&gt;If your project keeps secrets under different names (&lt;code&gt;.envrc&lt;/code&gt;, &lt;code&gt;credentials.json&lt;/code&gt;, a service-account file), add them in both places: the settings.json deny list &lt;em&gt;and&lt;/em&gt; the hook's pattern list. They guard different doors — file tools versus Bash — and a secrets file needs both doors watched.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this setup lives
&lt;/h2&gt;

&lt;p&gt;These templates and hooks are the core of a kit I put together for my own client work and now sell as the &lt;strong&gt;Claude Code Freelance Field Kit&lt;/strong&gt; ($29 on Gumroad): the four situation-based CLAUDE.md templates, five skills (bug investigation, code review, refactor planning, test-adding, handover documents), three hooks including the one above and a dangerous-command blocker, plus the client-work paperwork — estimate research, progress update, and scope clarification prompts, delivery/security/handover checklists, and work-log and estimate templates.&lt;/p&gt;

&lt;p&gt;Full disclosure: I'm the seller. The two ideas in this post — situation-based templates and the .env guard hook — are complete as they stand, whether or not the kit is useful to you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://osakadxlabo.gumroad.com/l/claude-code-freelance-field-kit" rel="noopener noreferrer"&gt;https://osakadxlabo.gumroad.com/l/claude-code-freelance-field-kit&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: This post was drafted with AI assistance and reviewed and edited by me. The configurations and hook script are from my own working setup.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
