[FEATURE] Feature request: Session start hook or --init-command CLI flag for automatic setup on launch
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Summary
I'd like the ability to automatically run a slash command (or shell command) when a Claude Code session starts,
optionally conditioned on the working directory.
## Current Limitation
- Available hooks (
PreToolUse,PostToolUse,Notification) only fire during tool execution, not on session
start.
- There's no CLI flag to inject an initial command into an interactive session.
- Shell wrappers (
<<<,expect) are fragile and break interactive stdin.
Proposed Solution
Proposed Solutions (any one would work)
SessionStarthook type — fires once when a session begins, with access tocwdfor conditional logic:
```json
{
"hooks": {
"SessionStart": [
{
"matcher": { "cwd_pattern": "/my/sandbox/dir/abc/.*" },
"commands": ["/sandbox"]
}
]
}
}
- CLI flag like --init-command "/sandbox" that executes a slash command after interactive startup completes.
- startup_commands field in .claude/settings.json that lists slash commands to run on launch:
{
"startup_commands": ["/sandbox"]
}
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
Use Case
I work across multiple project trees. When launching Claude from directories under a specific path (e.g.,
/my/sandbox/dir/abc/), I need /sandbox to run automatically to configure the session environment.
Currently I have to remember to type it manually every time.
Additional Context
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