### Ask Claude Code About Project Source: https://code.claude.com/docs/zh-CN/quickstart Examples of natural language queries to ask Claude Code about a project's purpose, technologies, entry points, and folder structure. ```bash > what does this project do? ``` ```bash > what technologies does this project use? ``` ```bash > where is the main entry point? ``` ```bash > explain the folder structure ``` -------------------------------- ### Use Git with Claude Code Source: https://code.claude.com/docs/zh-CN/quickstart Examples of conversational Git commands for checking changed files, committing changes, creating branches, viewing commit history, and resolving merge conflicts. ```bash > what files have I changed? ``` ```bash > commit my changes with a descriptive message ``` ```bash > create a new branch called feature/quickstart ``` ```bash > show me the last 5 commits ``` ```bash > help me resolve merge conflicts ``` -------------------------------- ### Common Claude Code Workflows Source: https://code.claude.com/docs/zh-CN/quickstart Examples of advanced workflows using Claude Code, including refactoring code, writing unit tests, updating documentation, and performing code reviews. ```bash > refactor the authentication module to use async/await instead of callbacks ``` ```bash > write unit tests for the calculator functions ``` ```bash > update the README with installation instructions ``` ```bash > review my changes and suggest improvements ``` -------------------------------- ### Ask Claude Code About Itself Source: https://code.claude.com/docs/zh-CN/quickstart Queries to understand Claude Code's capabilities, usage of slash commands, and compatibility with tools like Docker. ```bash > what can Claude Code do? ``` ```bash > how do I use slash commands in Claude Code? ``` ```bash > can Claude Code work with Docker? ``` -------------------------------- ### Configure Automatic Dependency Installation with SessionStart Hooks Source: https://code.claude.com/docs/zh-CN/claude-code-on-the-web This snippet demonstrates how to configure automatic dependency installation using SessionStart hooks in a `.claude/settings.json` file. It specifies a command to execute a shell script for installing packages. This is useful for ensuring all necessary dependencies are available when a session starts. ```json { "hooks": { "SessionStart": [ { "matcher": "startup", "hooks": [ { "type": "command", "command": ""$CLAUDE_PROJECT_DIR"/scripts/install_pkgs.sh" } ] } ] } } ``` -------------------------------- ### Login to Claude Account Source: https://code.claude.com/docs/zh-CN/quickstart Initiates the login process for Claude Code. This command prompts the user to authenticate using their Claude.ai or Claude Console account. ```bash /login ``` -------------------------------- ### Add Demo Plugin Marketplace (Shell) Source: https://code.claude.com/docs/zh-CN/discover-plugins Command to add the demo plugin marketplace maintained by Anthropic. This makes example plugins available for discovery and installation. ```shell /plugin marketplace add anthropics/claude-code ``` -------------------------------- ### SessionStart Hook Input Example (JSON) Source: https://code.claude.com/docs/zh-CN/hooks An example of the JSON input for the SessionStart hook. It contains basic session identifiers and the source from which the session was started. ```json { "session_id": "abc123", "transcript_path": "~/.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl", "permission_mode": "default", "hook_event_name": "SessionStart", "source": "startup" } ``` -------------------------------- ### Install Plugin from Demo Marketplace (Shell) Source: https://code.claude.com/docs/zh-CN/discover-plugins Command to install a specific plugin from the demo marketplace. The format includes the plugin name and the marketplace identifier. ```shell /plugin install commit-commands@anthropics-claude-code ``` -------------------------------- ### Execute Commit Command Plugin (Shell) Source: https://code.claude.com/docs/zh-CN/discover-plugins Example of using a plugin command after installation. This specific command, 'commit-commands:commit', is used to stage changes, generate a commit message, and create a commit. ```shell /commit-commands:commit ``` -------------------------------- ### Install Plugin from Local Marketplace Source: https://code.claude.com/docs/zh-CN/plugin-marketplaces Command to install a specific plugin from a locally added marketplace. This is useful for testing individual plugins within your local development environment. ```shell /plugin install test-plugin@my-local-marketplace ``` -------------------------------- ### Request Code Change Source: https://code.claude.com/docs/zh-CN/quickstart A natural language request for Claude Code to add a 'hello world' function to the main file. Claude will suggest, request approval, and then apply the change. ```bash > add a hello world function to the main file ``` -------------------------------- ### Install Plugin from Official Anthropic Market (Shell) Source: https://code.claude.com/docs/zh-CN/discover-plugins Command to install a plugin directly from the official Anthropic marketplace. This requires the plugin name and the marketplace identifier. ```shell /plugin install plugin-name@claude-plugins-official ``` -------------------------------- ### Fix Bugs or Add Features with Claude Code Source: https://code.claude.com/docs/zh-CN/quickstart Examples of natural language requests for Claude Code to implement features like input validation or fix bugs such as allowing empty form submissions. Claude will locate code, understand context, implement solutions, and run tests if available. ```bash > add input validation to the user registration form ``` ```bash > there's a bug where users can submit empty forms - fix it ``` -------------------------------- ### Install Sandbox Dependencies in WSL (Fedora) Source: https://code.claude.com/docs/zh-CN/troubleshooting Installs required packages for sandboxing functionality in WSL environments running Fedora. The command uses dnf to install 'bubblewrap' and 'socat', essential components for the sandbox feature. ```bash sudo dnf install bubblewrap socat ``` -------------------------------- ### Install Sandbox Dependencies in WSL (Ubuntu/Debian) Source: https://code.claude.com/docs/zh-CN/troubleshooting Installs necessary packages for sandboxing functionality in WSL environments running Ubuntu or Debian. The command uses apt-get to install 'bubblewrap' and 'socat', which are required for the sandbox feature. ```bash sudo apt-get install bubblewrap socat ``` -------------------------------- ### 管理已安装的插件 Source: https://code.claude.com/docs/zh-CN/discover-plugins 使用 CLI 命令来禁用、重新启用或卸载插件。`--scope` 选项可用于指定操作的应用范围(例如,项目范围)。 ```shell /plugin disable plugin-name@marketplace-name ``` ```shell /plugin enable plugin-name@marketplace-name ``` ```shell /plugin uninstall plugin-name@marketplace-name ``` ```shell claude plugin install formatter@your-org --scope project ``` ```shell claude plugin uninstall formatter@your-org --scope project ``` -------------------------------- ### Installing Ripgrep for Claude Code Search Source: https://code.claude.com/docs/zh-CN/troubleshooting Instructions for installing the 'ripgrep' utility on various operating systems, which is required for Claude Code's search and discovery features to function correctly. After installation, setting the USE_BUILTIN_RIPGREP environment variable to 0 is recommended. ```shell # macOS (Homebrew) brew install ripgrep # Windows (winget) winget install BurntSushi.ripgrep.MSVC # Ubuntu/Debian sudo apt install ripgrep # Alpine Linux apk add ripgrep # Arch Linux Pacman -S ripgrep ``` -------------------------------- ### Native Claude Code Installation Script (Windows PowerShell) Source: https://code.claude.com/docs/zh-CN/troubleshooting Installs Claude Code natively on Windows using PowerShell, avoiding npm and Node.js. It supports installing the stable, latest, or a specific version of the tool via an Invoke-RestMethod (irm) command. ```powershell # Install stable version (default) irm https://claude.ai/install.ps1 | iex # Install latest version & ([scriptblock]::Create((irm https://claude.ai/install.ps1))) latest # Install specific version number & ([scriptblock]::Create((irm https://claude.ai/install.ps1))) 1.0.58 ``` -------------------------------- ### 从远程 URL 添加插件市场 Source: https://code.claude.com/docs/zh-CN/discover-plugins 通过提供远程 `marketplace.json` 文件的 URL 来添加插件市场。请注意,基于 URL 的市场可能存在一些限制,例如在处理相对路径插件时可能出现“路径未找到”的错误。 ```shell /plugin marketplace add https://example.com/marketplace.json ``` -------------------------------- ### 解决 /plugin 命令未识别的问题 Source: https://code.claude.com/docs/zh-CN/discover-plugins 当 `/plugin` 命令未被识别时,首先检查 Claude Code 的版本是否满足要求(1.0.33 或更高)。如果版本过低,需要更新 Claude Code。更新后,重启终端和 Claude Code。 ```shell claude --version ``` ```shell brew upgrade claude-code ``` ```shell npm update -g @anthropic-ai/claude-code ``` -------------------------------- ### Example Markdown Code Block with Language Tag Source: https://code.claude.com/docs/zh-CN/troubleshooting An example of a correctly formatted Markdown code block with a language tag ('javascript'), which ensures proper syntax highlighting and readability. ```markdown ```javascript function example() { return "hello"; } ``` ``` -------------------------------- ### Native Claude Code Installation Script (macOS, Linux, WSL) Source: https://code.claude.com/docs/zh-CN/troubleshooting Installs Claude Code directly using a curl script, bypassing npm and Node.js dependencies. This method is recommended for macOS, Linux, and WSL, and allows installation of stable, latest, or specific versions. ```bash # Install stable version (default) curl -fsSL https://claude.ai/install.sh | bash # Install latest version curl -fsSL https://claude.ai/install.sh | bash -s latest # Install specific version number curl -fsSL https://claude.ai/install.sh | bash -s 1.0.58 ``` -------------------------------- ### 管理插件市场 (CLI) Source: https://code.claude.com/docs/zh-CN/discover-plugins 使用 CLI 命令来列出、更新或删除插件市场。删除市场将同时卸载从中安装的所有插件。 ```shell /plugin marketplace list ``` ```shell /plugin marketplace update marketplace-name ``` ```shell /plugin marketplace remove marketplace-name ``` -------------------------------- ### 从本地路径添加插件市场 Source: https://code.claude.com/docs/zh-CN/discover-plugins 添加包含 `.claude-plugin/marketplace.json` 文件的本地目录或直接添加 `marketplace.json` 文件的路径来管理本地插件市场。 ```shell /plugin marketplace add ./my-marketplace ``` ```shell /plugin marketplace add ./path/to/marketplace.json ``` -------------------------------- ### Example Markdown Code Block without Language Tag Source: https://code.claude.com/docs/zh-CN/troubleshooting An example of a Markdown code block generated by Claude Code that is missing a language tag. This can lead to incorrect syntax highlighting in various tools. ```markdown ``` function example() { return "hello"; } ``` ``` -------------------------------- ### Install Test Plugin Source: https://code.claude.com/docs/zh-CN/plugin-marketplaces Install a specific plugin from a marketplace to test its functionality and ensure it integrates correctly with your Claude environment. Use this command after adding a marketplace or to verify an existing plugin. ```shell /plugin install test-plugin@marketplace-name ``` -------------------------------- ### Preload Skills into Subagents (YAML) Source: https://code.claude.com/docs/zh-CN/sub-agents Inject skill content into a subagent's context at startup using the `skills` field. This provides domain knowledge without requiring discovery during execution. Each skill's full content is injected, and subagents do not inherit skills from the parent conversation. ```yaml --- name: api-developer description: Implement API endpoints following team conventions skills: - api-conventions - error-handling-patterns --- Implement API endpoints. Follow the conventions and patterns from the preloaded skills. ``` -------------------------------- ### Fix WSL npm OS Detection for Claude Code Installation Source: https://code.claude.com/docs/zh-CN/troubleshooting Addresses issues where WSL might be using the Windows npm during Claude Code installation. It suggests setting the OS configuration before installation and using a force flag to bypass OS checks. This is specific to Windows Subsystem for Linux environments. ```bash npm config set os linux npm install -g @anthropic-ai/claude-code --force --no-os-check ``` -------------------------------- ### 安装插件 Source: https://code.claude.com/docs/zh-CN/discover-plugins 在添加市场后,可以使用此命令安装插件。默认安装到用户范围。可以通过交互式 UI 选择不同的安装范围(用户、项目、本地)。 ```shell /plugin install plugin-name@marketplace-name ``` -------------------------------- ### Instruct Claude to Use Subagents for Investigation Source: https://code.claude.com/docs/zh-CN/best-practices This example demonstrates how to instruct Claude to use subagents for investigating specific aspects of a codebase. It provides a clear directive to use subagents to understand the authentication system's token refresh mechanism and identify existing OAuth utilities. This approach helps keep the main conversation context clean by offloading research tasks to separate agents. ```text Use subagents to investigate how our authentication system handles token refresh, and whether we have any existing OAuth utilities I should reuse. ``` -------------------------------- ### 解决插件缓存问题 Source: https://code.claude.com/docs/zh-CN/discover-plugins 如果插件技能在安装后未出现,可以尝试清除插件缓存并重启 Claude Code。这有助于解决因缓存问题导致的插件未正确加载的情况。 ```shell rm -rf ~/.claude/plugins/cache ``` -------------------------------- ### Reset Claude Code Authentication Source: https://code.claude.com/docs/zh-CN/troubleshooting Removes stored authentication tokens for Claude Code and forces a re-authentication process. This is useful for resolving persistent authentication issues by starting with a clean login state. ```bash rm -rf ~/.config/claude-code/auth.json claude ``` -------------------------------- ### Run Initialization Hooks Only in Claude CLI Source: https://code.claude.com/docs/zh-CN/cli-reference Executes initialization hooks and then exits without starting an interactive session. This is useful for setup tasks or batch processing where user interaction is not needed. It does not require any arguments. ```bash claude --init-only ``` -------------------------------- ### 配置自动更新 (环境变量) Source: https://code.claude.com/docs/zh-CN/discover-plugins 通过设置环境变量来控制 Claude Code 和插件的自动更新行为。`DISABLE_AUTOUPDATER` 可完全禁用自动更新,而 `FORCE_AUTOUPDATE_PLUGINS` 可在禁用 Claude Code 更新的同时保持插件自动更新。 ```shell export DISABLE_AUTOUPDATER=true export FORCE_AUTOUPDATE_PLUGINS=true ``` -------------------------------- ### Add Claude Code to Windows User PATH Environment Variable Source: https://code.claude.com/docs/zh-CN/troubleshooting Manually adds the Claude Code installation directory to the user's PATH environment variable on Windows. This ensures the 'claude' command can be found and executed from any terminal after a restart. ```text %USERPROFILE%\.local\bin ```