DEV Community

Cover image for Run `gh` Command in Claude Code on the Web
Oikon
Oikon

Posted on • Originally published at Medium

Run `gh` Command in Claude Code on the Web

I'm Oikon. I typically share Claude Code insights on X (Twitter).

Recently, Claude Code on the Web removed gh from the disallowed_tools list, making GitHub CLI available. In this article, I'll show you how to configure it. I've also published a setup package, so you can get started right away.

GitHub logo oikon48 / gh-setup-hooks

Enable `gh` command in Claude Code on the Web environment, just adding SessionStartHooks

gh-setup-hooks

npm version License: MIT

Auto-install GitHub CLI on Claude Code on the Web. Just add one line to settings.json.

Setup

1. Add hook to settings.json

Add to .claude/settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bun x gh-setup-hooks",
            "timeout": 120
          }
        ]
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

npx -y gh-setup-hooks is also ok.

2. Set up Claude Code on the Web

To use gh commands (e.g., gh pr create), you need to set GH_TOKEN or GITHUB_TOKEN:

  1. Go to Claude Code on the Web
  2. Open SettingsCustom Environment
  3. Add environment variable:

Note: The token needs repo scope for most operations.

Claude Code on the Web network should be Full or Custom. If using Custom, you need to allow release-assets.githubusercontent.com.

Cloud Environment Settings

How

TL;DR

  • Around December 17, 2025, gh was removed from disallowed_tools
  • Configure GITHUB_TOKEN in a custom environment
  • Easy setup with bun x gh-setup-hooks
  • Use CLAUDE_CODE_REMOTE to detect the "on the Web" environment

Note:
The specifications in this article are based on Claude Code on the Web as of January 8, 2026. Some setup steps may become unnecessary if gh command becomes installed by default in the future.

Quick Start

Here's how to get gh working in the shortest time possible.

1. Custom Environment Configuration

Create a custom environment in Claude Code on the Web and configure the following:

  • Environment Variable: GITHUB_TOKEN=ghp_xxxx... (Personal Access Token issued from GitHub)
  • Network Access: "Full" or "Custom" with release-assets.githubusercontent.com allowed

2. Hooks Configuration

Add the following to your repository's .claude/settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bun x gh-setup-hooks",
            "timeout": 120
          }
        ]
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

That's it! When you start a session in Claude Code on the Web, gh will be automatically installed, enabling PR creation and issue management.

⚠️ Warning:
Due to sandbox proxy configuration, you need to use the -R owner/repo flag when using gh commands. Claude Code often adds this automatically, but adding a note in CLAUDE.md makes things smoother.

What is Claude Code on the Web?

Claude Code on the Web is an environment where you can run Claude Code directly in your browser.

The main appeal is that you can develop with just a browser, even without a PC at hand. It works by cloning GitHub repositories and running Claude Code in a sandboxed environment. For detailed specifications, please check out my previous article:

As a side note, by prefixing your Claude Code prompt with &, you can send tasks from local Claude Code to Claude Code on the Web.

The Removal of gh Command Restrictions

Previously, the gh command was explicitly blocked in Claude Code on the Web. The startup options included --disallowed-tools Bash(gh:*), and the system prompt contained this statement:

The GitHub CLI (gh) is not available in this environment.

In other words, any GitHub CLI operations like creating PRs or managing issues were completely unavailable.

However, around December 17, 2025, gh had been removed from the disallowed_tools list.

The diff in data/startup.json shows that "disallowed_tools": ["Bash(gh:*)"] has been removed. This means the gh command itself is no longer blocked. However, since gh isn't installed by default, you still can't use it out of the box.

How the Setup Works

The gh-setup-hooks package uses sessionStartHooks to automatically install gh at session start.

How It Works

  1. Hook fires at session start
  2. Checks if it's a "on the Web" environment using CLAUDE_CODE_REMOTE environment variable
  3. Downloads and installs gh only in the "on the Web" environment
  4. Writes PATH to CLAUDE_ENV_FILE to enable it throughout the session

About the Environment Variables

CLAUDE_CODE_REMOTE: An environment variable set to true only in the Claude Code on the Web environment. This allows the script to skip execution in local environments and run only in the "on the Web" environment.

if [ "$CLAUDE_CODE_REMOTE" != "true" ]; then
    log "Not a remote session, skipping gh setup"
    exit 0
fi
Enter fullscreen mode Exit fullscreen mode

