Skip to content

Instantly share code, notes, and snippets.

@scytacki
Created January 26, 2026 14:04
Show Gist options
  • Select an option

  • Save scytacki/433da05d5afa0b8532a9540760411fe2 to your computer and use it in GitHub Desktop.

Select an option

Save scytacki/433da05d5afa0b8532a9540760411fe2 to your computer and use it in GitHub Desktop.
Fix npm and cypress Claude prompt

Check if you can run npm --version in the Bash tool. If it fails, diagnose and fix the shell environment for this Claude Code session by doing the following:

  1. Check if ELECTRON_RUN_AS_NODE is set (this interferes with Electron apps like Cypress). Check if nvm exists at $HOME/.nvm/nvm.sh but isn't being sourced.

  2. If either issue exists, create a SessionStart hook to fix them permanently:

    • Create ~/.claude/hooks/setup-env.sh (make it executable) with:
      #!/bin/bash
      ENV_BEFORE=$(export -p | sort)
      export NVM_DIR="$HOME/.nvm"
      [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
      unset ELECTRON_RUN_AS_NODE
      if [ -n "$CLAUDE_ENV_FILE" ]; then
        ENV_AFTER=$(export -p | sort)
        comm -13 <(echo "$ENV_BEFORE") <(echo "$ENV_AFTER") >> "$CLAUDE_ENV_FILE"
        echo "unset ELECTRON_RUN_AS_NODE" >> "$CLAUDE_ENV_FILE"
      fi
      exit 0
    • Add the hook to ~/.claude/settings.json (merge with existing settings if the file already exists):
      {
        "hooks": {
          "SessionStart": [
            {
              "hooks": [
                {
                  "type": "command",
                  "command": "$HOME/.claude/hooks/setup-env.sh"
                }
              ]
            }
          ]
        }
      }
  3. Tell me to start a new session (using /clear or reopening the Claude Code panel) so the hook takes effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment