Feature request: session-start hook

Status Fixed / completed
Maintainer reply ✓ Yes — dicksontsai
Activity 4 comments · opened Mar 3, 2026 · closed Mar 8, 2026
💡 Likely answer: A maintainer (dicksontsai, collaborator) responded on this thread — see the highlighted reply below.

Feature Request

Add a session-start hook event that fires when a new Claude Code conversation begins, before any user interaction.

Use Case

Our team's CLAUDE.md contains the instruction:

Claude should WARN THE USER if it is started in a directory other than the repo root OR a project root.

This is important in our monorepo because starting Claude Code in a subdirectory like project/etc/ means .claude/ settings and skills won't be inherited correctly.

The problem: even though the instruction is in CLAUDE.md, the model doesn't reliably act on it at conversation start. It's a model behavior issue — the instruction exists, but there's no guarantee it gets prioritized before the model starts responding to the user's first message.

A session-start hook would let us enforce this programmatically with a simple shell script that checks pwd against known project roots and emits a warning. This is more reliable than depending on the model to self-check.

Proposed Behavior

A new hook event type (e.g., session-start or on-init) that:

  • Fires once when a new Claude Code session begins
  • Runs before the user's first prompt is processed
  • Can output warnings/messages that are surfaced to the model and/or user
  • Supports the same shell command configuration as existing hooks

Workarounds Considered

  • Shell alias: Wrapping the claude command to check pwd before launch. Works but is per-user setup, not portable with the repo.
  • user-prompt-submit hook: Fires on every message, not just the first. Would need state tracking to avoid repeated warnings.
  • Memory files: Redundant with CLAUDE.md — the instruction already exists, the issue is enforcement timing.

View original on GitHub ↗

4 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/17278
  2. https://github.com/anthropics/claude-code/issues/3062
  3. https://github.com/anthropics/claude-code/issues/30266

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

akostibas · 7 months ago

Update: UserPromptSubmit hook doesn't solve this

We tried implementing this as a UserPromptSubmit hook in the project's .claude/settings.json. The hook works correctly when loaded, but there's a chicken-and-egg problem:

  • The hook lives in <repo-root>/.claude/settings.json
  • If Claude Code is started in a subdirectory (e.g., project/etc/), the project-level .claude/settings.json isn't loaded
  • So the hook that would warn about being in the wrong directory... doesn't run because you're in the wrong directory

A global hook (~/.claude/settings.json) could work technically, but it would need repo-specific logic in a global config, which isn't portable or maintainable.

This reinforces the need for a proper session-start hook — or alternatively, a way for project-level hooks to be discovered from parent directories even when Claude Code is started in a subdirectory.

dicksontsai collaborator · 7 months ago

A SessionStart hooks already exists for this purpose. See https://code.claude.com/docs/en/hooks#sessionstart

github-actions[bot] · 7 months ago

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.