CLAUDE_ENV_FILE: An environment variable file path provided by Claude Code. Writing to this file persists PATH settings throughout the session.

if [ -n "$CLAUDE_ENV_FILE" ]; then
    echo "export PATH=\"$LOCAL_BIN:\$PATH\"" >> "$CLAUDE_ENV_FILE"
    log "PATH persisted to CLAUDE_ENV_FILE"
fi
Enter fullscreen mode Exit fullscreen mode

Script Details (gh-setup.sh)

If you want to write your own script instead of using the package, here's a reference:

#!/bin/bash
# SessionStart hook: GitHub CLI auto-installation for remote environments
set -e

LOG_PREFIX="[gh-setup]"
log() { echo "$LOG_PREFIX $1" >&2; }

if [ "$CLAUDE_CODE_REMOTE" != "true" ]; then
    log "Not a remote session, skipping gh setup"
    exit 0
fi

log "Remote session detected, checking gh CLI..."

if command -v gh &>/dev/null; then
    log "gh CLI already available: $(gh --version | head -1)"
    exit 0
fi

LOCAL_BIN="$HOME/.local/bin"
mkdir -p "$LOCAL_BIN"

if [ -x "$LOCAL_BIN/gh" ]; then
    log "gh found in $LOCAL_BIN"
    export PATH="$LOCAL_BIN:$PATH"
    [ -n "$CLAUDE_ENV_FILE" ] && echo "export PATH=\"$LOCAL_BIN:\$PATH\"" >> "$CLAUDE_ENV_FILE"
    exit 0
fi

log "Installing gh CLI to $LOCAL_BIN..."

TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT

ARCH=$(uname -m)
case "$ARCH" in
    x86_64) GH_ARCH="amd64" ;;
    aarch64|arm64) GH_ARCH="arm64" ;;
    *) log "Unsupported architecture: $ARCH"; exit 0 ;;
esac

GH_VERSION="2.62.0"
GH_URL="https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${GH_ARCH}.tar.gz"

curl -sL "$GH_URL" -o "$TEMP_DIR/gh.tar.gz" || { log "Failed to download"; exit 0; }
tar -xzf "$TEMP_DIR/gh.tar.gz" -C "$TEMP_DIR" || { log "Failed to extract"; exit 0; }
mv "$TEMP_DIR/gh_${GH_VERSION}_linux_${GH_ARCH}/bin/gh" "$LOCAL_BIN/gh" || { log "Failed to install"; exit 0; }

chmod +x "$LOCAL_BIN/gh"
export PATH="$LOCAL_BIN:$PATH"
[ -n "$CLAUDE_ENV_FILE" ] && echo "export PATH=\"$LOCAL_BIN:\$PATH\"" >> "$CLAUDE_ENV_FILE"

log "gh CLI installed successfully: $($LOCAL_BIN/gh --version | head -1)"
Enter fullscreen mode Exit fullscreen mode

Conclusion

With gh now available, you can read issues and execute tasks, or create PRs directly in Claude Code on the Web. The CLAUDE_CODE_REMOTE variable can also be useful for other remote-only workflows.


If you found this article valuable, follow the author on X (@oikon48) for ongoing Claude Code insights and updates.


References

GitHub

GitHub logo oikon48 / gh-setup-hooks

Enable `gh` command in Claude Code on the Web environment, just adding SessionStartHooks

gh-setup-hooks

npm version License: MIT

Auto-install GitHub CLI on Claude Code on the Web. Just add one line to settings.json.

Setup

1. Add hook to settings.json

Add to .claude/settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bun x gh-setup-hooks",
            "timeout": 120
          }
        ]
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

npx -y gh-setup-hooks is also ok.

2. Set up Claude Code on the Web

To use gh commands (e.g., gh pr create), you need to set GH_TOKEN or GITHUB_TOKEN:

  1. Go to Claude Code on the Web
  2. Open SettingsCustom Environment
  3. Add environment variable:

Note: The token needs repo scope for most operations.

Claude Code on the Web network should be Full or Custom. If using Custom, you need to allow release-assets.githubusercontent.com.

Cloud Environment Settings

How

Documentation

Claude Code on the Web - Official Documentation

Claude Code Hooks - Official Documentation

Managing Personal Access Tokens - GitHub Docs

Related Articles

Claude Code on the Web Sandbox Specifications (Japanese)

Top comments (0)