When you run several Claude Code sessions at once, a plain "Claude needs your attention" alert is not enough, because you cannot tell which session sent it. The fix is to put the session's project or folder in every notification. Each hook receives the session's cwd and session_id as JSON, so your hook can read them and include the project name in the alert. Give sessions clear names with claude -n <name> or /rename, and use claude --worktree <name> so parallel sessions on one repository each have their own folder, which then shows up in the alert.
01Why parallel sessions get confusing
Running two or three Claude Code sessions side by side is now a normal way to work: one fixes a bug, one writes tests, one explores a refactor. Each session stops at its own pace. The problems are always the same:
- an alert arrives and you do not know which terminal tab it came from;
- one session has been waiting on a permission prompt for twenty minutes while you watched another;
- you answer in the wrong window.
All three come down to identification. Every alert should say where it came from, and every answer should go back to the session that asked.
02Separate the sessions properly first
Use worktrees for the same repository
Two sessions editing the same checkout will step on each other's changes. Claude Code's --worktree flag (-w for short) creates an isolated git worktree and starts the session in it:
claude --worktree feature-auth
claude --worktree fix-login
By default each worktree is created under .claude/worktrees/<name>/ at the repository root, on a new branch named worktree-<name>. Run each command in its own terminal. Add .claude/worktrees/ to your .gitignore so the worktrees do not appear as untracked files.
When you exit, Claude Code checks the worktree. If it is clean and you never named the session, Claude Code removes the worktree and its branch; otherwise it asks whether to keep it. To return to a kept worktree later, run the claude --worktree <name> --resume command it prints on exit. If you prefer to manage worktrees yourself, git worktree add ../project-feature-a -b feature-a works too; start claude inside that folder.
A useful side effect for notifications: each session now has its own folder name, such as feature-auth, which is exactly what you want in an alert.
Name your sessions
Names make sessions easy to find and resume:
claude -n auth-refactor
Inside a running session, /rename auth-refactor does the same, and the name appears on the prompt bar. Later, claude --resume auth-refactor takes you straight back. In the session picker (claude --resume with no name), Ctrl+W widens the list to every worktree of the repository.
03Put the project in every do-it-yourself alert
Every command hook receives JSON on standard input with fields common to all events, including session_id, cwd, transcript_path and hook_event_name. In a worktree session, cwd is the worktree root, and it follows Claude if it changes directory. Read it in your hook and use the last part of the path as the label.
On Mac and Linux, save this as ~/.claude/hooks/notify-session.sh and make it executable with chmod +x. It needs jq.
#!/bin/sh
input=$(cat)
project=$(basename "$(printf '%s' "$input" | jq -r '.cwd')")
event=$(printf '%s' "$input" | jq -r '.hook_event_name')
case "$event" in
Stop) msg="Claude has finished" ;;
*) msg="Claude needs you" ;;
esac
notify-send "Claude Code: $project" "$msg"
On a Mac, swap the last line for an osascript notification as shown in the macOS guide. On Windows, read the same JSON in PowerShell with ConvertFrom-Json; the Windows guide has a full example.
Then register it for the events you care about in ~/.claude/settings.json:
{
"hooks": {
"Stop": [
{ "hooks": [{ "type": "command", "command": "~/.claude/hooks/notify-session.sh" }] }
],
"Notification": [
{ "matcher": "permission_prompt", "hooks": [{ "type": "command", "command": "~/.claude/hooks/notify-session.sh" }] }
]
}
}
Two notes on paths. Quote variables such as "$input", because folder names can contain spaces. And if you reference a script with ${CLAUDE_PROJECT_DIR}, remember that it stays at the folder where the session started, even after Claude moves into a worktree. Read cwd from the input when you need the current folder.
If you work in tmux, the pane or window is often a better label than the folder. The tmux guide shows how to find and switch to the right pane.
04The hard part: answering the right session
A labelled alert tells you which session needs you. You still have to get to that terminal to answer. With three sessions, that means finding the right tab, scrolling to the prompt and typing. A do-it-yourself hook cannot easily send your answer back, because only the hook that is waiting inside that session can return a decision to Claude Code.
That is the gap Claude Code Notifier fills. It is an independent tool, not made by Anthropic. Its command line tool, ccn, is installed as Claude Code hooks on Mac, Windows and Linux, so every session you start is covered, in any terminal, without per-session setup. Each notification carries the project's name and folder, so on your iPhone or Android phone you can see which session sent it. Because the hook that sent the request is the one waiting for your answer, an approval, a choice or a follow-up instruction from the phone goes back to the session that asked.
A few details that matter with several sessions:
- Several computers. One phone can pair with several computers, and a computer with several phones.
ccn deviceslists the phones paired with this computer. - Presence. If you typed in the last 30 seconds, nothing waits for the phone and the terminal asks as usual. If you are away, the session waits for the phone's answer up to a ceiling you choose (
hold_ceiling_seconds) and stops waiting the moment you touch the keyboard. - Desktop notifications without a phone. Before you pair a phone,
ccnshows a desktop notification on the computer when any session finishes, needs a permission or asks a question.
If you only run one session at a time and sit at your desk, a labelled desktop alert is probably all you need. The comparison guide sets out the options side by side.
05FAQ
How do I tell which Claude Code session sent a notification?
Read the cwd field from the hook's JSON input and put the folder name in the alert title. With worktrees, each session has its own folder, so the name is distinct for every session. Tools such as Claude Code Notifier include the project name and folder in each notification for you.
Can I run two Claude Code sessions in the same repository?
Yes, but give each its own worktree so their edits do not collide. claude --worktree <name> creates one under .claude/worktrees/<name>/ on a new branch and starts the session there.
How do I name a Claude Code session?
Start it with claude -n <name>, or run /rename <name> inside a session. Resume it later with claude --resume <name>.
Do hooks run separately for each session?
Yes. Each session runs its own hooks when its events fire, and passes that session's session_id and cwd in the input. Hooks in ~/.claude/settings.json apply to every session you start.
Will notifications from different computers get mixed up?
Not with ccn. Each computer pairs with your phone separately and has its own name, and each notification carries the project it came from.