Every single session. The same conversation.
"Use TypeScript strict mode."
"Add JSDoc comments to functions."
"Don't touch the .env file."
"Ask me before making API calls."
I was spending the first 5 minutes of every Claude Code session just... repeating myself.
Sound familiar?
The Problem Nobody Talks About
AI coding assistants are incredibly powerful. But they have one fatal flaw:
They forget everything when the session ends.
- Your carefully explained coding standards? Gone.
- The architectural decisions you discussed for an hour? Vanished.
- That one rule about never auto-committing? It doesn't exist anymore.
I tried CLAUDE.md files. They help, but Claude doesn't always read them first. I tried system prompts. Too clunky.
Then I discovered something that changed everything.
The Feature Hiding in Plain Sight
Claude Code Hooks.
Hooks are shell commands that run automatically at specific moments in Claude's lifecycle. Not suggestions. Not guidelines Claude might follow. Actual code that executes every single time.
The difference? One relies on AI cooperation. The other just... works.Think of it like this
How Hooks Work (Simple Explanation)
Hooks trigger at specific events:
| Event | When It Fires | Use Case |
|---|---|---|
SessionStart |
Session begins | Load your coding rules |
PreToolUse |
Before any tool runs | Block dangerous commands |
PostToolUse |
After any tool runs | Auto-format code |
PreCompact |
Before context compression | Preserve important context |
Notification |
When Claude needs attention | Desktop alerts |
You configure them in .claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "echo 'Your rules here'"
}
]
}
]
}
}
That's it. Every session, your rules load automatically.
5 Practical Hooks You Can Use Today
1️⃣ Never Forget Your Coding Standards
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "echo '[RULES] 1) TypeScript strict mode 2) Add JSDoc to all functions 3) No console.log in production code'"
}
]
}
]
}
}
Every session starts with your rules. No more repeating yourself.
2️⃣ Protect Sensitive Files
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "if echo \"$CLAUDE_TOOL_INPUT\" | grep -qE '(\\.env|credentials|secrets)'; then echo 'BLOCKED: Cannot edit sensitive files' >&2; exit 2; fi"
}
]
}
]
}
}
Claude literally cannot edit your .env files. Not "won't"—can't.
3️⃣ Auto-Format After Every Edit
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "file=$(echo \"$CLAUDE_TOOL_INPUT\" | jq -r '.file_path'); if [[ \"$file\" == *.ts ]]; then npx prettier --write \"$file\"; fi"
}
]
}
]
}
}
Every TypeScript file gets formatted automatically. No more "can you run prettier?"
4️⃣ Get Desktop Notifications
{
"hooks": {
"Notification": [
{
"matcher": ".",
"hooks": [
{
"type": "command",
"command": "osascript -e 'display notification \"Claude needs your attention\" with title \"Claude Code\"'"
}
]
}
]
}
}
Walk away from your desk. Get pinged when Claude needs you.
💡 Use
notify-sendon Linux
5️⃣ Remember Rules After Context Compression
This one's important. When your conversation gets too long, Claude compresses the context—and often forgets your rules.
{
"hooks": {
"PreCompact": [
{
"hooks": [
{
"type": "command",
"command": "echo '[REMINDER] After compaction: TypeScript strict, JSDoc required, ask before API calls'"
}
]
}
]
}
}
Your rules survive the compression. Every time.
The Setup (Literally 2 Minutes)
Step 1: Create the settings file
mkdir -p .claude
touch .claude/settings.json
Step 2: Add your hooks
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "echo '[My Coding Rules] 1) Your rule here 2) Another rule'"
}
]
}
]
}
}
Step 3: Commit it to your repo
git add .claude/settings.json
git commit -m "Add Claude Code hooks"
✅ Done. Every developer on your team now has the same rules.
But Wait—There's Still a Problem
Hooks solve the "rules" problem beautifully. But there's something they can't do:
They can't remember WHY you built things a certain way.
Imagine this scenario
Hooks can remind Claude of rules. But they can't preserve the reasoning behind your architectural decisions.
The Missing Piece: Context in Code
This is why I built CodeSyncer.
bitjaru
/
codesyncer
Claude forgets everything when the session ends. CodeSyncer makes it remember.
CodeSyncer
Claude forgets everything when the session ends. CodeSyncer makes it remember.
한국어 | English
The Problem → The Solution
| Problem | Without CodeSyncer | With CodeSyncer |
|---|---|---|
| Context loss | Every session = start from scratch |
@codesyncer-* tags = permanent memory |
| Forgot to tag | Changes go untracked |
codesyncer watch catches everything |
| Rules forgotten | AI forgets guidelines mid-session | Hooks auto-remind at optimal moments |
| Dangerous inference | AI guesses prices, security, APIs | Auto-pause on critical keywords |
Demo
Quick Start
# 1. Install
npm install -g codesyncer
# 2. Initialize
cd /path/to/your/project
codesyncer init
# 3. Let AI set up (say this to Claude)
"Read .claude/SETUP_GUIDE.md and follow the instructions"
# 4. Start coding (say this each session)
"Read CLAUDE.md"
Upgrade
npm install -g codesyncer@latest
Core Features
🏷️ Tag System
Put context IN your code. AI reads code, so it recovers context automatically.
// @codesyncer-decision: [2024-01-15] Using JWT (session management is simpler)…The idea is simple: store context directly in your code comments.
/**
* Authentication service
*
* @codesyncer-decision [2026-01-15] JWT over sessions (stateless, easier scaling)
* @codesyncer-inference Token expiry 24h (standard for web apps)
*/
export class AuthService {
// @codesyncer-rule Never log tokens, even in debug mode
async login(credentials: Credentials) {
// ...
}
}
Next session, Claude reads the code and instantly knows:
- ✅ What was decided
- ✅ Why it was decided
- ✅ What rules apply
No repetition. No forgetting. The context lives in the code itself.
Hooks + CodeSyncer = Complete Solution
| Problem | Solution |
|---|---|
| AI forgets coding rules | Hooks → Auto-load every session |
| AI forgets decisions | @codesyncer-decision → Lives in code |
| AI makes assumptions | @codesyncer-inference → Documents reasoning |
| AI touches sensitive logic | @codesyncer-rule → Explicit warnings |
CodeSyncer even sets up the hooks for you:
npx codesyncer init
This creates:
- ✅
.claude/settings.jsonwith SessionStart and PreCompact hooks - ✅
.claude/CLAUDE.mdwith your coding rules - ✅ Tag system ready to use
Quick Start
Option 1: Just Hooks (Manual)
mkdir -p .claude
echo '{"hooks":{"SessionStart":[{"hooks":[{"type":"command","command":"echo [RULES] Your rules here"}]}]}}' > .claude/settings.json
Option 2: Full Setup (Recommended)
npx codesyncer init
TL;DR
| Hook | Purpose |
|---|---|
SessionStart |
Load rules every session |
PreCompact |
Preserve rules after compression |
PreToolUse |
Block dangerous operations |
PostToolUse |
Auto-format, auto-lint |
Notification |
Desktop alerts |
Hooks handle the "rules."
CodeSyncer handles the "reasoning."
Together, your AI finally stops forgetting.
Links
🔗 Claude Code Hooks Documentation
🔗 CodeSyncer GitHub
Have you tried hooks yet? What rules are you automating?
👇 Drop a comment below!

Top comments (0)