SuperAPI AI Directory

claude-code-guide

Coding & development

View repository

Updated 10-15 10:24

About this skill

Claude Code Advanced Development Guide

A comprehensive Chinese learning guide for Claude Code, covering all core concepts from basic to advanced, tool usage, development workflows, and best practices.

When to Use This Skill

Use this skill when you need help with the following:

  • Learning Claude Code's core features and tools
  • Mastering advanced usage of the REPL environment
  • Understanding development workflows and task management
  • Using MCP to integrate external systems
  • Implementing advanced development patterns
  • Applying Claude Code best practices
  • Solving common problems and errors
  • Performing large file analysis and processing

Quick Reference

Claude Code Core Tools (7)

  1. REPL - JavaScript runtime environment

    • Full ES6+ support
    • Preloaded libraries: D3.js, MathJS, Lodash, Papaparse, SheetJS
    • Supports async/await, BigInt, WebAssembly
    • File reading:window.fs.readFile()
  2. Artifacts - Visual output

    • React, Three.js, charting libraries
    • HTML/SVG rendering
    • Interactive components
  3. Web Search - Web search

    • Available only in the United States
    • Domain filtering support
  4. Web Fetch - Fetch web content

    • HTML to Markdown
    • Content extraction and analysis
  5. Conversation Search - Conversation search

    • Search historical conversations
    • Context retrieval
  6. Recent Chats - Recent conversations

    • Access recent sessions
    • Conversation history
  7. End Conversation - End conversation

    • Cleanup and summary
    • Session management

Large File Analysis Workflow

# 阶段 1:定量评估
wc -l filename.md    # 行数统计
wc -w filename.md    # 词数统计
wc -c filename.md    # 字符数统计

# 阶段 2:结构分析
grep "^#{1,6} " filename.md  # 提取标题层次
grep "```" filename.md       # 识别代码块
grep -c "keyword" filename.md # 关键词频率

# 阶段 3:内容提取
Read filename.md offset=0 limit=50      # 文件开头
Read filename.md offset=N limit=100     # 目标部分
Read filename.md offset=-50 limit=50    # 文件结尾

Advanced REPL Usage

// 数据处理
const data = [1, 2, 3, 4, 5];
const sum = data.reduce((a, b) => a + b, 0);

// 使用预加载库
// Lodash
_.chunk([1, 2, 3, 4], 2);  // [[1,2], [3,4]]

// MathJS
math.sqrt(16);  // 4

// D3.js
d3.range(10);  // [0,1,2,3,4,5,6,7,8,9]

// 读取文件
const content = await window.fs.readFile('path/to/file');

// 异步操作
const result = await fetch('https://api.example.com/data');
const json = await result.json();

Slash Command System

Built-in commands:

  • /help - Show help
  • /clear - Clear conversation
  • /plugin - Manage plugins
  • /settings - Configuration settings

Custom commands: Create .claude/commands/mycommand.md:

根据需求执行特定任务的指令

Usage:/mycommand

Development Workflow Patterns

1. File Analysis Workflow

# 探索 → 理解 → 实现
ls -la                  # 列出文件
Read file.py            # 读取内容
grep "function" file.py # 搜索模式
# 然后实现修改

2. Algorithm Validation Workflow

# 设计 → 验证 → 实现
# 1. 在 REPL 中测试逻辑
# 2. 验证边界情况
# 3. 实现到代码

3. Data Exploration Workflow

# 检查 → 分析 → 可视化
# 1. 读取数据文件
# 2. REPL 中分析
# 3. Artifacts 可视化

Core Concepts

Tool Permission System

Tools with automatically granted permissions:

  • REPL
  • Artifacts
  • Web Search/Fetch
  • Conversation Search

Tools requiring authorization:

  • Bash (read/write file system)
  • Edit (modify files)
  • Write (create files)

Project Context

Claude automatically recognizes:

  • Git repository status
  • Programming language (from file extensions)
  • Project structure
  • Dependency configuration

Memory System

Conversation memory:

  • Stored in the current session
  • 200K token window
  • Automatic context management

Persistent memory (experimental):

  • Saved across sessions
  • User preference memory
  • Project context retention

MCP Integration

What is MCP?

Model Context Protocol - A protocol that connects Claude to external systems.

MCP Server Configuration

Configuration file:~/.config/claude/mcp_config.json

{
  "mcpServers": {
    "my-server": {
      "command": "node",
      "args": ["path/to/server.js"],
      "env": {
        "API_KEY": "your-key"
      }
    }
  }
}

Using MCP Tools

Claude automatically discovers MCP tools and uses them in conversations:

"使用 my-server 工具获取数据"

Hook System

Hook Types

