cd /news/ai-tools/one-claude-md-doesn-t-fit-every-proj… · home › topics › ai-tools › article
[ARTICLE · art-174728] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

One CLAUDE.md Doesn't Fit Every Project: Split Your Templates by Situation, Not by Stack

A freelance developer reorganized their Claude Code CLAUDE.md templates around project situations — new projects, inherited codebases, and billable client work — rather than tech stacks, arguing that working rules depend on risk profile rather than framework. They also published a PreToolUse Bash hook that blocks commands touching .env, .envrc, credentials.json and similar secret files, since settings.json deny rules only cover file tools, not shell commands. The hook strips .env.example from the command string before matching so template reads pass while real secrets files are blocked.

recommendation

Pair settings.json deny rules on .env with a PreToolUse Bash hook that exits 2 on commands touching .env, .envrc or credentials files, stripping .env.example before matching.

more in playbook: Securing agents and AI tools
by read5 min views1 publishedNov 23, 2026

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.

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

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 .env files from leaking into the session through Bash.

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:

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:

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.

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:

A few habits that made this work in practice:

<angle brackets> is a rule Claude can't act on yet. Project name, actual build/test commands, where backups live — the specifics are the point.~/.claude/CLAUDE.md. Rules that are about 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.

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

cat .env
grep -r "API_KEY" .
cp .env /tmp/backup/

A PreToolUse hook can watch the Bash tool specifically and block any command that touches .env-style files. Here's the one I use, in full:

#!/usr/bin/env bash
#

set -euo pipefail

input=$(cat)
tool=$(printf '%s' "$input" | jq -r '.tool_name // empty')

[ "$tool" = "Bash" ] || exit 0

command=$(printf '%s' "$input" | jq -r '.tool_input.command // empty')

rest="${command//.env.example/}"

case "$rest" in
  *".env"* | *".envrc"* | *"credentials.json"* | *"service-account"*.json* | *".npmrc"* | *".aws/credentials"*)
    echo "Blocked by hook (possible secret access): ${command}" >&2
    echo "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." >&2
    exit 2
    ;;
esac

exit 0

Wire it up in .claude/settings.json like this:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/guard-env-files.sh" }
        ]
      }
    ]
  }
}

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

Two design choices worth pointing out:

.env.example stays readable.cat .env.example passes.cp .env.example .env is blocked on purpose. And when you genuinely need to know what's in an .env — usually it's which keys exist, not their values — read it yourself and paste the key names into the conversation. The values rarely need to enter the chat at all.

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

These templates and hooks are the core of a kit I put together for my own client work and now sell as the Claude Code Freelance Field Kit ($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.

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.

https://osakadxlabo.gumroad.com/l/claude-code-freelance-field-kit

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.

── more in #ai-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/one-claude-md-doesn-…] indexed:0 read:5min 2026-11-23 · —