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/Rtmplehrfy/file196d71e847a3.json.
#> Installed hook "file196d21affeca" to
#> /tmp/Rtmplehrfy/file196d4d12bfc4/file196d21affeca.sh.
remove_hook(fs::path_ext_remove(basename(tmp_hook)), tmp_dir,
settings = tmp_settings, force = TRUE
)
#> Removed hook "file196d21affeca" from /tmp/Rtmplehrfy/file196d4d12bfc4.
