Skip to content

Add Claude session initialization with npm dependency setup#2

Closed
MahammadNuriyev62 wants to merge 1 commit intomasterfrom
claude/setup-web-connector-Ju4dR
Closed

Add Claude session initialization with npm dependency setup#2
MahammadNuriyev62 wants to merge 1 commit intomasterfrom
claude/setup-web-connector-Ju4dR

Conversation

@MahammadNuriyev62
Copy link
Copy Markdown
Owner

Summary

This PR adds automatic dependency installation for Claude remote sessions by introducing a session start hook that runs npm install when Claude connects in web environments.

Changes

  • Added .claude/hooks/session-start.sh: A bash script that automatically installs npm dependencies when a remote Claude session starts. The script only executes in remote (web) environments to avoid unnecessary runs in local development.
  • Added .claude/settings.json: Configuration file that registers the session start hook to run during Claude session initialization.
  • Updated .gitignore: Modified to allow .claude/settings.json and .claude/hooks/ to be committed to the repository while keeping other .claude/ contents ignored.

Implementation Details

  • The session start hook checks the CLAUDE_CODE_REMOTE environment variable to ensure it only runs in remote environments
  • Uses set -euo pipefail for robust error handling in the bash script
  • Leverages CLAUDE_PROJECT_DIR environment variable for proper project directory resolution
  • The gitignore pattern uses negation rules to selectively include specific .claude/ files while excluding others

This ensures that Claude sessions in web environments have all necessary dependencies installed automatically without manual intervention.

https://claude.ai/code/session_01JgNTrM3pwNC2NDT97TBJj5

Set up .claude/hooks/session-start.sh to install npm dependencies
when running in Claude Code on the web. Register the hook in
.claude/settings.json and update .gitignore to track the .claude
config files.

https://claude.ai/code/session_01JgNTrM3pwNC2NDT97TBJj5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants