Skip to main content

Overview

Platform detection utilities help you identify which host platform (ChatGPT, Claude, etc.) is running your app, so you can conditionally use platform-specific features.

Import

import { detectPlatform, isChatGPT, isClaude } from 'sunpeak/platform';

detectPlatform

Detect the current host platform.

Signature

function detectPlatform(): Platform

Platform Type

type Platform = 'chatgpt' | 'claude' | 'unknown';

Detection Order

  1. Runtime objects — checks for window.openai (injected by ChatGPT and by the simulator when ChatGPT host is selected)
  2. User agent — checks navigator.userAgent for platform identifiers
  3. Hostname — checks window.location.hostname for known host domains

Usage

import { detectPlatform } from 'sunpeak/platform';

function MyResource() {
  const platform = detectPlatform();

  switch (platform) {
    case 'chatgpt':
      return <ChatGPTFeatures />;
    case 'claude':
      return <ClaudeFeatures />;
    default:
      return <GenericUI />;
  }
}

isChatGPT

Check if the app is running in a ChatGPT host.

Signature

function isChatGPT(): boolean

Usage

import { isChatGPT } from 'sunpeak/platform';
import { useUploadFile } from 'sunpeak/platform/chatgpt';

function MyResource() {
  if (!isChatGPT()) {
    return <p>Upload requires ChatGPT.</p>;
  }
  return <Uploader />;
}

function Uploader() {
  const uploadFile = useUploadFile();
  // ...
}

isClaude

Check if the app is running in a Claude host.

Signature

function isClaude(): boolean

Usage

import { isClaude } from 'sunpeak/platform';

function MyResource() {
  if (isClaude()) {
    // Claude-specific behavior
  }
}

Simulator Behavior

In the Simulator, platform detection reflects the currently selected host:
Host selectedisChatGPT()isClaude()detectPlatform()
ChatGPTtruefalse'chatgpt'
Claudefalsefalse*'unknown'*
* Claude detection relies on user agent or hostname, which aren’t present in the simulator. Use useHostContext() to read host identity from the MCP protocol instead.

See Also

ChatGPT Hooks

Platform-specific hooks for ChatGPT features.

useHostContext

Read host identity and capabilities via the MCP protocol.