In .claude/settings.json configuration:

{
  "hooks": {
    "tool-pre-use": "echo 'About to use tool'",
    "tool-post-use": "echo 'Tool used'",
    "user-prompt-submit": "echo 'Processing prompt'"
  }
}

Common Hook Uses

  • Auto-format code
  • Run tests
  • Git commit checks
  • Logging
  • Send notifications

Advanced Patterns

Multi-Agent Collaboration

Use the Task tool to launch a sub-agent:

"启动一个专门的代理来优化这个算法"

Sub-agent characteristics:

  • Independent context
  • Focus on a single task
  • Return results to the main agent

Intelligent Task Management

Use the TodoWrite tool:

"创建任务列表来跟踪这个项目"

Task status:

  • pending - Pending
  • in_progress - In progress
  • completed - Completed

Code Generation Patterns

Progressive development:

  1. Generate the basic structure
  2. Add core functionality
  3. Implement details
  4. Test and optimize

Validation-driven:

  1. Write test cases
  2. Implement functionality
  3. Run tests
  4. Fix issues

Quality Assurance

Automated testing

# 运行测试
npm test
pytest

# 类型检查
mypy script.py
tsc --noEmit

# 代码检查
eslint src/
flake8 .

Code Review Patterns

Use a sub-agent for review:

"启动代码审查代理检查这个文件"

Review focus:

  • Code quality
  • Security issues
  • Performance optimization
  • Best practices

Error Recovery

Common error patterns

  1. Tool usage errors

    • Check permissions
    • Validate syntax
    • Confirm paths
  2. File operation errors

    • Confirm the file exists
    • Check read/write permissions
    • Validate that paths are correct
  3. API call errors

    • Check network connectivity
    • Validate the API key
    • Confirm the request format

Progressive Fix Strategy

  1. Isolate the problem
  2. Minimize reproduction
  3. Fix step by step
  4. Validate the solution

Best Practices

Development Principles

  1. Clarity first - Clarify requirements and goals
  2. Progressive implementation - Develop step by step
  3. Continuous validation - Test frequently
  4. Appropriate abstraction - Reasonable modularization

Tool Usage Principles

  1. The right tool - Choose the appropriate tool
  2. Tool combination - Coordination of multiple tools
  3. Least privilege - Request only necessary permissions
  4. Error handling - Handle failures gracefully

Performance Optimization

  1. Batch operations - Combine multiple operations
  2. Incremental processing - Process large files
  3. Cache results - Avoid redundant computation
  4. Async first - Use async/await

Security Considerations

Sandbox Model

Each tool runs in an isolated environment:

  • REPL: no file system access
  • Bash: requires explicit authorization
  • Web: only specific domains

Security Best Practices

  1. Least privilege - Grant only the necessary permissions
  2. Code review - Check generated code
  3. Sensitive data - Do not share keys
  4. Regular audits - Check hooks and configuration

Troubleshooting

Tool unavailable

Symptom: Tool call fails

Solution:

  • Check permission settings
  • Verify syntax is correct
  • Confirm file paths
  • Check error messages

REPL performance issues

Symptom: REPL executes slowly

Solution:

  • Reduce data volume
  • Use streaming
  • Optimize algorithms
  • Process in batches

MCP connection failure

Symptom: MCP server not responding

Solution:

  • Check the configuration file
  • Verify the server is running
  • Confirm environment variables
  • Check server logs

Practical Examples

Example 1: Data analysis

// 在 REPL 中
const data = await window.fs.readFile('data.csv');
const parsed = Papa.parse(data, { header: true });
const values = parsed.data.map(row => parseFloat(row.value));
const avg = _.mean(values);
const std = math.std(values);
console.log(`平均值: ${avg}, 标准差: ${std}`);

Example 2: File search

# 在 Bash 中
grep -r "TODO" src/
find . -name "*.py" -type f

Example 3: Web data retrieval

"使用 web_fetch 获取 https://api.example.com/data 的内容,
然后在 REPL 中分析 JSON 数据"

Reference Files

This skill includes detailed documentation:

  • README.md (9,594 lines) - A complete advanced guide to Claude Code

Includes the following topics:

  • In-depth analysis of core tools
  • Advanced REPL collaboration patterns
  • Detailed development workflows
  • Complete MCP integration guide
  • Hook system configuration
  • Advanced patterns and best practices
  • Troubleshooting and security considerations

Use the view command to view the reference file for detailed information.

Resources

Notes

This guide combines:

  • Official features and announcements
  • Patterns observed in actual use
  • Conceptual approaches and best practices
  • Third-party tool integrations

Please refer to the latest official documentation when using this.


Use this skill to gain an in-depth mastery of Claude Code's powerful features!