Claude Code hook

Claude Ignore

A Claude Code PreToolUse hook that prevents Claude from reading files that match patterns in .claudeignore files, similar to how .gitignore works.

47 stars 8 forksHooks Source

Install

Install
npm install -g claudeignore

Found in the project README. Check it for setup steps after installing.

From source
git clone https://github.com/li-zhixin/claude-ignore.git

From the README

claude-ignore

A Claude Code PreToolUse hook that prevents Claude from reading files that match patterns in .claudeignore files, similar to how .gitignore works.

中文说明 / Chinese Documentation

Features

- Hierarchical .claudeignore support: Automatically discovers and applies .claudeignore files from the current directory up to the root
- Supports standard gitignore-style patterns
- Works as a Claude Code PreToolUse hook
- Exits with code 2 when a path is ignored, preventing Claude from reading the file
- Filters out comments (lines starting with #) and empty lines
- Flexible project configuration with multiple ignore levels

Installation

Install globally to use across all projects:

To update to the latest version:

Quick Start

Option 1: Auto Setup (Recommended)

Run the init command in your project directory:

This will:

- Create a .claudeignore file if it doesn't exist
- Set up .claude/settings.json with the necessary hook configuration
- If .claude/settings.json already exists, it will show you the template configuration for manual merging

Option 2: Manual Setup

1. Create a .claudeignore file in your project root with patterns to ignore:

2. Configure Claude Code to use this as a PreToolUse hook by adding to .claude/settings.json:

Commands

claude-ignore init

Initializes claude-ignore configuration in your project:

- Creates .claudeignore file from template if it doesn't exist
- Creates .claude/settings.json with hook configuration if it doesn't exist
- Shows template configuration for manual merging if .claude/settings.json already exists

claude-ignore (default)

Checks if a file should be ignored based on .claudeignore patterns. This is used internally by Claude Code as a PreToolUse hook.

How it works

When Claude tries to read a file, this hook:

1.…
Read the full README on GitHub

How hooks work

  • Hooks are shell commands Claude Code runs at fixed points: before or after a tool call, when you submit a prompt, when Claude stops, on notifications and at session start.
  • They are set in the hooks section of ~/.claude/settings.json (or .claude/settings.json for a project), or come bundled in a plugin.
  • A hook can block a tool call, add context, or run a formatter or test. Read the scripts before you install them: they run on your machine with your permissions.
Claude Code docs

Details

Type
Hooks
Language
JavaScript
License
MIT
Last updated
5 November 2025
Topics
claudeclaude-codeignore

FAQ

What is Claude Ignore?

A Claude Code PreToolUse hook that prevents Claude from reading files that match patterns in .claudeignore files, similar to how .gitignore works. It is a hook for Claude Code, from li-zhixin/claude-ignore on GitHub.

How do I install Claude Ignore?

Run npm install -g claudeignore, then follow the setup in the README.

Is Claude Ignore popular?

li-zhixin/claude-ignore has 47 GitHub stars and 8 forks. It was last updated on 5 November 2025.

More hooks

Browse the most popular Claude Code mods, all hooks, or the skills and MCP server directories.