Claude Code now supports Hooks
55 comments
·July 1, 2025nojs
Exit Code 2 Behavior
PreToolUse - Blocks the tool call, shows error to Claude
This is great, it means you can set up complex concrete rules about commands CC is allowed to run (and with what arguments), rather than trying to coax these via CLAUDE.md.E.g. you can allow
docker compose exec django python manage.py test
but prevent docker compose exec django python manage.py makemigrations
ramoz
Really excited to see this implemented.
Hooks will be important for "context engineering" and runtime verification of an agent's performance. This extends to things such as enterprise compliance and oversight of agentic behavior.
Nice of Anthropic to have supported the idea of this feature from a github issue submission: https://github.com/anthropics/claude-code/issues/712
chisleu
It is indeed. I don't use Claude Code. I use Cline which is a VS Code extension (cline.bot).
This is a pretty killer feature that I would expect to find in all the coding agents soon.
cheriot
Amazing how there's whole companies dedicated to this and yet claude code keeps leading the way.
wippler
Not to take away anything here, but hooks are present in other similar products. Atleast one example here - https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/com...
brynary
This closes a big feature gap. One thing that may not be obvious is that because of the way Claude Code generates commits, regular Git hooks won’t work. (At least, in most configurations.)
We’ve been using CLAUDE.md instructions to tell Claude to auto-format code with the Qlty CLI (https://github.com/qltysh/qlty) but Claude a bit hit and miss in following them. The determinism here is a win.
It looks like the events that can be hooked are somewhat limited to start, and I wonder if they will make it easy to hook Git commit and Git push.
carraes
So, form my limited understanding, this doesn't take up context, it's something auto where you can configure per tool use, and not MCP that Claude decides "when" to run it?!
petethepig
Would love to see this in Cursor. My workaround right now is using a bunch of rules that sort of work some of the time.
ed_mercer
As an ex-Cursor user myself, is there any reason that you’re still using it? Genuinely curious.
jerrygoyal
I've been using cursor for last 1 year but haven't tried Claude Code, Do you think it has gotten better?
Aeolun
Cursor is still the best when you don’t have access to a Claude subscription.
am17an
You get CC when you sign up for their $20 plan also.
porker
That tab autocomplete and predicting what I'm going to edit next is the best I've found.
The rest I can take or leave (plenty of good or better alternatives)
parhamn
This needs a way to match directories for changes in monorepos. E.g. run this linter only if there were changes in this directory.
ramoz
An abstraction via a script should work, right? They document that it pipes the JSON data to your command's stdin,
```lint-monorepo.sh
# read that data
json_input=$(cat)
# do some parsing here with jq, get the file path (file_path)
if [$file_path" == "$dir1"*]
run lint_for_dir1
```
dcre
Whatever you run in the hook can check whatever conditions you want.
brynary
This can be implemented at the line level if the linter is Git aware
jonstewart
I've been playing with Claude Code the past few days. It is very energetic and maybe will help me get over the hump on some long-standing difficult problems, but it loses focus quickly. Despite explicit directions in CLAUDE.md to build with "make -j8" and run unit tests with "make -j8 check", I see it sometimes running make without -j or calling the test executable directly. I would like to limit it to doing certain essential aspects of workflow with the commands I specify, just as a developer would normally do. Are "Hooks" the right answer?
bfLives
For the `-j` issue specifically, exporting `MAKEFLAGS=-j8` should work.
artursapek
adding a hook to have it push to prod every time baby
bgwalter
We have to do this, otherwise China wins the "AI" race!
thelittleone
This also:
1) Assign coding task via prompt 2) Hook: Write test for prompt proves 3) Write code 4) Hook: Test code 5) Code passes -> Commit 6) Else go to 3.
apwell23
you can just tell it do that or in your claude.md. don't need hooks
bearjaws
Claude Code has basically grown to dominate my initial coding workflow.
I was using the API and passed $50 easily, so I upgraded to the $100 a month plan and have already reached $100 in usage.
I've been working on a large project, with 3 different repos (frontend, backend, legacy backend) and I just have all 3 of them in one directory now with claude code.
Wrote some quick instructions about how it was setup, its worked very well. If I am feeling brave I can have multiple claude codes running in different terminals, each working on one piece, but Opus tends to do better working across all 3 repos with all of the required context.
Still have to audit every change, commit often, but it works great 90% of the time.
Opus-4 feels like what OAI was trying to hype up for the better part of 6 months before releasing 4.5
null
rtp4me
Just started using Claude (very late to the game), and I am truly blown away. Instead of struggling for hours trying to get the right syntax for a Powershell script or to convert Python to Go, I simply ask Claude to make it happen. This helps me focus on content creation instead of the mind-bending experience of syntax across various languages. While some might call it laziness, I call it freedom as it helps me get my stuff done quicker.
I have been using it for other stuff (real estate, grilling recipes, troubleshooting electrical issues with my truck), and it seems to have a very large knowledge base. At this point, my goal is to get good at asking the right kinds of questions to get the best/most accurate answers.
dmix
That’s great. Regardless of the naysayers about AI hype in tech, it was a major development for general society even if this is all it ends up being.
billbrown
It remains to be seen whether it's a net value once the VC firehose dries up and the true costs are revealed. It's quite possible that the profitable price is not worth it for most companies.
null
As an aside, people say AI will eliminate coding jobs, but then who will configure these hooks? Or think about adding such a feature?
These kinds of tooling and related work will still be there unless AI evolves to the point that it even thinks of this and announces this to all other AI entities and they also implement it properly etc.