YouTube Deep SummaryYouTube Deep Summary

Star Extract content that makes a tangible impact on your life

Video thumbnail

I used HOOKS to make CLAUDE CODE Meow, Beep, and Talk

Greg Baugues (@greggyb) • 14:28 minutes • Published 2025-07-16 • YouTube

📝 Transcript (306 entries):

[00:00] When Enthropic announced hooks for [00:01] Claude Code, there was this comment from [00:03] Maximum Guide on the Claude AI [00:05] subreddit, and they said, "I'm going to [00:07] use this to make Claude meow. I've always wanted a cat, but I'm allergic." That felt like as good of a use case as any to get started with. So, this is what your cloud code can sound like when you're running it in parallel. Or maybe you prefer the old school beeps. [00:32] Or maybe you want Cloud Code to talk to [00:33] you. Editing ready for you bashing. Let me quickly walk you through how I built this. And I think this is a really great project for getting started with Cloud Code and hooks because when you assign sounds to all of the different events, you will start to understand when they're getting triggered, which will then help you come up with new ideas for a bit more pragmatic ways that you can use hooks, which is an incredibly powerful addition to Claude Code. The general idea here is that Claude has a whole bunch of different types of events and you can set up hooks to run custom commands before or after or on those different events. So some of those [01:08] events would be a pre-tool use. So before it uses a tool, the tool includes bash which you'll find out if you do this is a lot of cloud code use. Uh it is also editing files. It is reading files. It is uh fetching stuff from the web. Uh you can also do post tool use. [01:26] So this is letting you know after it's [01:28] finished that task. There's notification. There's always been the notification with cloud code that you could set up with iTerm for instance to beep when it's waiting for your approval on something. But I found that it was easy to miss this and didn't always work great and I've really enjoyed being able to customize that. There's stop. So this [01:44] is when cloud code's completed as its [01:45] task. I actually use this a lot in lie of the notification. Uh and then there's uh pre-ompact. So something that it's going to do before it autocompacts all of your history. Uh, so you can set up uh Claude to run custom commands before it does any of these actions. And the [02:02] way you're going to set that up is in [02:03] your settings.json. Now, anytime you're editing your settings.json, you got to figure out which one do you edit. And I think this is a little confusing for folks and probably worth a deep dive later on. Uh, but generally for this use [02:15] case, I've been doing it in my [02:16] settings.json in my project. This way it is committed to my repo and uh it will be included on all of the uh work trees that I'm running this on. I also have created inside mycloud directory a hooks directory where I'm storing all of the files associated with these hooks here. Uh and I suspect that I might end up moving some of this stuff out to my user settings, my uh user.cloud cloud [02:45] directory so that this is included in [02:47] all of my uh cloud usage across all my [02:50] projects. But for right now, I'm just doing this on a single project. I did not want to do it in my settings.local.json because then it's not committed to the repo and then I don't get all of this across all the different work trees. You've edited your [03:01] settings.json before. You've probably just looked at the permissions. Uh and this is a lot of permissions that I've given Claude. Now we'll minimize those for now. Uh and now we have hooks. So, [03:13] we're going to define the type of event [03:15] that we're going to trigger a hook on. Hooks are a list and then uh a list of uh dictionaries. And there's really I think actually command is the only type of hook that you can run. And for now, the only thing I'm doing is running a custom Python script. And so I'm running Python 3 and then I'm passing the full path of that script. So you can see that [03:38] here in my project I have claude hooks [03:42] and then the script called hook handler [03:44] and so I'm doing Python 3 users Greg [03:47] code YouTube tracker claude hooks etc. All right so this means that anytime that cla code needs to run the notification it's running hook handler. It means that anytime it's running stop it triggers a stop event it's running hook handler. Anytime it's running pre-tool use it's running the hook handler. I tried this a few different ways. I tried writing different scripts [04:07] for different um events. Uh I have also tried uh using the same script but passing different arguments in uh like command line arguments in. I found that difficult to debug. Uh I found that what I want to do is keep my settings.json as simple as possible and then handle all of the logic in the Python script because there I have much better debugging etc. All right, so let's take [04:32] a look at the Python script. This Python script, by the way, uh I generated with cloud code. I basically passed it the URL for the hooks uh documentation and told it what I want to do. I went through several different iterations and then I had it um uh refactor it several times to make it as legible as possible. And you can find this script at uh highhigh.ai/hooks. [04:56] Um, but basically what's going to happen [04:57] here, first and foremost, let's just run [05:00] and log the data that cloud code is [05:04] passing into this script when it gets [05:07] triggered because that data is what will [05:10] help you decide what you want to do. You can see under hook input, hooks receive JSON data via standard in containing session information and event specific data. And it goes through some of the specifics of what that looks like. All right. And so, uh, let's just do this. [05:26] Another little tip that I found for [05:27] working with cloud code is you can just [05:29] say to cloud code, uh, do some stuff [05:34] to test out my hooks integration. And then it will just do stuff. Uh, and I think right now I have the beeps turned on. So, you can hear the various beeps that it's doing. And then as that runs, you can see that it was updating its to-dos and it's reading a file now. So I'm [05:57] going to come over here and I'm going to [05:58] look into my hook handler.json L. Uh because I have a function in my hook handler called log hook data. It's right here. Claw's going to keep making sounds in the background as we go. Um which I [06:12] might need to turn off. Uh and so this is basically just uh writing out the uh data that's coming in via standard in. So this is what that looks like. So you can see there's a session ID. You can see that uh we have an event name. We [06:26] have the tool name. So in this case it's it's pre-tool use. So we have the tool name and then the tool input. So this gives us all the information we need to know about what Claude is doing in order to branch the logic to to do the various stuff. Um, so let's uh come back in here and we'll look at then what my hook handler is doing. Uh, basically I have a [06:50] uh [06:52] a few different directories here. I have a sounds directory and I have um beeps and I have voice and I think on a different branch I had my meow sounds although I may have actually accidentally reverted that out after I recorded the demo. But okay, we'll go dig through uh git for that later. Uh the way that I got these is I use uh Epidemic Sound. Uh I use it in my various YouTube videos. Um they have [07:17] music. Uh and then I also they also have a sound effects section here. And so I just came in here and I got there was a section for uh beeps. And so I just all sorts of fun beeps that you can play with. Uh oh my god, that one's Let's make that one stop right now. Sorry [07:35] about that. Uh they've got one for uh you know they've got cats. That's kind of nice. All right. I feel like I only use sad meows in mine. I should change that. Uh [07:51] I did some construction equipment once [07:53] for the tool use. Uh they also have this new feature called voices which I played around with. So you can they have these voice actors who have donated their voice to the AI and then you can make them say things. So uh I used Sean here because he's British. Seemed like Claude might be British. Uh uh [08:15] say committing and you can create the [08:18] voice over. Commiting. Commiting. Okay. Uh I guess I did spell that wrong. Let's try that again. [08:30] committing. There we go. That's better. Uh, so you can see how I did those. One, if you do end up using these, one, um, just tip is say they often will cram a whole bunch of different, uh, sound effects on the same one. And so you can see it here. [08:47] All right. So then if you go to download, you can come to segment and you can select just the segment of the sound effect that you want to download. So I'll take that down. you can get just that. So, I did that. I played with a [08:58] different a few different ways of doing [09:00] this. The first iteration I did, um, I just threw a bunch of random sound effects into a folder and then I just let it pick randomly. I do like assigning specific sounds to specific actions because I do find that it helps me understand when Claude is doing stuff. For instance, I didn't realize how often Claude is updating its to-do list. Uh, which I I thought was actually kind of cool. I didn't realize initially before [09:24] I started doing this how many of the [09:26] commands that Claude runs is a bash [09:28] command and so initially I just had it [09:30] uh playing a sound for bash and then it [09:32] was the same sound over and over again [09:34] and then I realized that I needed to do [09:35] a pattern match on uh you know the [09:38] specific commands such as editing files [09:40] or reading files um or even you know it [09:42] runs bash for uh using the GitHub CLI um [09:46] and so doing all those different things [09:47] I think it just helped me understand [09:49] claude code and how it worked better. So I have here um I've renamed these various uh sounds to the command. So here you can see with uh speaking committing or I have one for bash bashing or testing running tests. You go the PR creating pull request. See so uh pretty cool. Well, I I thought [10:19] that was great. And I mean, you can imagine what this Python script's doing here. Um, so basically, we just play the sound. I have a little toggle up here, sounds type, that I can set this to meows or voices or beeps. Uh, and then I just have a map uh telling it to map the different event to the various uh sound files. Uh, and then it will uh match go [10:44] in depth on uh the different bash [10:46] commands to figure out which sound it [10:48] should play for those. Um, and uh, this was really fun and pretty easy to create with Claude. And I think that this was uh, a really cool foray into using hooks because it helped me understand the different event types by assigning the different sounds, which has then given me a lot more thoughts about different ways that I can use hooks. I've seen a lot of folks use them for instance to um prevent some of the commands that they're most concerned about. So for instance, you could set up a hook to look for a bash command that's running rm-rf for instance and to uh you know have it not do that. Uh you could um a lot of [11:26] folks are using it to run llinters. A lot of folks are using it to ensure that the test suite is being run before uh you open up a pull request. Um, and so there's just a lot of really interesting things you can do here that gives you a lot a little bit more deterministic control over cloud codes behavior. Uh, but I did find that getting started by doing the fun thing with sounds was a great way to get started here. If you want to see all this code, you can check out hihigh.ai/hooks [11:54] and I put the code up there and would [11:56] love to hear what you're using hooks [11:57] for.