Zum Inhalt springen
DeutschlandGPT

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:

FileApplies to
.deutschlandgpt/settings.jsonthe project. The file belongs in the repository
.deutschlandgpt/settings.local.jsonthe project, but only for you. It stays on your computer
~/.deutschlandgpt/settings.jsonyour 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:

JSON
{
  "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 example runCommand(git *).
  • async: with true the 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 codeResult
0The run continues. If the command prints JSON, the app evaluates it
2The hook blocks. The error output (stderr) goes to the model
otherThe 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

EventWhen the hook runs
PreToolUsebefore a tool runs. Here a hook can stop the call
PostToolUseafter a tool ran successfully
PostToolUseFailureafter a tool failed
PermissionRequestwhen the app would ask for approval
UserPromptSubmitwhen you send a message
SessionStartwhen a conversation starts
Stopwhen the agent wants to end its turn. A Stop hook can hold that up at most 8 times in a row
SubagentStopwhen a sub-agent has finished
PreCompactbefore 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:

FieldContent
session_idthe conversation's id
cwdthe project folder the command runs in
hook_event_namethe event, for example PreToolUse
permission_modethe mode: default, acceptEdits, plan, dontAsk or auto
dgpt_permission_modethe same mode with the app's name, so normal instead of default
transcript_pathalways null. The app does not store the conversation as a file

Depending on the event, these fields are added:

EventAdditional fields
PreToolUse, PermissionRequesttool_name, tool_input, tool_use_id, dgpt_tool_name, dgpt_tool_input
PostToolUsethe same tool fields and tool_response, the tool's result
PostToolUseFailurethe same tool fields and error, the error message
UserPromptSubmitprompt, your message
SessionStartsource: startup on the first send in a new conversation, resume in an existing one, compact after every compaction, the automatic one included
PreCompacttrigger, always manual, and custom_instructions, the text after /compact, empty without one
Stop, SubagentStopstop_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_nameApp tool
BashrunCommand
ReadreadFile
WritewriteFile
EditeditFile, editDocument
NotebookEditeditNotebook
GrepsearchFiles
GlobglobFiles
WebFetchfetchUrl
Tasktask
TaskOutputreadCommandOutput
TaskStopkillCommand
SkilluseSkill

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:

FieldEffect
hookSpecificOutput.permissionDecisionPreToolUse only: deny stops the call, ask forces a question, allow works like an allow rule
hookSpecificOutput.permissionDecisionReasonthe reason for permissionDecision. With deny the model reads it, with ask it appears on the question
hookSpecificOutput.updatedInputPreToolUse only: replaces the tool's input. The app checks the new input like any other
hookSpecificOutput.decisionPermissionRequest only, see below
hookSpecificOutput.additionalContexttext for the model on SessionStart, UserPromptSubmit, PostToolUse and PostToolUseFailure; on PreCompact part of the instructions for the summary
decision: "block" with reasonblocks like exit code 2, with reason as the reason
decision: "approve" with reasonthe older form of permissionDecision: "allow", PreToolUse only
continue: false with stopReasonon UserPromptSubmit the message does not reach the model and you see stopReason. On Stop and SubagentStop the turn ends at once
systemMessagea 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:

JSON
{
  "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:

EventEffect of a block
PreToolUse, PermissionRequestThe call does not run. The model reads the reason as the result
PostToolUse, PostToolUseFailureThe tool has already run. The reason goes to the model as a notice
UserPromptSubmitYour message does not reach the model. You see the reason
Stop, SubagentStopThe turn continues, and the reason is the model's next instruction
PreCompactThe compaction does not happen
SessionStartNothing 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.

Was this page helpful?