Skip to content

feat: add blockEnvFiles hook to prevent access to .env files#1

Merged
timoconnellaus merged 3 commits intomasterfrom
feature/extensions
Jul 8, 2025
Merged

feat: add blockEnvFiles hook to prevent access to .env files#1
timoconnellaus merged 3 commits intomasterfrom
feature/extensions

Conversation

@timoconnellaus
Copy link
Owner

Summary

  • Adds a new predefined hook blockEnvFiles that prevents reading or writing to .env files
  • Allows access to example env files (.env.example, .env.sample, etc.)
  • Provides clear error messages when access is blocked

Implementation Details

  • Works with Read, Write, Edit, and MultiEdit tools
  • Uses regex patterns to identify .env files and their variants
  • Includes comprehensive test coverage (18 test cases, all passing)

Usage

import { defineHooks, blockEnvFiles } from '@timoaus/define-claude-code-hooks';

export default defineHooks({
  PreToolUse: [
    blockEnvFiles, // Protects sensitive .env files
  ],
});

Test Plan

  • Blocks access to .env files
  • Blocks access to .env variants (.env.local, .env.production, etc.)
  • Allows access to example files (.env.example, .env.sample, etc.)
  • Works with all file operation tools (Read, Write, Edit, MultiEdit)
  • Ignores non-file tools (Bash, WebFetch, etc.)
  • Provides clear error messages

🤖 Generated with Claude Code

timoconnellaus and others added 3 commits July 8, 2025 13:17
- Creates new predefined hook that blocks reading/writing of .env files
- Allows access to example env files (.env.example, .env.sample, etc.)
- Works with Read, Write, Edit, and MultiEdit tools
- Includes comprehensive documentation and usage examples

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@timoconnellaus timoconnellaus merged commit 9b198ff into master Jul 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant