claude-cli

📁 xjthy001/skills 📅 1 day ago
0
总安装量
1
周安装量
安装命令
npx skills add https://github.com/xjthy001/skills --skill claude-cli

Agent 安装分布

amp 1
openclaw 1
opencode 1
cursor 1
codex 1

Skill 文档

Claude Code CLI

Quick Reference

Core Commands

claude                        # Start interactive REPL
claude "query"                # Start REPL with initial prompt
claude -p "query"             # Non-interactive (headless/SDK) mode
cat file | claude -p "query"  # Pipe content for processing
claude -c                     # Continue most recent conversation
claude -c -p "query"          # Continue via SDK
claude -r "session" "query"   # Resume specific session by ID or name
claude update                 # Update to latest version
claude mcp                    # Configure MCP servers

Essential Flags

Flag Purpose
-p, --print Non-interactive mode (headless/SDK)
-c, --continue Continue most recent conversation
-r, --resume Resume session by ID or name
--model Set model (sonnet, opus, or full name)
--permission-mode Set mode: default, plan, acceptEdits, bypassPermissions
--allowedTools Auto-approve specific tools
--disallowedTools Block specific tools
--tools Restrict available tools
--append-system-prompt Add to default system prompt
--system-prompt Replace entire system prompt
--output-format Output: text, json, stream-json
--json-schema Structured output matching schema (with -p)
--max-turns Limit agentic turns (with -p)
--max-budget-usd Spending limit (with -p)
--add-dir Add working directories
--mcp-config Load MCP servers from JSON
--agents Define subagents via JSON
--agent Use specific agent for session
--chrome Enable Chrome browser integration
--name Name session for later resume
--from-pr Start session linked to a PR
--verbose Verbose logging
--debug Debug mode with category filtering

Workflows

1. Explore-Plan-Implement

# Phase 1: Explore (Plan Mode)
claude --permission-mode plan
> read /src/auth and explain the session flow

# Phase 2: Plan
> create a plan to add OAuth2 support
# Press Ctrl+G to edit plan in text editor

# Phase 3: Implement (Normal Mode, Shift+Tab to switch)
> implement the OAuth flow from your plan, write tests, run them

# Phase 4: Commit
> commit with a descriptive message and open a PR

2. Headless/SDK Mode

# Simple query
claude -p "What does the auth module do?"

# Structured JSON output
claude -p "Summarize this project" --output-format json

# Schema-validated output
claude -p "Extract function names" --output-format json \
  --json-schema '{"type":"object","properties":{"functions":{"type":"array","items":{"type":"string"}}}}'

# Auto-approve tools
claude -p "Run tests and fix failures" --allowedTools "Bash,Read,Edit"

# Create commit
claude -p "Create a commit for staged changes" \
  --allowedTools "Bash(git diff *),Bash(git log *),Bash(git status *),Bash(git commit *)"

# Continue conversations
session_id=$(claude -p "Start review" --output-format json | jq -r '.session_id')
claude -p "Continue review" --resume "$session_id"

# Stream tokens
claude -p "Write a poem" --output-format stream-json --verbose --include-partial-messages

# Custom system prompt
gh pr diff "$1" | claude -p \
  --append-system-prompt "You are a security engineer. Review for vulnerabilities." \
  --output-format json

# Budget and turn limits
claude -p --max-budget-usd 5.00 --max-turns 10 "Refactor auth module"

3. Interactive Keyboard Shortcuts

Shortcut Action
Shift+Tab Cycle permission modes (Normal -> Auto-Accept -> Plan)
Ctrl+C Cancel current operation
Ctrl+G Open prompt in text editor
Ctrl+L Clear screen (keeps history)
Ctrl+R Reverse search history
Ctrl+B Background running tasks
Ctrl+T Toggle task list
Esc Esc Rewind/summarize to previous point
Alt+P Switch model
Alt+T Toggle extended thinking
\ + Enter Multiline input

Extension Points

Memory (CLAUDE.md)

Persistent instructions loaded every session. See references/memory.md.

Type Location Scope
User ~/.claude/CLAUDE.md All projects
Project ./CLAUDE.md or ./.claude/CLAUDE.md Team-shared
Local ./CLAUDE.local.md Personal, per-project
Rules ./.claude/rules/*.md Modular project rules
Auto memory ~/.claude/projects/<project>/memory/ Claude’s automatic notes

Subagents

Isolated workers with custom prompts, tools, and models. See references/subagents.md.

# Via /agents command (interactive)
/agents

# Via CLI flag
claude --agents '{
  "reviewer": {
    "description": "Code reviewer",
    "prompt": "Review for quality and security",
    "tools": ["Read", "Grep", "Glob", "Bash"],
    "model": "sonnet"
  }
}'

# Agent files: ~/.claude/agents/ (user) or .claude/agents/ (project)

Hooks

Deterministic shell commands on lifecycle events. See references/hooks.md.

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{"type": "command", "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"}]
    }],
    "Notification": [{
      "matcher": "",
      "hooks": [{"type": "command", "command": "notify-send 'Claude Code' 'Needs attention'"}]
    }]
  }
}

MCP Servers

Connect to external tools via Model Context Protocol. See references/mcp.md.

# Add remote server
claude mcp add server-name --transport http https://example.com/mcp

# Add stdio server
claude mcp add server-name -- npx -y @example/mcp-server

# Add with env vars
claude mcp add server-name --env API_KEY=xxx -- npx -y @example/server

# List/remove
claude mcp list
claude mcp remove server-name

Skills

Reusable knowledge and workflows. See references/skills.md.

# Skill locations
~/.claude/skills/<name>/SKILL.md     # Personal (all projects)
.claude/skills/<name>/SKILL.md       # Project (team-shared)

# Invoke directly
/skill-name

# Or Claude loads automatically based on description match

Settings & Permissions

Hierarchical configuration. See references/settings.md.

# Settings files (priority: managed > CLI > local > project > user)
~/.claude/settings.json                # User settings
.claude/settings.json                  # Project settings (git-tracked)
.claude/settings.local.json            # Local overrides (gitignored)

# Permission rules
"permissions": {
  "allow": ["Bash(npm run *)", "Read"],
  "deny": ["Bash(curl *)", "Read(./.env)"]
}

Detailed References

For in-depth documentation on specific topics: