Hooks
Hooks are shell commands DSCC runs around tool calls. Declare them in
settings.hooks.PreToolUse[] and
settings.hooks.PostToolUse[] (arrays of shell commands,
config.rs:568–572).
Events
Defined at crates/runtime/src/hooks.rs:8–21.
| Event | Fires |
|---|---|
PreToolUse |
Before a tool executes |
PostToolUse |
After a tool returns |
Stdin payload
Each hook receives JSON on stdin (hooks.rs:118–126):
{
"hook_event_name": "PreToolUse",
"tool_name": "bash",
"tool_input": {...},
"tool_input_json": "{...}",
"tool_output": null,
"tool_result_is_error": false
}
Environment variables
Set before the hook runs (hooks.rs:169–178):
| Variable | Present |
|---|---|
HOOK_EVENT |
Always |
HOOK_TOOL_NAME |
Always |
HOOK_TOOL_INPUT |
Always (JSON) |
HOOK_TOOL_IS_ERROR |
Always |
HOOK_TOOL_OUTPUT |
PostToolUse only |
Exit codes
From hooks.rs:164–213:
| Exit | Effect | Stdout meaning |
|---|---|---|
0 |
Allow | Informational message |
2 |
Deny | Rejection reason |
| Other | Warn, continue | — |
| Signal | Warn, continue | — |
Shell
| OS | Invocation |
|---|---|
| Unix | /bin/sh -lc (hooks.rs:76–103) |
| Windows | cmd /C (hooks.rs:76–103) |
Example — reject
rm -rf /
{
"hooks": {
"PreToolUse": [
"if [ \"$HOOK_TOOL_NAME\" = \"bash\" ] && echo \"$HOOK_TOOL_INPUT\" | grep -q 'rm -rf /'; then echo 'refusing rm -rf /' >&2; exit 2; fi"
]
}
}
See also
- config-files.md for where
settings.hooksis loaded from. - permissions.md for the other gate on tool calls.