Skip to content

Pre Tool Use

Configuration for pre-tool-use hooks that run before tools are executed.

All file protection rules are consolidated in this section to prevent Claude from making unintended modifications to protected files, directories, or executing dangerous commands.

Custom message when blocking file edits with generation markers.

Available placeholders: - {file_path} - The path to the file being blocked - {marker} - The generation marker that was detected

yaml generatedFileMessage: "Cannot modify {file_path} - it contains '{marker}' marker"

Default: null (uses a generic error message)

AttributeValue
Type`string
Defaultnull

Examples:

generatedFileMessage: "Cannot modify {file_path} - it contains '{marker}' marker"

Directories where file additions are prevented (in addition to root if preventRootAdditions is enabled).

List of directory paths where new files cannot be created. Useful for protecting build output directories or other generated content.

AttributeValue
Typearray
Default[]

Examples:

preventAdditions: - "dist" - "build" - "node_modules"

Prevent editing of files with generation markers (enabled by default).

When enabled, checks for common markers like “DO NOT EDIT”, “Code generated by”, “@generated”, etc. in file contents before allowing edits.

Default: true

AttributeValue
Typeboolean
Defaulttrue

Prevent Claude from creating or modifying files at the repository root.

Helps maintain clean project structure by preventing clutter at the root level. This is a security best practice to avoid accidental modification of important configuration files.

Default: true

AttributeValue
Typeboolean
Defaulttrue

Block Claude from modifying or creating files that match .gitignore patterns.

When enabled, files matching patterns in .gitignore will be protected. Uses your existing .gitignore as the source of truth for file protection.

Default: false

AttributeValue
Typeboolean
Defaultfalse

Tool usage validation rules for fine-grained control over tool usage.

Allows controlling which tools can be used on which files or with which command patterns. Rules are evaluated in order.

AttributeValue
Typearray
Default[]

Examples:

toolUsageValidation: # Allow writing to JavaScript files - tool: "Write" pattern: "**/*.js" action: "allow"
# Block environment file modifications - tool: "*" pattern: ".env*" action: "block" message: "Environment files cannot be modified"
# Block dangerous git operations - tool: "Bash" commandPattern: "git push --force*" action: "block" message: "Force push is not allowed"

Files that Claude cannot edit, using glob patterns.

Supports various glob patterns for flexible file protection. By default, conclaude’s own config files are protected to prevent the AI from modifying guardrail settings - this is a security best practice.

Supports two formats: 1. Simple string patterns: "*.lock" 2. Detailed objects with custom messages: {pattern: "*.lock", message: "..."}

AttributeValue
Typearray
Default[]

Examples:

uneditableFiles: - ".conclaude.yml" # Protect config - ".conclaude.yaml" # Alternative extension - "*.lock" # Lock files - pattern: ".env*" message: "Environment files contain secrets. Use .env.example instead."

This section uses the following nested type definitions:

Tool usage validation rule for fine-grained control over tool usage based on file patterns.

Allows controlling which tools can be used on which files or with which command patterns. Rules are evaluated in order and the first matching rule determines the action.

Properties:

PropertyTypeDefaultDescription
actionstring-Action to take when the rule matches: “allow” or “block”
commandPattern`stringnull`-
matchMode`stringnull`-
message`stringnull`-
patternstring-File path pattern to match
toolstring-The tool name to match against

Configuration for an uneditable file rule.

Files that Claude cannot edit, using glob patterns. Supports various glob patterns for flexible file protection.

Two formats are supported for backward compatibility:

  1. Simple string patterns: "*.lock" - Just the glob pattern as a string - Uses a generic error message when blocking

  2. Detailed objects with custom messages: {pattern: "*.lock", message: "..."} - Allows specifying a custom error message - More descriptive feedback when files are blocked

Variants:

  1. object: Detailed format with pattern and optional custom message.

Allows providing a custom error message that will be shown when Claude attempts to edit a file matching this pattern.

Properties:

  • message (string | null): Optional custom message to display when blocking edits to matching files
  • pattern (string): Glob pattern matching files to protect (e.g., “.lock”, “.env”, “src/**/*.ts”)
  1. string: Simple format: just a glob pattern string.

Uses a generic error message when blocking file edits. Backward compatible with existing configurations.

Here are complete configuration examples for the preToolUse section:

preToolUse: # Prevent root-level file creation preventRootAdditions: true
# Protect specific files with glob patterns uneditableFiles: - ".conclaude.yml" - "*.lock" - pattern: ".env*" message: "Environment files contain secrets"
# Prevent modifications to git-ignored files preventUpdateGitIgnored: false
# Fine-grained tool control toolUsageValidation: - tool: "Bash" commandPattern: "git push --force*" action: "block" message: "Force push is not allowed"
# Block additions to specific directories preventAdditions: - "dist" - "build"
# Protect generated files preventGeneratedFileEdits: true generatedFileMessage: "Cannot modify {file_path} - it contains '{marker}'"