Help article
Hooks
Hooks run your own commands at moments of an agent turn, for example before a shell command or after a file edit, and can allow, deny or add context. They run on your computer through Runner.
- Put hooks in ~/.itwins/hooks.json (all folders on that computer) or <folder>/.itwins/hooks.json (one folder). Settings > Hooks lists the hooks iTwins found and their source file.
- Events: sessionStart, sessionEnd, beforeSubmitPrompt, beforeShellExecution, afterShellExecution, beforeMCPExecution, afterMCPExecution, beforeReadFile, afterFileEdit, afterAgentResponse, afterAgentThought, subagentStart, subagentStop, preCompact and stop.
- Each hook gets the event as JSON on stdin and may print JSON with permission ("allow", "deny" or "ask"), additionalContext, userMessage or agentMessage. A timeout and failClosed can be set per hook.
- Tab completion and workspace-open events from the desktop editor have no moment on the web; Settings > Hooks marks such hooks as not run.