AETERNAE AI RESEARCH LLC INDEPENDENT RESEARCH
ÆAETERNAERESEARCH
Sign inRequest access
← Malware catalog

Attributed metadata history

REPORTPUBLIC METADATA

Keep Claude Code out of .env and .git: deny rules or a 29-line hook

The first guide in this series built a hook that blocks recursive deletes in the shell. A reader pointed out the gap it leaves: a hook on the shell tools sees nothing when the agent changes a file with its edit tools. It can empty .env, rewrite .git/config, or edit .claude/settings.json and switch the guard itself off, without running one command. Claude Code has two tools for this, a deny rule and a hook. This post sets up both, shows the test run for the hook, and then shows what happened when real sessions were asked to change .env. The formats were checked against the Claude Code reference on 27 November 2026, and the sessions ran on Claude Code 2.1.332. What Claude Code already does Some paths are protected with no setup at all. The reference lists folders such as .git and .claude, and files such as .gitconfig and .mcp.json. In the default mode and in acceptEdits mode, a write to one of them asks you first. In bypassPermissions mode it is allowed. Two things are left open. .env is not on that list (.envrc is). And a prompt only helps when a person is there to read it. The simple tool: a deny rule A deny rule is a line in .claude/settings.json: { "permissions": { "deny": [ "Edit(/.env)", "Edit(/.env.*)" ] } } An Edit rule covers every built-in tool that edits files, so the Write tool is included. The patterns use gitignore syntax. The slash in front means the folder the settings file belongs to, which is the project for a project's settings. Claude Code enforces these rules itself; the model does not get a vote. The second tool: a hook A PreToolUse hook is a program that Claude Code runs before a tool call. It reads the call as JSON and can answer "deny" with a reason. What the hook receives For an edit, these are the fields that matter: { "hook_event_name": "PreToolUse", "tool_name": "Edit", "cwd": "/work/project", "tool_input": { "file_path": "/work/project/.env", "old_string": "DEBUG=0", "new_string": "DEBUG=1" } } The Write tool sends file_path and content. The notebook tool, NotebookEdit, names its path notebook_path. The reference says file_path is always absolute for the file tools: Claude Code expands ~ and relative paths before the hook runs, so a rule on paths cannot be dodged that way. The answer is the same as in the first guide: print a deny decision with a reason and exit with code 0, or print nothing to let the usual permission check carry on. The hook Save this as .claude/hooks/no-touch.mjs in your project: import { readFileSync } from 'node:fs'; import path from 'node:path'; // Claude Code writes the tool call to standard input as JSON. A pipe from Windows PowerShell can put a mark in front. let call; try { call = JSON.parse(readFileSync(0, 'utf8').replace(/^\uFEFF/, '')); } catch { process.exit(0); } const file = call?.tool_input?.file_path ?? call?.tool_input?.notebook_path; if (!['Edit', 'Write', 'NotebookEdit'].includes(call?.tool_name) || typeof file !== 'string') process.exit(0); // The path as the project sees it: from the project folder down, forward slashes, lower case. const root = process.env.CLAUDE_PROJECT_DIR || call.cwd || process.cwd(); const where = path.relative(root, path.resolve(root, file)).split(path.sep).join('/').toLowerCase(); const RULES = [ ['part of the git folder', /(^|\/)\.git(\/|$)/], ['one of the settings or hooks that guard this project', /(^|\/)\.claude\/(settings(\.local)?\.json$|hooks\/)/], ['a file of secrets', /(^|\/)\.env(\.(?!(example|sample|template)$)[^/]+)?$/], ]; const hit = RULES.find(([, pattern]) => pattern.test(where)); if (!hit) process.exit(0); // no opinion: the usual permission check carries on console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: `Blocked by no-touch.mjs: ${where} is ${hit[0]}, and only the human changes it. ` +

Reference details

Source category
research-report
First reported
Nov 27, 2026 17:49 UTC
Last reported
Nov 27, 2026 17:49 UTC
Catalog updated
Nov 27, 2026 17:55 UTC
Record ID
2f063d47113ddfed8309d91b94d93c45d495acd11a91ab8443217ad6ca9ad41b

Published indicators

Network indicators are visibly defanged. This page does not make them clickable or send them to another service.

No validated file hashes or network indicators are stored for this record.

Source observations

intelligence_src_6dc544294b7f21f98a

Source-provided label
Publisher RSS metadata
Evidence class
mentioned in report
Confidence
Not reported
Observed
Nov 27, 2026 17:49 UTC
Retrieved
Nov 27, 2026 17:55 UTC

This record contains metadata and attribution only. It does not host, download, unpack, render, or execute malware samples.

Feed collection status

Sources represented on this page. Publication and observation dates describe the content; successful batch dates describe local collection. A recent batch does not certify complete coverage or current provider availability.

1 sources: 0 stale, 0 needing attention, 0 paused, 0 unverified.

Review source update dates and status
  • intelligence_src_6dc544294b7f21f98aRecent successful batchLast successful batch: Last attempt:

Stale means older than twice the recorded collection interval, with a minimum of one hour; without an interval, the threshold is 24 hours. Cached content remains available while a feed is stale, paused, or unverified.