claude-code - 💡(How to fix) Fix [FEATURE] Feature request: Session start hook or --init-command CLI flag for automatic setup on launch [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56302Fetched 2026-05-06 06:31:43
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

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.

Root Cause

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.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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)

  1. SessionStart hook type — fires once when a session begins, with access to cwd for conditional logic:
    {                                                                                                            
      "hooks": {                                                                                                 
        "SessionStart": [                                                                                        
          {                                                                                                      
            "matcher": { "cwd_pattern": "/my/sandbox/dir/abc/.*" },                                          
            "commands": ["/sandbox"]                                                                             
          }                                                                                                      
        ]                                                                                                        
      }                                                                                                          
    }
  2. CLI flag like --init-command "/sandbox" that executes a slash command after interactive startup completes.
  3. 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

extent analysis

TL;DR

Implementing a SessionStart hook or adding a CLI flag like --init-command could enable running a slash command automatically when a Claude Code session starts.

Guidance

  • Consider adding a SessionStart hook with a cwd_pattern matcher to conditionally run the desired command based on the working directory.
  • Evaluate the feasibility of introducing a CLI flag, such as --init-command, to execute a slash command after interactive startup.
  • Assess the potential of adding a startup_commands field in .claude/settings.json to list slash commands for automatic execution on launch.
  • Review the proposed solutions to determine which one best fits the requirements and is most straightforward to implement.

Example

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": { "cwd_pattern": "/my/sandbox/dir/abc/.*" },
        "commands": ["/sandbox"]
      }
    ]
  }
}

Notes

The choice of solution depends on the specific requirements and constraints of the Claude Code system, including potential limitations on hook functionality, CLI flag parsing, and configuration file handling.

Recommendation

Apply workaround by introducing a SessionStart hook, as it provides flexibility and conditional logic based on the working directory.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [FEATURE] Feature request: Session start hook or --init-command CLI flag for automatic setup on launch [1 participants]