cross-platform-compatibility
Handle cross-platform compatibility including file paths, environment detection, platform-specific dependencies, and testing across Windows, macOS, and Linux. Use when dealing with platform-specific code or OS compatibility.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o cross-platform-compatibility.zip https://jpskill.com/download/21383.zip && unzip -o cross-platform-compatibility.zip && rm cross-platform-compatibility.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21383.zip -OutFile "$d\cross-platform-compatibility.zip"; Expand-Archive "$d\cross-platform-compatibility.zip" -DestinationPath $d -Force; ri "$d\cross-platform-compatibility.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
cross-platform-compatibility.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
cross-platform-compatibilityフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 13
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
クロスプラットフォーム互換性
目次
概要
Windows、macOS、Linux でシームレスに動作するコードを記述するための包括的なガイドです。ファイルパスの処理、環境検出、プラットフォーム固有の機能、およびテスト戦略について説明します。
使用場面
- 複数のオペレーティングシステム向けアプリケーションの構築
- ファイルシステム操作の処理
- プラットフォーム固有の依存関係の管理
- オペレーティングシステムとアーキテクチャの検出
- 環境変数の操作
- クロスプラットフォーム CLI ツールの構築
- 改行コードと文字エンコーディングの処理
- プラットフォーム固有のビルドプロセスの管理
クイックスタート
最小限の動作例です。
// ❌ BAD: プラットフォーム固有の区切り文字を含むハードコードされたパス
const configPath = "C:\\Users\\user\\config.json"; // Windowsのみ
const dataPath = "/home/user/data.txt"; // Unixのみ
// ✅ GOOD: pathモジュールを使用
import path from "path";
import os from "os";
// プラットフォームに依存しないパスの構築
const configPath = path.join(os.homedir(), "config", "app.json");
const dataPath = path.join(process.cwd(), "data", "users.txt");
// 相対パスの解決
const absolutePath = path.resolve("./config/settings.json");
// パスコンポーネントの取得
const dirname = path.dirname("/path/to/file.txt"); // '/path/to'
const basename = path.basename("/path/to/file.txt"); // 'file.txt'
const extname = path.extname("/path/to/file.txt"); // '.txt'
// パスの正規化 (.. と . を処理)
const normalized = path.normalize("/path/to/../file.txt"); // '/path/file.txt'
リファレンスガイド
references/ ディレクトリ内の詳細な実装です。
| ガイド | 内容 |
|---|---|
| ファイルパスの処理 | ファイルパスの処理 |
| プラットフォーム検出 | プラットフォーム検出 |
| 改行コード | 改行コード |
| 環境変数 | 環境変数 |
| シェルコマンド | シェルコマンド |
| ファイルパーミッション | ファイルパーミッション |
| プロセス管理 | プロセス管理 |
| プラットフォーム固有の依存関係 | プラットフォーム固有の依存関係 |
| 複数プラットフォームでのテスト | 複数プラットフォームでのテスト |
| 文字エンコーディング | 文字エンコーディング |
| ビルド設定 | ビルド設定 |
ベストプラクティス
✅ するべきこと
- パスには path.join() または path.resolve() を使用する
- 改行コードには os.EOL を使用する
- 必要に応じて実行時にプラットフォームを検出する
- すべてのターゲットプラットフォームでテストする
- プラットフォーム固有のモジュールには optionalDependencies を使用する
- ファイルパーミッションを適切に処理する
- ユーザー入力にはシェルエスケープを使用する
- テキストファイルの改行コードを正規化する
- デフォルトで UTF-8 エンコーディングを使用する
- プラットフォーム固有の動作を文書化する
- プラットフォーム固有の機能にはフォールバックを提供する
- CI/CD を使用して複数のプラットフォームでテストする
❌ するべきではないこと
- バックスラッシュまたはスラッシュを含むファイルパスをハードコードする
- Unix 専用の機能(シグナル、パーミッション、シンボリックリンク)を前提とする
- Windows 固有の癖(ドライブレター、UNC パス)を無視する
- フォールバックなしでプラットフォーム固有のコマンドを使用する
- 大文字と小文字を区別するファイルシステムを前提とする
- 異なる改行コードを忘れる
- チェックせずにプラットフォーム固有の API を使用する
- 環境変数へのアクセスパターンをハードコードする
- 文字エンコーディングの問題を無視する
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Cross-Platform Compatibility
Table of Contents
Overview
Comprehensive guide to writing code that works seamlessly across Windows, macOS, and Linux. Covers file path handling, environment detection, platform-specific features, and testing strategies.
When to Use
- Building applications for multiple operating systems
- Handling file system operations
- Managing platform-specific dependencies
- Detecting operating system and architecture
- Working with environment variables
- Building cross-platform CLI tools
- Dealing with line endings and character encodings
- Managing platform-specific build processes
Quick Start
Minimal working example:
// ❌ BAD: Hardcoded paths with platform-specific separators
const configPath = "C:\\Users\\user\\config.json"; // Windows only
const dataPath = "/home/user/data.txt"; // Unix only
// ✅ GOOD: Use path module
import path from "path";
import os from "os";
// Platform-independent path construction
const configPath = path.join(os.homedir(), "config", "app.json");
const dataPath = path.join(process.cwd(), "data", "users.txt");
// Resolve relative paths
const absolutePath = path.resolve("./config/settings.json");
// Get path components
const dirname = path.dirname("/path/to/file.txt"); // '/path/to'
const basename = path.basename("/path/to/file.txt"); // 'file.txt'
const extname = path.extname("/path/to/file.txt"); // '.txt'
// Normalize paths (handle .. and .)
const normalized = path.normalize("/path/to/../file.txt"); // '/path/file.txt'
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| File Path Handling | File Path Handling |
| Platform Detection | Platform Detection |
| Line Endings | Line Endings |
| Environment Variables | Environment Variables |
| Shell Commands | Shell Commands |
| File Permissions | File Permissions |
| Process Management | Process Management |
| Platform-Specific Dependencies | Platform-Specific Dependencies |
| Testing Across Platforms | Testing Across Platforms |
| Character Encoding | Character Encoding |
| Build Configuration | Build Configuration |
Best Practices
✅ DO
- Use path.join() or path.resolve() for paths
- Use os.EOL for line endings
- Detect platform at runtime when needed
- Test on all target platforms
- Use optionalDependencies for platform-specific modules
- Handle file permissions gracefully
- Use shell escaping for user input
- Normalize line endings in text files
- Use UTF-8 encoding by default
- Document platform-specific behavior
- Provide fallbacks for platform-specific features
- Use CI/CD to test on multiple platforms
❌ DON'T
- Hardcode file paths with backslashes or forward slashes
- Assume Unix-only features (signals, permissions, symlinks)
- Ignore Windows-specific quirks (drive letters, UNC paths)
- Use platform-specific commands without fallbacks
- Assume case-sensitive file systems
- Forget about different line endings
- Use platform-specific APIs without checking
- Hardcode environment variable access patterns
- Ignore character encoding issues
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (3,973 bytes)
- 📎 references/build-configuration.md (562 bytes)
- 📎 references/character-encoding.md (1,395 bytes)
- 📎 references/environment-variables.md (1,007 bytes)
- 📎 references/file-path-handling.md (2,346 bytes)
- 📎 references/file-permissions.md (965 bytes)
- 📎 references/line-endings.md (990 bytes)
- 📎 references/platform-detection.md (2,313 bytes)
- 📎 references/platform-specific-dependencies.md (1,001 bytes)
- 📎 references/process-management.md (1,551 bytes)
- 📎 references/shell-commands.md (1,521 bytes)
- 📎 references/testing-across-platforms.md (1,888 bytes)
- 📎 scripts/scaffold-tests.sh (574 bytes)