2 min read

Making Claude Code Hooks Smarter

Added project detection so iOS hooks don't run in Python projects anymore.

Got annoyed today. Every time I opened Claude Code in a Python project, it would run iOS environment checks. “Checking Xcode… Checking SwiftLint…” Like, I’m working on a FastAPI app here.

The problem

My global Claude Code config had iOS hooks that ran on every session start:

"SessionStart": [
  { "command": "~/.claude/hooks/ios-env-check.sh" },
  { "command": "~/.claude/hooks/worktree-status.sh" }
]

These hooks don’t know what kind of project they’re in. They just run.

What I changed

Added project detection at the top of ios-env-check.sh:

is_ios_project() {
  ls *.xcodeproj &>/dev/null || \
  ls *.xcworkspace &>/dev/null || \
  [ -f "Package.swift" ] || \
  ls *.swift &>/dev/null 2>&1
}

if ! is_ios_project; then
  exit 0  # Silent exit
fi

Now it checks for Xcode project files or Swift files before running any checks. If it’s not an iOS project, it exits silently.

Other fixes while I was at it

Since I was already in there:

  1. Converted all hooks to English - Korean output was using 7x more tokens. My CLAUDE.md already said “write skills in English” but I hadn’t followed my own advice.

  2. Added worktree cleanup hints - I kept forgetting to clean up old worktrees. Now if you have more than 3, you get a reminder:

    ⚠️  You have 5 worktrees. Consider cleaning up:
       Remove worktree: claude-worktree remove
       Prune stale:     git worktree prune
  3. Fixed install.sh - The claude-worktree CLI wasn’t being installed globally. Added symlink creation:

    mkdir -p ~/.local/bin
    ln -sf "$DOTFILES/scripts/claude-worktree" ~/.local/bin/claude-worktree
  4. Added Slack webhook check - slack-notify.sh would fail if SLACK_WEBHOOK_URL wasn’t set. Now it just exits silently.

The full list

FileChange
ios-env-check.shProject detection + English
spm-check.shEnglish output
worktree-status.shCleanup hints + English
slack-notify.shWebhook URL check
install.shCLI symlink + PATH warning
settings.jsonAdded spm-check.sh

Now my Python and Next.js projects start clean, and iOS projects still get the full environment check.