[BUG] Hooks not saving
Status Fixed / completed
Maintainer reply ✓ Yes — dicksontsai
Activity 7 comments · opened Jul 13, 2025 · closed Jul 14, 2025
💡 Likely answer: A maintainer (dicksontsai, collaborator)
responded on this thread — see the highlighted reply below.
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ x] Other: local macos
- Claude CLI version: v1.0.51
- Operating System: macOS 15.5
- Terminal: ghostty
Bug Description
Having an inordinate amount of trouble trying to get hooks to work. When I add, I see the hook in my config, but then if I confirm via /hooks, the matcher etc is now gone.
Steps to Reproduce
- Add a hook via /hooks that results in:
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [
{
"type": "command",
"command": "deno run --allow-read --allow-write /Users/rcogley/.claude/aichaku/hooks/aichaku-hooks.ts sensitive-file-guard"
}
]
}
]
}
- Esc, esc to REPL and it says it saved the hook.
- Was told by chat support that I need to confirm the hook in /hooks so I do that, but starting from the matcher, /hooks says I don't have any configured....
Expected Behavior
I can save and also confirm a hook via /hooks
Actual Behavior
When I save, then go and look at the config, then go back to /hooks, even after a restart of claude code, there is nothing to be seen at all. HOwever, the hook is still in the config.
7 Comments
I wonder, the config files are symlinked. Would this cause trouble?
Because my
~/.claude/settings.jsonis a symlink, I tested the theory of adding the test hook to my project.claude/settings.json, because that is just a file. It still does not work after that change. Further, though I have no Stop command configured, debug apparently shows it's looking for a Stop command (but this could be that it is just being verbose, saying "you don't have a stop command"):Also, an aside, but the language in "where should this hook be saved" could be polished up. Inconsistent labels.
<img width="2886" height="1476" alt="Image" src="https://github.com/user-attachments/assets/de5ad0df-e83d-444e-8b04-13c6ef53ccb1" />
Ok, after debugging, I discovered the hooks were configured correctly but failing silently due to missing permissions and lack of proper error handling. Here's what fixed it:
Root Cause
Solution
The key changes were to the TypeScript hook command and adding proper error handling:
And in the TypeScript hook itself, adding proper error handling and exit codes:
Working Example
With these changes, the hooks I was going for now work properly:
🪴 Creating .env.test file...
❌ Write operation blocked by hook:
⚠️ Modifying potentially sensitive file - proceed with caution
Key Findings
In the end the hooks feature is working in Claude Code - it just needs proper configuration and error handling to be visible.
Hope this will help others who encounter similar issues with hooks not appearing to work! Sorry for the firedrill!
Thanks for writing up your setup experience!
Yes, it's just being verbose. It indicates to the user that that moment is when the hook would trigger.
The inconsistency is intentional.
.claude/settings.json(project-level settings) is not in.gitignore, while.claude/settings.local.json(project-local-level settings) is in.gitignore. This means that if you add a hook to.claude/settings.jsonand git stage/commit normally, the hooks will then be used for everyone else who checks out your commit.The documentation at https://docs.anthropic.com/en/docs/claude-code/hooks is authoritative. You can pass in the documentation into either Claude Code or claude.ai for better results. Otherwise, neither Claude Code nor claude.ai will know anything about the hooks feature.
I've passed those docs and still got back some mean hallucinations about what has to be done, but noted. I got the diff between configs, but the grammar in the screenshot is a little funky. At any rate, thanks!
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.