From f1a84ddbde711a4ff75cbd04321bea707ce3de47 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 21 Dec 2025 22:22:35 -0800 Subject: [PATCH] feat: add Claude Code web session setup with gh CLI and worktree support (#8249) * feat: add SessionStart hook for Claude Code on the web Adds a session-start hook that runs in remote environments to: - Install all dependencies (npm run install:all) - Generate gRPC/protobuf types (npm run protos) This enables Claude Code web sessions to properly run tests and linters. * feat: add .worktreeinclude for Claude Code worktrees Ensures environment files and local settings are copied to new worktrees: - .env files - .clineignore - Local Claude settings * fix: include node_modules and generated files in worktreeinclude Copying these to worktrees saves significant setup time: - node_modules: skips npm install (~1-2 min) - src/generated/, src/shared/proto/: skips proto generation * feat: install gh CLI and add GITHUB_TOKEN support in session hook - Rename session-start.sh to claude-code-for-web-setup.sh - Install latest gh CLI from GitHub releases - Check for GITHUB_TOKEN and inform Claude about gh availability - Enables using `gh issue`, `gh pr` commands when token is configured * refactor: make .worktreeinclude a symlink to .gitignore --- .claude/hooks/claude-code-for-web-setup.sh | 51 ++++++++++++++++++++++ .claude/settings.json | 14 ++++++ .worktreeinclude | 1 + 3 files changed, 66 insertions(+) create mode 100755 .claude/hooks/claude-code-for-web-setup.sh create mode 100644 .claude/settings.json create mode 120000 .worktreeinclude diff --git a/.claude/hooks/claude-code-for-web-setup.sh b/.claude/hooks/claude-code-for-web-setup.sh new file mode 100755 index 00000000..38cb4298 --- /dev/null +++ b/.claude/hooks/claude-code-for-web-setup.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -euo pipefail + +# Only run in Claude Code remote environments +if [ "${CLAUDE_CODE_REMOTE:-}" != "true" ]; then + exit 0 +fi + +cd "$CLAUDE_PROJECT_DIR" + +echo "=== Claude Code for Web Setup ===" +echo "" + +# Install latest gh CLI tool +echo "Installing GitHub CLI..." +GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep '"tag_name"' | cut -d'"' -f4 | sed 's/^v//') +curl -sL "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" -o /tmp/gh.tar.gz +tar -xzf /tmp/gh.tar.gz -C /tmp +sudo mv "/tmp/gh_${GH_VERSION}_linux_amd64/bin/gh" /usr/local/bin/gh +rm -rf /tmp/gh.tar.gz /tmp/gh_${GH_VERSION}_linux_amd64 +echo "Installed gh version: $(gh --version | head -1)" +echo "" + +# Check if GITHUB_TOKEN is set and configure gh +if [ -n "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is configured - gh CLI is ready to use" + echo "" + echo "You can use gh commands directly, for example:" + echo " gh issue list --repo cline/cline --limit 5" + echo " gh pr list --repo cline/cline --state open" + echo " gh issue view 123 --repo cline/cline" + echo "" +else + echo "GITHUB_TOKEN is not set - gh CLI will have limited functionality" + echo "" + echo "To enable full GitHub API access:" + echo "1. Create a Fine-grained Personal Access Token at https://github.com/settings/tokens?type=beta" + echo "2. Add it as GITHUB_TOKEN in your Claude Code environment settings" + echo "" +fi + +# Install project dependencies +echo "Installing dependencies..." +npm run install:all + +# Generate gRPC/protobuf types (required for TypeScript) +echo "Generating proto types..." +npm run protos + +echo "" +echo "Session setup complete!" diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 00000000..2e612c9c --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,14 @@ +{ + "hooks": { + "SessionStart": [ + { + "hooks": [ + { + "type": "command", + "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/claude-code-for-web-setup.sh" + } + ] + } + ] + } +} diff --git a/.worktreeinclude b/.worktreeinclude new file mode 120000 index 00000000..3e4e48b0 --- /dev/null +++ b/.worktreeinclude @@ -0,0 +1 @@ +.gitignore \ No newline at end of file