Deletes a hook script from the hooks directory, removes its registration
from settings.json, and removes it from the lock file.
Arguments
- name
The name of the hook to remove (the script filename stem, e.g.
"lint-staged"forlint-staged.sh).- path
The hooks directory. Can be one of:
A known coding agent name such as
'claude_code','cursor', or'github_copilot'(seehook_path()for the full list) to use that agent's conventional project-scope path.A character string giving the directory path directly.
NULL(the default), in which case the path is resolved from theWF_AGENTenvironment variable, or by prompting in interactive sessions. SetWF_AGENTin your.Renviron(e.g. withusethis::edit_r_environ()) to avoid the prompt.
- settings
Path to the
settings.jsonfile where the hook is registered. WhenNULL(the default), defaults tosettings.jsonin the parent directory ofpath.- force
If
FALSE(the default), prompts for confirmation in interactive sessions. Set toTRUEto skip the prompt.
Examples
tmp_hook <- tempfile(fileext = '.sh')
writeLines(c('#!/bin/bash', 'echo hello'), tmp_hook)
tmp_dir <- tempfile()
tmp_settings <- tempfile(fileext = '.json')
add_hook(tmp_hook,
event = 'PreToolUse', path = tmp_dir,
settings = tmp_settings
)
#> Registered PreToolUse hook in /tmp/Rtmp1p0v0x/file1be51a7e94c8.json.
#> Installed hook "file1be51a7f4625" to
#> /tmp/Rtmp1p0v0x/file1be51f5ae638/file1be51a7f4625.sh.
remove_hook(fs::path_ext_remove(basename(tmp_hook)), tmp_dir,
settings = tmp_settings, force = TRUE
)
#> Removed hook "file1be51a7f4625" from /tmp/Rtmp1p0v0x/file1be51f5ae638.
