Hooks
Your own commands that the desktop app runs on your computer at certain events in Code and Cowork
Hooks are commands that the desktop app runs on your computer at certain events of an agent run in Code and Cowork. A hook can, for example, start a formatter after a file was edited, or check a command before it runs and stop it.
You see and manage hooks under Settings → Desktop app → Hooks.
Hooks are available in the desktop app from the first version after 0.15.0. If your settings have no Hooks entry, you are either still on 0.15.0 or older, where the app does not run hooks yet, or neither Code nor Cowork is enabled for you.
Hooks run commands with your rights on this device. Only approve commands you understand.
Where hooks are defined
Hooks live in the hooks section of the same files that also hold the permission rules:
| File | Applies to |
|---|---|
.deutschlandgpt/settings.json | the project. The file belongs in the repository |
.deutschlandgpt/settings.local.json | the project, but only for you. It stays on your computer |
~/.deutschlandgpt/settings.json | your own settings, in every folder |
Structure
Each event holds a list of entries, each with a matcher and the commands to run. This example formats every file the agent edits or creates:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "jq -r .tool_input.file_path | xargs npx prettier --write",
"timeout": 60
}
]
}
]
}
}
matcher selects the tools. Empty or * matches all of them. Besides the app's own names, the Claude Code names such as Bash, Edit, Write and Read work as well; the full list is under Tool names. Tools of local MCP servers are named mcp__<server>__<tool>. Separate several names with |, for example Bash|Read. Anything else is read as a regular expression. For SessionStart the matcher is compared with startup, resume or compact, for PreCompact with manual. UserPromptSubmit, Stop and SubagentStop ignore it.
A command can also carry these fields:
if: the command only runs when the call matches this rule. You write it as in the permissions, for examplerunCommand(git *).async: withtruethe command runs alongside, and the agent does not wait for it.onFailure: with"block"a failed command counts as a block.
How a command runs
The command receives the event data as JSON on standard input and runs in the project folder. After 60 seconds the app stops it. Use timeout to set a different limit, at most 600 seconds.
What happens next depends on the exit code:
| Exit code | Result |
|---|---|
0 | The run continues. If the command prints JSON, the app evaluates it |
2 | The hook blocks. The error output (stderr) goes to the model |
| other | The run continues. The error only appears in the display |
When a hook allows an action, it works like an allow rule: the app no longer asks about it. Deny rules, ask rules, dangerous commands, plan mode and paths outside the shared folder still lead to a question or a block.
Events
| Event | When the hook runs |
|---|---|
PreToolUse | before a tool runs. Here a hook can stop the call |
PostToolUse | after a tool ran successfully |
PostToolUseFailure | after a tool failed |
PermissionRequest | when the app would ask for approval |
UserPromptSubmit | when you send a message |
SessionStart | when a conversation starts |
Stop | when the agent wants to end its turn. A Stop hook can hold that up at most 8 times in a row |
SubagentStop | when a sub-agent has finished |
PreCompact | before compacting with /compact. Automatic compaction does not trigger it |
Input on stdin
Every command receives a JSON object on standard input. The field names are Claude Code's, so existing scripts run unchanged. These fields come with every event:
| Field | Content |
|---|---|
session_id | the conversation's id |
cwd | the project folder the command runs in |
hook_event_name | the event, for example PreToolUse |
permission_mode | the mode: default, acceptEdits, plan, dontAsk or auto |
dgpt_permission_mode | the same mode with the app's name, so normal instead of default |
transcript_path | always null. The app does not store the conversation as a file |
Depending on the event, these fields are added:
| Event | Additional fields |
|---|---|
PreToolUse, PermissionRequest | tool_name, tool_input, tool_use_id, dgpt_tool_name, dgpt_tool_input |
PostToolUse | the same tool fields and tool_response, the tool's result |
PostToolUseFailure | the same tool fields and error, the error message |
UserPromptSubmit | prompt, your message |
SessionStart | source: startup on the first send in a new conversation, resume in an existing one, compact after every compaction, the automatic one included |
PreCompact | trigger, always manual, and custom_instructions, the text after /compact, empty without one |
Stop, SubagentStop | stop_hook_active: true when the turn already continues because of a Stop hook |
tool_name is the Claude Code name where one exists, otherwise the app's name. tool_input uses Claude Code's keys: file_path instead of path for tools that work on a single file, old_string, new_string and replace_all for Edit, pattern instead of query for Grep, and for Bash one command line in command with timeout in milliseconds. All other keys are in snake_case. dgpt_tool_name and dgpt_tool_input hold the name and input as the app knows them.
The app also sets these environment variables: DGPT_PROJECT_DIR and CLAUDE_PROJECT_DIR with the project folder, and DGPT_FILE with the file when a tool works on exactly one file.
Tool names
tool_name | App tool |
|---|---|
Bash | runCommand |
Read | readFile |
Write | writeFile |
Edit | editFile, editDocument |
NotebookEdit | editNotebook |
Grep | searchFiles |
Glob | globFiles |
WebFetch | fetchUrl |
Task | task |
TaskOutput | readCommandOutput |
TaskStop | killCommand |
Skill | useSkill |
In a list of names such as Edit|Write, Edit also matches editNotebook, MultiEdit matches editFile, Agent matches task and KillShell matches killCommand. A regular expression only sees the app name and the Claude name from the table. Every other tool appears under its app name, for example deleteFile. Tools of local MCP servers appear as mcp__<server>__<tool>.
Output on stdout
When a command exits with code 0 and its output starts with {, the app reads it as JSON. Invalid JSON is not evaluated as JSON. The hook shows up as failed, and its output counts as plain text. Plain text without JSON goes to the model as context on SessionStart and UserPromptSubmit; on PreCompact it becomes part of the instructions for the summary. On every other event it is ignored.
The app evaluates these fields:
| Field | Effect |
|---|---|
hookSpecificOutput.permissionDecision | PreToolUse only: deny stops the call, ask forces a question, allow works like an allow rule |
hookSpecificOutput.permissionDecisionReason | the reason for permissionDecision. With deny the model reads it, with ask it appears on the question |
hookSpecificOutput.updatedInput | PreToolUse only: replaces the tool's input. The app checks the new input like any other |
hookSpecificOutput.decision | PermissionRequest only, see below |
hookSpecificOutput.additionalContext | text for the model on SessionStart, UserPromptSubmit, PostToolUse and PostToolUseFailure; on PreCompact part of the instructions for the summary |
decision: "block" with reason | blocks like exit code 2, with reason as the reason |
decision: "approve" with reason | the older form of permissionDecision: "allow", PreToolUse only |
continue: false with stopReason | on UserPromptSubmit the message does not reach the model and you see stopReason. On Stop and SubagentStop the turn ends at once |
systemMessage | a notice for you only. The model does not see it. PreCompact and SubagentStop do not show it |
If hookSpecificOutput carries a hookEventName for a different event, the app skips the whole block. It does not evaluate other Claude Code fields, including those that replace a tool's result in PostToolUse.
For PermissionRequest the decision sits in its own object:
{
"hookSpecificOutput": {
"hookEventName": "PermissionRequest",
"decision": { "behavior": "deny", "message": "No push to main" }
}
}
behavior is allow, deny or ask, message is the reason. With allow the object may also carry updatedInput.
What a block does, whether by exit code 2 or decision: "block", depends on the event:
| Event | Effect of a block |
|---|---|
PreToolUse, PermissionRequest | The call does not run. The model reads the reason as the result |
PostToolUse, PostToolUseFailure | The tool has already run. The reason goes to the model as a notice |
UserPromptSubmit | Your message does not reach the model. You see the reason |
Stop, SubagentStop | The turn continues, and the reason is the model's next instruction |
PreCompact | The compaction does not happen |
SessionStart | Nothing is blocked. The error only appears in the display |
When several hooks disagree, deny wins over ask, and ask over allow. A hook from a plugin can only deny or ask: the app ignores its allow and its updatedInput.
Approval
Hooks from project files only run once you have approved them. You do that per file under Settings → Desktop app → Hooks. If the hooks section of a file changes, for example after a git pull or because the agent edited the file, it waits for your approval again. You confirm your own settings in ~/.deutschlandgpt/settings.json once when they were changed outside the app.
An approved hook receives content from your conversations. If your organization works under professional secrecy (§203), a notice about § 203 StGB therefore appears before the approval. The hooks are only approved once you confirm it with the checkbox.
Project hooks and local hooks also only run in a folder you explicitly trust. The same applies to the permission rules from these files. You mark a folder as trusted in the file tree: right-click the folder and choose Trust this folder.
The Hooks page shows for each file the event, matcher and command verbatim, and its status: approved, waiting for approval or blocked. Below that are the latest runs with exit code and duration. Revoke approval stops the hooks of a file again. When hooks are waiting for approval, the app also shows a notice above the input field.
Diagnostics after changes
With Diagnostics after changes on the Hooks page you set up, per shared folder, a type check that runs on your computer after every file change the agent makes. If the folder has a tsconfig.json, that is npx --no-install tsc --noEmit -p .; with a Cargo.toml it is cargo check --quiet --message-format short; with both files, both. Before setting it up, the app shows the commands verbatim. Set up adds a PostToolUse hook to .deutschlandgpt/settings.local.json, which stays on this computer, and approves it at the same time. If the check finds errors, the agent sees the first 40 lines in the result of its change and can fix them right away. Without errors it sees nothing. Like every local hook, this one only runs in a folder you trust.
Your organization's rules
Your organization's administrators can switch off hooks from project folders and plugins with their own commands. Then even hooks you have already approved no longer run, and the Hooks page shows them as blocked. In organizations bound by professional secrecy (§ 203 StGB), hooks from project folders are off at first. When an administrator switches either of them on in the desktop app, the same notice about § 203 StGB appears there first. Switching off needs no notice.