Intro to Claude Code Hooks

Intro to Claude Code Hooks

2 min read
45 views

What is Claude Code

Claude code is truly an amazing terminal (and also available for VS Code editors' plugin) based tool that basically is your capable Senior Software Engineer who will do your work for you.

What are Hooks?

Hooks let Claude Code do certain things during it's key workflow. This allows you to run tests, after it is done, or run notify you when it's done working

Hooks for Claude Code can be configured in "settings.json". There are multiple places you can configure hooks as shown here:

  • Globally: ~/.claude/settings.json
  • Project Specific: .claude/settings.json
  • Locally (don't recommended to commit to Git): .claude/settings.local.json

How to Setup Automatic Notifications

Prerequisites

You will need to install terminal-notifier first before you get started.

Assuming you have HomeBrew, run the following:

brew install terminal-notifier

and you should see something like this:

==> Fetching downloads for: terminal-notifier
✔︎ Bottle Manifest terminal-notifier (2.0.0)                                                                                                                                   Downloaded   14.1KB/ 14.1KB
✔︎ Bottle terminal-notifier (2.0.0)                                                                                                                                            Downloaded  353.3KB/353.3KB
==> Pouring terminal-notifier--2.0.0.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/terminal-notifier/2.0.0: 13 files, 488.6KB
==> Running `brew cleanup terminal-notifier`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).

Setup Notifications

You can setup notifications across all your projects that you use Claude Code for by opening up ~/.claude/settings.json in your favorite editor. If you never used it, you should see something like this:

{
  "permissions": {
    "allow": [],
    "deny": [],
    "ask": []
  }
}

OR

{}

At the top level, add a new entry called "hooks" and add the following:

...
"hooks": {
      "Notification": [
        {
          "matcher": "",
          "hooks": [
            {
              "type": "command",
              "command": "terminal-notifier -message 'Claude just finished and needs your input.'  -title 'Claude Code Just Finished'"
            }
          ]
        }
      ]
  }
...

so it looks like:

{
  "permissions": {
    "allow": [],
    "deny": [],
    "ask": []
  },
  "hooks": {
      "Notification": [
        {
          "matcher": "",
          "hooks": [
            {
              "type": "command",
              "command": "terminal-notifier -message 'Claude just finished and needs your input.'  -title 'Claude Code Just Finished'"
            }
          ]
        }
      ]
  }
}

and you should be set.

Testing it out

Now, run your claude code like you normally do and you will get a terminal notification when it's done.

Share this post

D

davydany

Software Engineer & Tech Leader passionate about building innovative solutions and sharing knowledge through writing.