Skip to main content
.clineignore will be deprecated soon..clineignore filters what Cline loads automatically, but it is not a security or access-control boundary — ignored files can still be read via explicit @ mentions or shell commands. We’re moving away from it as a supported feature.

Enforcing .clineignore with a Hook

While .clineignore is being phased out as a built-in feature, you can keep using the same file — and get a stronger, enforced restriction than the original ever provided — with a PreToolUse hook. The original .clineignore only filtered automatic context loading; the hook script below actively blocks the tool call whenever a file read (read_files), edit (editor, apply_patch), or shell command (run_commands) targets a file matching a .clineignore pattern.

Install in the VS Code extension

Hooks in the extension live in .clinerules/hooks/ (workspace) or ~/Documents/Cline/Hooks/ (global), must be named exactly after their event with no file extension, and need a shebang and the executable bit:
Then check Enable Hooks in Cline’s feature settings.

Install in the CLI

The CLI discovers hooks from .cline/hooks/ in the workspace (or ~/.cline/hooks/ globally, or a custom --hooks-dir):

List the files to protect

Add a .clineignore file at your workspace root. Patterns use .gitignore syntax — directories, globs, and ! negations all work:
When Cline tries to touch a matching file, the hook cancels the tool call before it runs — the file is never accessed, and the current task run stops. In the extension you’ll see the PreToolUse hook row followed by an Aborted status; in the CLI the run ends. Send a follow-up message to continue the conversation. The hook records the block reason in its output:

The hook script

The script handles both hook payload shapes (the extension’s preToolUse.parameters and the CLI’s tool_call.input), evaluates paths with real gitignore semantics via git check-ignore scoped to .clineignore alone, and also blocks attempts to modify .clineignore itself so the agent cannot un-ignore files. It requires jq and git — though git is used purely as a pattern matcher, so your workspace does not need to be a git repository.
The source lives at sdk/examples/hooks/PreToolUse_ClineignoreGuard.sh.
This hook covers only part of what .clineignore did — and enforces more than it ever did:
  • It blocks file reads, edits, and shell commands — it does not filter search or file-listing results, so it is an access-control boundary rather than a context-reduction tool (the original .clineignore was the reverse).
  • A cancelled tool call stops the current task run with the reason shown; send a follow-up message to continue the conversation.
  • The shell guard is a conservative token check, not a full shell parser: it catches straightforward access like cat .env, but a sufficiently creative command could still slip through. Paths are canonicalized lexically, but symlinks are not resolved — a pre-existing symlink aliasing an ignored file is not caught, so add such aliases to .clineignore too.
  • In the CLI, hooks are disabled in --yolo mode; use --act or --plan.

The rest of this page is the original .clineignore reference, retained for existing users while the feature is phased out.
The .clineignore file tells Cline which files and directories to skip when analyzing your codebase. It works like .gitignore: create a file named .clineignore in your project root, add patterns for files you want excluded, and Cline will ignore them.

Why It Matters

Without a .clineignore, Cline may load your entire project into context, including dependencies, build artifacts, and generated files. This wastes tokens, increases costs, and can push useful context out of the window. Adding a .clineignore can cut your starting context from 200k+ tokens to under 50k. That means faster responses, lower costs, and the ability to use smaller, cheaper models effectively.

Creating a .clineignore

Create a file named .clineignore in your project root:

Pattern Syntax

.clineignore uses the same pattern syntax as .gitignore: Lines starting with # are comments. Blank lines are ignored.

What to Exclude

Start with these categories and adjust for your project: Almost always exclude:
  • Package manager directories (node_modules/, vendor/, .venv/)
  • Build outputs (dist/, build/, .next/, out/)
  • Coverage reports (coverage/)
  • Lock files if large (package-lock.json, yarn.lock)
Exclude if present:
  • Large data files (.csv, .xlsx, .sqlite, .parquet)
  • Binary assets (images, fonts, videos)
  • Generated code (API clients, protobuf outputs, minified bundles)
  • Environment files with secrets (.env, .env.local)
Keep accessible:
  • Source code you actively work on
  • Configuration files Cline needs to understand (tsconfig.json, package.json)
  • Documentation and READMEs
  • Test files (Cline often needs these for context)

How It Works

When Cline scans your project to build context, it checks each file path against your .clineignore patterns. Matching files are excluded from:
  • The file listing Cline sees when starting a task
  • Automatic context gathering during conversations
  • Search results when Cline looks for relevant code
As noted above, explicit @ mentions still bypass these rules — for example, @/node_modules/some-package/index.js reads that file even though node_modules/ is ignored. Ignore rules control automatic loading, not explicit access.
.clineignore is separate from .gitignore. Files tracked by Git but irrelevant to Cline (like large test fixtures or data files) should go in .clineignore even if they’re not in .gitignore.

Tips

  • Check your token usage in the task header after adding a .clineignore. The difference is often dramatic.
  • If Cline seems to be missing context about a file, check whether it’s being excluded by your ignore patterns.
  • For monorepos or multi-root workspaces, each workspace root can have its own .clineignore. See Multi-Root Workspaces for details.