10 ms·
Claude Code now supports hooks
- owentbrown 1y agoI'm excited to see these improvements but, none of them are enough to make up for inconvenience of having to start a new conversation (/clear) after every task. I've been using Gemini Code. The larger context window is big enough to work for a full session without having to /clear. It matters. Having to think so hard and conserve tokens with Claude is problematic.
- eightnoteight 1y agoone thing that is getting clear is that the gains from model enhancement is getting saturated thats why we are starting to see a programming of ai, almost like programming building blocks if there is a pathway for models to get smart enough to know when to trigger these hooks by themselves from system prompt or by default itself, then it wouldn't make sense to have these hooks
- ramoz 1y agoReally 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 https://github.com/anthropics/claude-code/issues/712
- chisleu 1y agoIt 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.
- wilde 1y agoThis is nice but I really wish they’d just let me fork the damn thing already.
- coherentpony 1y ago[flagged]
- deleted 1y ago[deleted]
- petethepig 1y agoWould 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 1y agoAs an ex-Cursor user myself, is there any reason that you’re still using it? Genuinely curious.
- porker 1y agoThat 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)
- wahnfrieden 1y agoClaude Code has Cursor integration you can use both
- jerrygoyal 1y agoI've been using cursor for last 1 year but haven't tried Claude Code, Do you think it has gotten better?
- _1tem 1y agoYes, I abandoned Cursor recently and went back to Claude Code. Two main reasons: 1. The “plan mode” for Claude makes it execute complex tasks much more reliably. It automatically keeps track of todos and completes them. With Cursor I’m constantly fighting with it. 2. I can now use my IDE of choice (JetBrains) rather than a poor fork of VS Code. 3. Daily usage limits now included in the monthly $20/month Claude Pro plan seems to be enough for my daily needs. No extra costs.
- matltc 1y agoI used GitHub copilot in my vscode setup. Claude Code is its agent mode on steroids: highly configurable, seems to have much larger context window, can write "memories", has hooks now. Highly recommend trying it out. The time it saved me in first few hours of use easily made the monthly fee worthwhile. I did hit a limit near the four-hour mark (resets every five hours for us Pro subscribers), but just went and reviewed the ~1700 lines it added in that time and cleaned up the config files (updated todos etc)
- artursapek 1y agoadding a hook to have it push to prod every time baby
- apwell23 1y agoyou can just tell it do that or in your claude.md. don't need hooks
- thelittleone 1y agoIn some cases cc misses rules in CLAUDE.md.
- ramoz 1y agoIn many cases.
- apwell23 1y agoso its back to hand coding stuff again. They are going to slowly add "features" that brings handcoding back till its like 100% handcoding again.
- ramoz 1y agoThis doesn’t come without consideration. You can see I mention this in the original feature request. Yes - it’s fine to think of it as handholding (or handcoding). These model providers cannot be responsible for ultimate alignment with their users. Today, they can at best enable integration so a user, or business, can express and ensure their own alignment at runtime. The nature of these systems already requires human symbiosis. This is nothing more than a new integration point. Will empower agents beyond today’s capabilities, increase adoption.
- thelittleone 1y agoThis 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.
- nojs 1y agoExit 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
- brynary 1y agoThis 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 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.
- alfons_foobar 1y agoWhy is it that regular git hooks do not work with claude code?
- brynary 1y agoWhen using Claude Code cloud, in order to create signed commits, Claude uses the GitHub API to create commits instead of the git CLI
- ramoz 1y agoWdym Claude Code cloud? Like in a cloud env?
- alfons_foobar 1y agoHuh, I had not heard of claude code cloud before. (Also almost swallowed my tongue saying that out loud)
- BonoboIO 1y agoHusky and lint-staged worked for me. Pre Commit Hooks did not work for me.
- symbolicAGI 1y agoFYI. Claude loves Java. I never have to reformat. It picks up my indentation preferences immediately and obeys my style guide flawlessly. When I ask it to perfect my JavaDoc it is awesome. Must be a ton of fabulous enterprise Java in the training set.
- parhamn 1y agoThis needs a way to match directories for changes in monorepos. E.g. run this linter only if there were changes in this directory.
- brynary 1y agoThis can be implemented at the line level if the linter is Git aware
- ramoz 1y agoAn 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 1y agoWhatever you run in the hook can check whatever conditions you want.
- tinodb 1y agoSet up pre-commit and call that from a hook? That's what we have
- bionhoward 1y agoGiven the Anthropic legal terms forbid competing with them, what are we actually allowed to do with this? Seems confusing what is allowed. No machine learning work? That would compete. No writing stuff I would train AI on. Except I own the stuff it writes, but I can’t use it. Can we build websites with it? What websites don’t compete with Anthropic? Terminal games? No, Claude code is a terminal game, if you make a terminal game it competes with Claude? Can their “trust and safety team” humans read everyone’s stuff just to check if we’re competing with LLMs (funny joke) and steal business ideas and use them at Anthropic? Feels like the dirty secret of AI services is, every possible use case violates the terms, and we just have to accept we’re using something their legal team told us not to use? How is that logically consistent? Any safety concerns? This doesn’t seem like a law Asimov would appreciate. It would be cool if the set of allowed use cases wasn’t empty. That might make Anthropic seem more intelligent
- nerdsniper 1y agoWould you argue that Cursor (valued at $10B) is breaking Anthropic's terms by making an IDE that competes with their Canvas feature?
- deleted 1y ago[deleted]
- jazzyjackson 1y agoIs Cursor using Claude code to build? Or they just allow it to plug into Claude?
- moralestapia 1y agoYes.
- varenc 1y agoCursor isn't building models trained with the outputs of Anthropic models (I think). That's what the ToS is forbidding.
- 1y ago
- carraes 1y agoSo, 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?!
- apwell23 1y ago[flagged]
- chisleu 1y agoYup, slowing down the AI is a really hard thing to do. I've mostly accomplished it, but I use extensive auto prompting and a large memory bank. All of it is designed explicitly to slow down the AI. I've taught it how to do what I call "Baby Steps", which is defined as: "The smallest possible change that still effectively moves the technology forward." Some of my prompting is explicit about human review and approval of every change including manual testing of the application in question BEFORE the model moves on to the next step.
- wewewedxfgdf 1y agoThe key phrase is "Do not overengineer." I say stuff like: This code must be minimal. Meet only the stated requirements. Do not overengineer. Create a numbered index of requirements. Verify after you write the code that all requirements are met and no more.
- deleted 1y ago[deleted]
- AdieuToLogic 1y agoSo many people yearn for LLM's to be like the Star Trek ship computer, which when asked a question unconditionally provides a response relevant and correct, needing no verification. A better analogy is LLM's are closer to the "universal translator" with an occasional interaction similar to[0]: Black Knight: None shall pass. King Arthur: What? Black Knight: None shall pass! King Arthur: I have no quarrel with you good Sir Knight, But I must cross this bridge. Black Knight: Then you shall die. King Arthur: I command you, as King of the Britons, to stand aside! Black Knight: I move for no man. King Arthur: So be it! [they fight until Arthur cuts off the Black Knight's left arm] King Arthur: Now, stand aside, worthy adversary. Black Knight: 'Tis but a scratch. King Arthur: A scratch? Your arm's off! Black Knight: No, it isn't. King Arthur: Well, what's that then? Black Knight: I've had worse. 0 - https://en.wikiquote.org/wiki/Monty_Python_and_the_Holy_Grail https://en.wikiquote.org/wiki/Monty_Python_and_the_Holy_Grai...
- bearjaws 1y agoClaude 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
- deleted 1y ago[deleted]
- wahnfrieden 1y agoYou can’t use it across three repos like a workspace in Xcode?
- nikita2206 1y agoIt is all file based, so yes you can if you do what OP said: `git clone repo-one && git clone repo-two` and tell claude that repo-one directory is for example frontend, repo-two is backend (or better name the directories after what they are)
- bearjaws 1y agoExactly this, nothing fancy really.
- booli 1y agoYou can use git work tree for that. There is a very extensive blog here: https://www.pulsemcp.com/posts/how-to-use-claude-code-to-wield-coding-agent-clusters https://www.pulsemcp.com/posts/how-to-use-claude-code-to-wie...
- rtp4me 1y agoJust 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.
- deleted 1y ago[deleted]
- dmix 1y agoThat’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 1y agoIt 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.
- KoolKat23 1y agoIt can still be a lot more expensive and be cheaper than a human, it might mean less chance taking and spending the money to try set it up and see if it works though. More existing setups, less new setups.
- paulhodge 1y agoI'm pretty sure that the $100 / $200 plans are a net profit for Anthropic. Most users (including myself) don't come close to the usage limit. I've been trying to max out the $100 plan and I have a problem where I run out of stuff to ask it to do. Even when I try to have multiple side projects at once, Claude just gets stuff done, and then sits idle.
- jonstewart 1y agoI'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 1y agoFor the `-j` issue specifically, exporting `MAKEFLAGS=-j8` should work.
- wahnfrieden 1y agoor mcp
- kaoD 1y agoThanks, I'll let Claude know.
- edg5000 1y agoMaybe a good way to think about this is that humans like usability/automations because even through we can handle more complicated manual operations, "abstracting away" certain operations helps us free up context. E.g. I like to be able to press F5 to reconfigure, build, run and attach debugger automatically from the IDE. If I had to manually to all this every time it would really clog up my context. So maybe try to make things easier for the AI. Another example, it was messing up string dictionary keys all the time, even after CLAUDE.md etc. I realised, if it's annoying for the human to get dictionary string keys right (for humans it's error prone, humans prefer constants or propterties that will give instant feedback by the IDE if there is a typo). Ideally Claude would have an MCP which linting/indexing. E.g. if it edits a source file, without building/running it instantly receives errors by the editing tool. And Claude should ideally have some kind of code index in its context in the same way my indexer for Java/C++/TypeScript etc probably has a cached index of all symbols somewhere, allowing instant error detection. Maybe even running a fast language server MCP on each line edit may help claude. Specifically regarding make -j8, I think an IDE MCP would help, where it should provide the same amount of ergonomy has a GUI IDE provides; e.g. quick shortcuts for common actions such as search, find-replace, build and even debug/set breakpoint, find references. Currently Claude is grepping, which works. Is there an IDE-MCP somewhere; with language server support? That would be quite something!
- cheriot 1y agoAmazing how there's whole companies dedicated to this and yet claude code keeps leading the way.
- wippler 1y agoNot 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/command-line-context-hooks.html https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/com...
- stavros 1y agoDoes it? Claude Code is the product that works the least well for me, mainly because of its tendency to go off and do tons of stuff. I've found LLMs are at their best when they produce few enough lines of code that I can review and iterate, not when they go off and invent the world. For that reason, I mainly use Aider and Cursor (the latter mostly in the "give me five lines" comment mode).
- theshrike79 1y agoHave you tried Gemini CLI yet? :D It's even worse than Claude 3.5 was. I asked it to check a few unit tests and it charged ahead by inventing features and started writing them - apologising profusely as it did so =)
- danielbln 1y agoI tell Claude Code to make a detailed implementation plan, then come back to me for discussion, then we step through the plan bit by bit together. It's all about guidelines. Don't want it to charge ahead? Tell it not to.
- stavros 1y agoI had a very specific problem I wanted to solve, Opus kept being entirely sure that it knew what the problem was, and that it could fix it. Next iteration, when the previous solution didn't work, Claude was sure it was some other thing. So on and so forth, until I was $35 poorer and had a bunch of code that didn't really seem to do anything, and certainly not fix my problem. Planning and discussion wouldn't have fixed that.
- mkagenius 1y agoAs 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.
- mrmincent 1y agoTo misuse a woodworking metaphor, I think we’re experiencing a shift from hand tools to power tools. You still need someone who understands the basics to get the good results out of the tools, but they’re not chiseling fine furniture by hand anymore, they’re throwing heaps of wood through the tablesaw instead. More productive, but more likely to lose a finger if you’re not careful.
- steve_adams_86 1y agoI like this metaphor because power tools didn’t lead to more sophisticated craftspeople despite the increase in efficiency and potential. I think it will be the same with code. More outputs, not necessarily more refined or better in any way, but not innately bad either.
- SkepticalWhale 1y agoGreat analogy. Although I still wonder how long we're in this phase and how ubiquitous it will be, because didn't power tools coincide with improved automation in factories eliminating manufacturing jobs?
- otterley 1y agoWhen all you have is a hammer, everything looks like your thumb.
- deleted 1y ago[deleted]
- forgotoldacc 1y agoAnd we may get an ugly transitory period where a lot of programs go from being clearly hand made with some degree of care and some fine details that show the developer's craftsmanship, to awful prefab and brutalist software that feels inhuman, mass-produced, and nothing is really fit for the job but still shipped because it kind of works well enough. People go to museums to admire old hand-carved furniture and travel to cities to admire the architecture of centuries past made with hand-chiseled blocks. While power tools do let people make things of equal quality faster, they're instead generally used to make things of worse quality much, much faster and the field has gone from being a craft to simply being an assembly line job. As bad as software is today, we're likely to hit even deeper lows and people will miss the days where Electron apps are good compared to what's yet to come. There's already been one step in this direction with the Cambrian extinction of 90s/early 2000s software. People still talk about how soulful Winamp/old Windows Media Player/ZSNES/etc were.
- aantix 1y agoWish it supported rollbacks..
- robbomacrae 1y agoWith this you could add support yourself! Add a PostToolUse [0] hook that automatically creates a git commit whenever changes are made. Then you can either git checkout the commit you want to rollback to... Or you could assign those git commits an index and make a little MCP server that allows you to /rollback:goto 3 or /rollback:back 2 or whichever syntax you want to support. In fact if you put that paragraph into Claude I wouldn't be surprised if it made it for you. [0] https://docs.anthropic.com/en/docs/claude-code/hooks#posttooluse https://docs.anthropic.com/en/docs/claude-code/hooks#posttoo...
- b0a04gl 1y ago>before this you had to trust that claude would follow your readme instructions about running linters or tests. hit and miss at best. now its deterministic. pre hook blocks bad actions post hook validates results. >hooks let you build workflows where multiple agents can hand off work safely. one agent writes code another reviews it another deploys it. each step gated by verification hooks.
- icoder 1y agoThis nicely describes where we're at with LLM's as I see it: they are 'fancy' enough to be able to write code yet at the same time they can't be trusted to do stuff which can be solved with a simple hook. I feel that currently improvement mostly comes from slapping what to me feels like workarounds on top of something that very well may be a local maximum.
- Marazan 1y agoSomeone described LLMs in the coding space as stone soup. So much stuff is being created around then to make them work better that at some point it feels like you'll be able to remove the LLM part of the equation
- samrus 1y agoWe cant deny the LLM has utility. You cant eat the stone but the LLM can implement design patterns for example. I think this insistance on near autonomous agents is setting the bar too high, which wouldnt be an issue if these companies werent then insisting that the bar is set just right. These things understand language perfectly, theyve solved NLP because thats what they model extremely well. But agentic stuff is modelled by reinforcement learning and until thats in the foundation model itself (at the token prediction level) these things have no real understanding of state spaces being a recursive function of action spaces and such stuff. And they cant autonomously code or drive or manage a fund until they do
- ramoz 1y agoClaude Code is an agent, not an LLM. Literally this is software that was released 4mo ago. lol. 1y ago - No provider was training LLMs in an environment modeled for agentic behavior - ie in conjunction with software design of an integrated utility. 'slapped on workaround' is a very lazy way to describe this innovation.
- theusus 1y agoI was yesterday only searching for ways to live lint than waiting for Claude to do that or during pre-commit
- ainiriand 1y agoI tried to make an app in claude code like they so much fanfare it could do, and it failed. It was obvious it will fail, I wanted something that I think it was not done before, using the Youtube api. But it failed nonetheless. I am tired of pretending that this can actually pull any meaningful work besides a debug companion or a slightly enhanced google/stackoverflow.
- ramoz 1y agoIf you do not know the software design, claude code will fail. If you know the software design, you can guide it toward success.
- causal 1y agoI see this a lot on HN: approach AI hoping it will fail and declaring it useless when minimal effort produces bad results.
- bognition 1y agoInteresting how long ago did you do this? How long did you spend on it? I was skeptical about Claude code and then I spent a week really learning how to use it. Within the week I had built a backend with FastAPI that supported user creation, password reset, email confirmation, a front end, and support for ouath into a few systems. It definitely took me some time to learn how to make it work, but I’m astounded at how much work I got done and for so little typing.
- prmph 1y agoI frequently have to remind Claude Code of the instructions in the CLAUDE.md file, as well as various general aspects of the code base. Maybe this will enable a fix
- SV_BubbleTime 1y ago> Stop using early returns in void functions! It’s in the clause.md you shouldn’t do that in this project! Reading CLAUDE.md (22 seconds, 2.6k tokens..) You’re absolutely right!
- unshavedyak 1y agoHonestly patterns like these that can have a tool fix the LLM quirks seems powerful.
- SV_BubbleTime 1y agoNo doubt, it’s just that I shouldn’t have to. Remind the tool of its own configuration file.
- camwest 1y agoA couple of example hooks: https://cameronwestland.com/building-my-first-claude-code-hooks-automating-the-workflow-i-actually-want https://cameronwestland.com/building-my-first-claude-code-ho... I'm happy to see Claude Code reaching parity with Cursor for linting/type checking after edits.
- climatenufties 1y ago[dead]
- Syzygies 1y ago.claude/settings.local.json fragment: "hooks": { "PostToolUse": [ { "matcher": "Edit|MultiEdit|Write", "hooks": [ { "type": "command", "command": "jq -r '.tool_input.file_path' | xargs bin/save-hook.sh" } ] } ] } I jumped at this HN post, because Claude Code Opus 4 has this stupid habit of never terminating files with a return. To test a new hook one needs to restart claude. Better to run the actual processing through a script one can continually edit in one session. This script uses formatters on C files and shell scripts, and just fixes missing returns on other files. As usual claude and other AI is poor at breaking problems into small steps, and makes up ways to do things. The above hook receives a json file, which I first saved to disk, then extracted the file path and saved that to disk, then instead called save-hook.sh on that path. Now we're home after a couple of edits to save-hook.sh This was all ten minutes. I wasted far more time letting it flail attempting bigger steps at once.
- 6thbit 1y agoFind it a bit odd they didn't model this as an MCP server itself, and making hooks just mcp tools with pre-agreed names. Wouldn't it be nice to have the agent autodiscover the hooks and abstracting their implementation details away under the mcp server, which you could even reuse by other agents?