Skip to main content
Hooks let you inject custom logic into Cline’s workflow at key moments. They run automatically when specific events happen during development. You can validate operations before they execute, monitor tool usage, and shape how Cline makes decisions.
Hooks in action

What You Can Build

  • Stop operations before they cause problems (like creating .js files in a TypeScript project)
  • Run linters or custom validators before files get saved
  • Prevent operations that violate security policies
  • Track everything for analytics or compliance
  • Trigger external tools or services at the right moments

Hook Types

Hook TypeWhen It Runs
TaskStartWhen you start a new task
PreToolUseBefore Cline executes tools like file editing
PostToolUseAfter tool execution completes
UserPromptSubmitWhen you submit a message to Cline

Hook Locations

Hooks can be stored globally or in a project workspace. See Storage Locations for guidance on when to use each.
  • Global hooks: ~/Documents/Cline/Hooks/
  • Project hooks: .clinerules/hooks/ in your repo (can be committed to version control)

Creating a Hook

  1. Open Cline and click the Hooks tab
  2. Choose between Global Hooks or project-specific hooks
  3. Click “New hook…” dropdown and select a hook type
  4. Review the hook’s code with the pencil icon
  5. Toggle the switch to activate once you understand the behavior
Hook controls
Always review a hook’s code before enabling it. Hooks execute automatically during your workflow.

Example: TypeScript Enforcement

This hook blocks creation of .js files in a TypeScript project:
#!/bin/bash
# PreToolUse hook to enforce TypeScript

TOOL_NAME=$(echo "$CLINE_TOOL_NAME")
FILE_PATH=$(echo "$CLINE_TOOL_PARAMS" | jq -r '.path // empty')

if [[ "$TOOL_NAME" == "write_to_file" && "$FILE_PATH" == *.js ]]; then
  echo '{"action": "block", "message": "Use .ts files instead of .js in this TypeScript project"}'
  exit 0
fi

echo '{"action": "approve"}'

CLI Support

Hooks are available in the Cline CLI:
# Enable hooks for a task
cline "What does this repo do?" -s hooks_enabled=true

# Configure hooks globally
cline config set hooks-enabled=true
CLI hooks are only supported on macOS and Linux.
  • Rules define high-level guidance that hooks can enforce
  • Checkpoints let you roll back if a hook didn’t catch an issue
  • Auto-Approve works well with hooks as safety nets