From 882d9ba859c179deb34b29a9392b2dfaf8a4490e Mon Sep 17 00:00:00 2001 From: sususu Date: Mon, 3 Nov 2025 12:07:43 +0800 Subject: [PATCH] docs: Standardize XCodeCLI casing in setup script --- .gitignore | 1 + CLAUDE.md | 111 +++++++++++++++++++++ README.md | 224 +++++++++++++++++++++++++++++++++++++++++++ setup-claude-code.sh | 10 +- 4 files changed, 341 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 CLAUDE.md create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6b130c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.claude/settings.local.json diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..388b0f5 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,111 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## 项目概述 + +XCodeCLI-Shells 是一个配置工具集,用于设置 Claude Code 与 XCodeCLI API 路由器的集成。项目包含跨平台的安装脚本,支持 Windows (PowerShell) 和 Unix/Linux/macOS (Bash)。 + +## 核心架构 + +### 脚本功能 +- **setup-claude-code.ps1**: Windows PowerShell 配置脚本 +- **setup-claude-code.sh**: Unix/Linux/macOS Bash 配置脚本 + +两个脚本提供相同的功能: +- 验证 API 密钥格式 +- 测试 API 连接 +- 创建 Claude Code 配置文件 (~/.claude/settings.json) +- 设置环境变量 (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN) +- 支持团队和个人 API 端点 + +### 配置结构 +脚本生成的 settings.json 包含: +```json +{ + "env": { + "ANTHROPIC_BASE_URL": "<用户提供的URL>", + "ANTHROPIC_AUTH_TOKEN": "<用户API密钥>", + "CLAUDE_CODE_MAX_OUTPUT_TOKENS": 20000, + "DISABLE_TELEMETRY": 1, + "DISABLE_ERROR_REPORTING": 1, + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1, + "CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR": 1, + "MAX_THINKING_TOKENS": 12000 + }, + "model": "sonnet" +} +``` + +## 常用命令 + +### Windows (PowerShell) +```powershell +# 基本使用 +.\setup-claude-code.ps1 -BaseUrl https://api.xcodecli.com -ApiKey your-api-key + +# 测试连接 +.\setup-claude-code.ps1 -Test -BaseUrl https://api.xcodecli.com -ApiKey your-api-key + +# 显示当前设置 +.\setup-claude-code.ps1 -Show + +# 交互模式 +.\setup-claude-code.ps1 + +# 帮助 +.\setup-claude-code.ps1 -Help +``` + +### Unix/Linux/macOS (Bash) +```bash +# 基本使用 +./setup-claude-code.sh --url https://api.xcodecli.com --key your-api-key + +# 测试连接 +./setup-claude-code.sh --test --url https://api.xcodecli.com --key your-api-key + +# 显示当前设置 +./setup-claude-code.sh --show + +# 交互模式 +./setup-claude-code.sh + +# 帮助 +./setup-claude-code.sh --help +``` + +## API 端点支持 + +### 个人 API +- 端点: `/api/v1/claude/balance` +- 响应字段: `balance` + +### 团队 API +- 端点: `/api/v1/team/stats/spending` +- 响应字段: `daily_remaining` +- URL 格式: 必须以 `/team` 结尾 + +## 开发注意事项 + +### PowerShell 脚本特性 +- 支持执行策略绕过: `powershell -ExecutionPolicy Bypass` +- 彩色输出功能 (Blue/Green/Yellow/Red) +- 环境变量持久化 (用户级别) +- JSON 配置验证 + +### Bash 脚本特性 +- 依赖 jq 进行 JSON 处理 +- ANSI 颜色输出 +- 临时文件清理 +- 错误处理和回滚机制 + +### 安全考虑 +- API 密钥格式验证 (仅允许字母数字、连字符、下划线) +- 配置文件自动备份 (时间戳) +- 敏感信息掩码显示 +- HTTP 状态码验证 + +### 配置文件位置 +- Windows: `%USERPROFILE%\.claude\settings.json` +- Unix/Linux/macOS: `~/.claude/settings.json` \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..495db84 --- /dev/null +++ b/README.md @@ -0,0 +1,224 @@ +# XCodeCLI-Shells + +> Configuration scripts for integrating Claude Code with XCodeCLI API router + +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux%20%7C%20macOS-blue.svg)](https://github.com/your-username/XCodeCLI-Shells) + +## Overview + +XCodeCLI-Shells is a cross-platform configuration toolkit for setting up Claude Code integration with XCodeCLI API router. These scripts enable you to easily configure Claude Code to use custom API endpoints, supporting both personal and team API access. + +## Features + +- 🌐 **Cross-platform support**: Windows (PowerShell) and Unix/Linux/macOS (Bash) +- 🔐 **Security validation**: API key format validation and connection testing +- ⚡ **Quick setup**: Auto-generates Claude Code configuration files and environment variables +- 🛡️ **Data protection**: Automatic backup of existing configs, sensitive info masking +- 🎯 **Multi-endpoint support**: Supports both personal and team API endpoints +- 📊 **Real-time feedback**: Colored output and detailed status information + +## Quick Start + +### Requirements + +#### Windows +- PowerShell 5.0 or higher +- Internet connection + +#### Unix/Linux/macOS +- Bash shell +- `jq` command-line tool +- `curl` tool + +### Install jq (Unix/Linux/macOS only) + +```bash +# macOS (using Homebrew) +brew install jq + +# Ubuntu/Debian +sudo apt-get install jq + +# CentOS/RHEL/Fedora +sudo yum install jq +# or (newer versions) +sudo dnf install jq +``` + +## Usage + +### Windows (PowerShell) + +#### Basic usage +```powershell +.\setup-claude-code.ps1 -BaseUrl https://api.xcodecli.com -ApiKey your-api-key-here +``` + +#### Interactive mode +```powershell +.\setup-claude-code.ps1 +``` + +#### Test connection +```powershell +.\setup-claude-code.ps1 -Test -BaseUrl https://api.xcodecli.com -ApiKey your-api-key-here +``` + +#### Show current settings +```powershell +.\setup-claude-code.ps1 -Show +``` + +#### Help +```powershell +.\setup-claude-code.ps1 -Help +``` + +### Unix/Linux/macOS (Bash) + +#### Basic usage +```bash +./setup-claude-code.sh --url https://api.xcodecli.com --key your-api-key-here +``` + +#### Interactive mode +```bash +./setup-claude-code.sh +``` + +#### Test connection +```bash +./setup-claude-code.sh --test --url https://api.xcodecli.com --key your-api-key-here +``` + +#### Show current settings +```bash +./setup-claude-code.sh --show +``` + +#### Help +```bash +./setup-claude-code.sh --help +``` + +## Parameters + +### PowerShell Script Parameters + +| Parameter | Type | Description | +|-----------|------|-------------| +| `-BaseUrl` | String | XCodeCLI API base URL | +| `-ApiKey` | String | API key | +| `-Test` | Switch | Test API connection only | +| `-Show` | Switch | Show current settings | +| `-Help` | Switch | Show help information | + +### Bash Script Parameters + +| Parameter | Type | Description | +|-----------|------|-------------| +| `-u, --url` | String | XCodeCLI API base URL | +| `-k, --key` | String | API key | +| `-t, --test` | Flag | Test API connection only | +| `-s, --show` | Flag | Show current settings | +| `-h, --help` | Flag | Show help information | + +## API Endpoint Support + +### Personal API +- **Endpoint**: `/api/v1/claude/balance` +- **Response field**: `balance` +- **Usage**: Query personal account balance + +### Team API +- **Endpoint**: `/api/v1/team/stats/spending` +- **Response field**: `daily_remaining` +- **Usage**: Query team daily remaining quota +- **URL format**: Must end with `/team` + +## Configuration Files + +Scripts create configuration files at: + +- **Windows**: `%USERPROFILE%\.claude\settings.json` +- **Unix/Linux/macOS**: `~/.claude/settings.json` + +### Configuration Structure + +```json +{ + "env": { + "ANTHROPIC_BASE_URL": "https://api.xcodecli.com", + "ANTHROPIC_AUTH_TOKEN": "your-api-key", + "CLAUDE_CODE_MAX_OUTPUT_TOKENS": 20000, + "DISABLE_TELEMETRY": 1, + "DISABLE_ERROR_REPORTING": 1, + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1, + "CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR": 1, + "MAX_THINKING_TOKENS": 12000 + }, + "model": "sonnet" +} +``` + +## Security Features + +- **API key validation**: Only accepts keys with alphanumeric characters, hyphens, and underscores +- **Configuration backup**: Auto-backup existing config files (with timestamp) +- **Sensitive info protection**: Automatic masking of API keys in output +- **Connection verification**: Test API connection validity before configuration + +## Troubleshooting + +### Windows PowerShell Execution Policy Error + +If you encounter execution policy errors, use: + +```powershell +powershell -ExecutionPolicy Bypass -File setup-claude-code.ps1 +``` + +### Unix/Linux/macOS Permission Issues + +Ensure the script has execute permissions: + +```bash +chmod +x setup-claude-code.sh +``` + +### jq Not Installed Error + +Please install `jq` tool according to the [Requirements](#requirements) section. + +### API Connection Failed + +1. Check network connection +2. Verify API URL is correct +3. Confirm API key validity +4. Check firewall settings + +## Verify Installation + +After installation, you can verify Claude Code configuration with: + +```bash +claude --version +``` + +## Contributing + +Welcome to submit Issues and Pull Requests to improve this project. + +## License + +This project is licensed under the MIT License. See [LICENSE](LICENSE) file for details. + +## Related Links + +- [Claude Code Official Documentation](https://docs.claude.com/en/docs/claude-code) +- [XCodeCLI Project](https://github.com/your-username/XCodeCLI) + +--- + +**Note**: Please keep your API key secure and do not commit configuration files containing real API keys to public repositories. \ No newline at end of file diff --git a/setup-claude-code.sh b/setup-claude-code.sh index 436a1c7..008be10 100644 --- a/setup-claude-code.sh +++ b/setup-claude-code.sh @@ -1,7 +1,7 @@ #!/bin/bash -# Claude Code Configuration Script for xcodecli -# This script configures Claude Code to use your xcodecli instance +# Claude Code Configuration Script for XCodeCLI +# This script configures Claude Code to use your XCodeCLI instance set -e @@ -172,7 +172,7 @@ display_settings() { # Main function main() { - print_info "Claude Code Configuration Script for xcodecli" + print_info "Claude Code Configuration Script for XCodeCLI" echo "=======================================================" echo @@ -208,7 +208,7 @@ main() { Usage: $0 [OPTIONS] Options: - -u, --url URL Set the xcodecli base URL (default: $DEFAULT_BASE_URL) + -u, --url URL Set the XCodeCLI base URL (default: $DEFAULT_BASE_URL) -k, --key KEY Set the API key -t, --test Test API connection only (requires -u and -k) -s, --show Show current settings and exit @@ -244,7 +244,7 @@ EOF echo # Get base URL - read -p "Enter xcodecli URL [$DEFAULT_BASE_URL]: " base_url + read -p "Enter XCodeCLI URL [$DEFAULT_BASE_URL]: " base_url if [ -z "$base_url" ]; then base_url="$DEFAULT_BASE_URL" fi