Skip to content
glep

glep / Guides

Using glep with Cursor

Install the glep preToolUse hook for Cursor so the agent's Grep and Glob calls are redirected to the glep index, and see how it maps each field.

On this page
  1. First principles
  2. Requirements
  3. Install
  4. What the hook does
  5. One hook for both editors
  6. Uninstall

The cursor/ folder in the repository contains a preToolUse hook for Cursor, hooks/glep_redirect.py, and an installer. Cursor has no skill file; the hook’s message tells the agent which command to run.

First principles

Cursor and Claude Code send different payloads and expect different replies, but the decision is the same in both: allow the built-in call, or deny it and name the equivalent glep command. So one hook file serves both editors. It reads the payload, decides, and formats the reply for whichever editor called it. Like the Claude Code hook, it never runs glep itself and allows every call it cannot translate.

Requirements

  • glep on your PATH. See Installation.
  • python3 on your PATH, for the hook.
  • A .glep/ index in the working directory. Run glep index once in the project root.

Install

git clone https://github.com/velofy/glep
glep/cursor/install.sh

The script copies the hook to ~/.cursor/hooks/glep_redirect.py and makes it executable.

If ~/.cursor/hooks.json does not exist, the script creates it with this content. If it already exists, the script prints the same block for you to merge into hooks.preToolUse:

{
  "version": 1,
  "hooks": {
    "preToolUse": [
      {
        "command": "./hooks/glep_redirect.py",
        "matcher": "Grep|Glob"
      }
    ]
  }
}

What the hook does

The hook allows the call unchanged unless glep is on the PATH and the working directory (the payload’s cwd) contains a .glep/ directory. Malformed input is also allowed through.

When both are present, it denies Grep and Glob calls with Cursor’s permission format:

{
 "permission": "deny",
 "user_message": "Use glep via Bash (indexed search).",
 "agent_message": "This project has a glep index. Run the equivalent indexed search via Bash instead: glep -i -g '*.rs' -e 'foo bar'"
}

Grep parameters are translated the same way as in the Claude Code hook, with two extra spellings:

  • pattern becomes -e, -i stays -i, and case_sensitive: false also becomes -i.
  • output_mode becomes -l or -c, and multiline becomes -U.
  • glob (or include) becomes -g, and type becomes -t.
  • -C, -A and -B pass through, and path is appended.
  • offset and head_limit become | tail -n +K and | head -N pipes on the shown command.
  • -n: false, with output_mode set to content or left out, is left to the built-in tool.

For Glob, the hook reads glob_pattern (or pattern) and target_directory (or path), and suggests glep --files 'pattern' dir.

One hook for both editors

The Cursor copy of glep_redirect.py detects which editor called it. Payloads with hook_event_name: preToolUse or a cursor_version field get the Cursor format above. Anything else gets Claude Code’s hookSpecificOutput format, so the same file also works as a Claude Code hook. See Using glep with Claude Code.

The repository tests both formats with cursor/hooks/test_hook.sh.

Uninstall

Remove the glep entry from ~/.cursor/hooks.json and delete ~/.cursor/hooks/glep_redirect.py.