






















This is a guide that lists many of the Claude Code existing capabilities.
# Install Claude Code globally
npm install -g @anthropic-ai/claude-code
# Verify installation
claude --version
# Start your first session
claude
Claude Code will prompt you to authenticate with your Anthropic account on first use. Follow the browser-based authentication flow to complete setup.
# Start new interactive conversation
claude
# Start new conversation with initial prompt
claude "help me set up a Kubernetes deployment"
# Direct query mode - execute once and exit
claude -p "analyze the database schema in this project"
# Continue previous conversation
claude -c
# Resume specific session by ID (see session management section for how to find IDs)
claude -r session-id-here
# Process stdin content
cat application.log | claude -p "identify error patterns"
While in an interactive session, these commands control your workflow:
# Session management
/clear # Reset conversation history
/exit # End current session
/help # Display available commands
# Configuration and status
/config # Open configuration interface
/status # Show account and system information
/doctor # Diagnose installation issues
/cost # Display token usage statistics
# Project initialization
/init # Generate CLAUDE.md project guide
/memory # Edit project memory files
# Account management
/login # Switch Anthropic accounts
/logout # Sign out current account
The following shows how to resume and continue working on previous sessions.
# Interactive session selection
claude --resume
# Resume specific session
claude --resume 550e8400-e29b-41d4-a716-446655440000
# Continue most recent session
claude --continue
# Resume in print mode (non-interactive)
claude -p --resume session-id "add error handling to the API"
# Continue in print mode
claude -p --continue "now add unit tests"
When you run claude --resume without a session ID, Claude Code will display an interactive list of your recent sessions, showing:
# Model selection
claude --model sonnet # Use latest Sonnet
claude --model opus # Use latest Opus
claude --model claude-sonnet-4-20250514 # Specific version
# Directory access
claude --add-dir ../frontend --add-dir ../backend
# Output formatting
claude -p "generate API documentation" --output-format json
claude -p "analyze performance" --output-format stream-json
# Session control
claude --continue "add unit tests for the new functions"
claude --resume session-id "implement the database changes" # Use claude --resume to see available IDs
claude --max-turns 5 "focused code review"
The --max-turns flag helps control API costs by limiting conversation length.
With the following copmmands we are controlling what Claude Code is allowed and not allowed to do.
# Allow specific tools without prompting
claude --allowedTools "Bash(git log:*)" "Bash(git status:*)" "Write"
# Block dangerous operations
claude --disallowedTools "Bash(rm:*)" "Bash(sudo:*)" "Bash(chmod:*)"
# Skip all permission prompts (use with caution)
claude --dangerously-skip-permissions
# List configured servers
claude mcp list
# Interactive server setup
claude mcp add
# Add Puppeteer
claude mcp add puppeteer -s user -- npx -y @modelcontextprotocol/server-puppeteer
# Add filesystem server
claude mcp add filesystem -- npx @modelcontextprotocol/server-filesystem /path/to/project
# Add HTTP-based server
claude mcp add --transport http api-server https://api.example.com/mcp
# Add server with authentication
claude mcp add secure-api -e Authorization="Bearer token123" -- server-command
# Import from Claude Desktop configuration
claude mcp add-from-claude-desktop
# Debug MCP connection issues
claude --mcp-debug
If you prefer direct config file editing (as per your DevOps preference), create or edit your .claude.json file:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp@latest"]
}
}
}
Once you have MCP servers configured, Claude Code automatically discovers their available tools and makes them accessible through slash commands. This allows you to extend Claude's capabilities with external services and APIs.
# Filesystem server - access local files and directories
claude mcp add filesystem -- npx @modelcontextprotocol/server-filesystem /path/to/project
# GitHub server - interact with GitHub repositories
claude mcp add github -- npx @modelcontextprotocol/server-github
# SQLite server - database operations
claude mcp add sqlite -- npx @modelcontextprotocol/server-sqlite
# Instead of /mcp__sqlite__list_tables
claude "List all tables in the database"
claude "Show me what tables exist in this database"
claude "What tables are available?"
# Puppeteer server - web automation and testing
claude mcp add puppeteer -s user -- npx -y @modelcontextprotocol/server-puppeteer
# AWS Serverless MCP - AWS Lambda and serverless operations
# Add via npm package (if available)
claude mcp add aws-serverless -- npx awslabs-aws-serverless-mcp
# Or add via local installation
claude mcp add aws-serverless -- /path/to/aws-serverless-mcp/server
# May require AWS credentials and additional setup
export AWS_ACCESS_KEY_ID=your-key
export AWS_SECRET_ACCESS_KEY=your-secret
# Context7 - documentation and context management
claude mcp add context7 -- npx -y @upstash/context7-mcp@latest
Link to an article about AWS MCP servers - click here
If you have configured an MCP server in your Claude Desktop, you can add those to Claude Code:
# Import pre-configured servers from Claude Desktop
claude mcp add-from-claude-desktop
# List all configured MCP servers
claude mcp list
# Start interactive session to see available slash commands
claude
> /
# This will show all available commands including MCP tools
The commands that you can execute for each MCP tool can be either based on the natural language or using the direct commands.
Assume you have git mcp server installed.
You could use the natural language to let Claude Code execute some operations, like:
claude "Show me GitHub issue #123"
claude "Query users table for anyone named John"
claude "Take a full-page screenshot of https://example.com"
claude "Read the Button.tsx component file"
We can also call the direct commands. Let's try by selecting the github server.
Select it by entering /mcp: and then select github MCP server:
/mcp
# Output:
※ Tip: Want Claude to remember something? Hit # to add preferences, tools, and instructions to Claude's memory
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Manage MCP servers │
│ │
│ 1. awslabs.aws-serverless-mcp ✔ connected · Enter to view details │
│ 2. context7 ✔ connected · Enter to view details │
│ 3. filesystem ✘ failed · Enter to view details │
│ ❯ 4. github ✔ connected · Enter to view details │
│ ↓ 5. puppeteer ✔ connected · Enter to view details │
│ │
│ ※ Tip: Run claude --debug to see logs inline, or view log files in │
│ /Users/alma/Library/Caches/claude-cli-nodejs/-Users-alma-dev-projects-temp-my-blog-quizes-my-blog
After we have selected github we can see that there are 26 tools available.
Select View tools:
※ Tip: Want Claude to remember something? Hit # to add preferences, tools, and instructions to Claude's memory
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Github MCP Server │
│ │
│ Status: ✔ connected │
│ Command: npx │
│ Args: @modelcontextprotocol/server-github │
│ Capabilities: tools │
│ Tools: 26 tools │
│ │
│ ❯ 1. View tools │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Esc to go back
# Output View tools:
│ Tools for github (26 tools) │
│ │
│ ↑ 5. push_files │
│ 6. create_issue │
│ 7. create_pull_request │
│ ❯ 8. fork_repository │
│ ↓ 9. create_branch
If we select fork_repository, we get some information about this particular tool:
│ fork_repository (github) │
│ │
│ Tool name: fork_repository │
│ Full name: mcp__github__fork_repository │
│ │
│ Description: │
│ Fork a GitHub repository to your account or specified organization │
│ │
│ Parameters: │
│ • owner (required): string - Repository owner (username or organization) │
│ • repo (required): string - Repository name │
│ • organization: string - Optional: organization to fork to (defaults to your account)
Wit this information, we can call these tools directly. Here are some examples:
# Example GitHub operations:
/mcp__github__create_issue "Bug report" "Description of the issue"
/mcp__github__list_issues
/mcp__github__get_pull_request 123
/mcp__github__fork_repository [owner] [repo] [organization]
Example:
/mcp__github__fork_repository "prometheus-community" "helm-charts"
This will fork the prometheus-community/helm-charts repository
MCP tools require explicit permission through the --allowedTools flag:
# Allow specific MCP tools
claude --allowedTools "mcp__filesystem__read_file,mcp__github__list_issues"
# Allow all tools from a specific server
claude --allowedTools "mcp__filesystem__*"
# Use in configuration
claude config set allowedTools "mcp__filesystem__*,mcp__github__get_issue"
# Debug MCP connections
claude --mcp-debug
# Check server status
claude mcp list
# Test specific server
claude mcp get github
# Common issues:
# - Server not responding: Check if the server process is running
# - Tool not found: Verify the exact tool name with / command
# - Permission denied: Add tool to allowedTools configuration
Here are some examples how you could create your own custom commands for Claude Code to use.
Be aware, we can either create a project-specific commands or user profile commands. This is controlled by choosing where to store the configuration, either under the user profile or directly in the projects.
In this example, we're creating a project-specific commands.
# The following creates the .claude/commands/ directory where Claude Code looks for custom project commands.
mkdir -p .claude/commands
# Define a code review command
cat > .claude/commands/review.md << 'EOF'
Perform a code review focusing on:
- Security vulnerabilities
- Performance bottlenecks
- Code maintainability
- Test coverage gaps
EOF
# Use the command
/project:review
Here, we're creating a command under the user profile:
# Create personal commands directory
mkdir -p ~/.claude/commands
# Define a debugging command
cat > ~/.claude/commands/debug.md << 'EOF'
Analyze the provided code or logs for debugging:
1. Identify potential root causes
2. Suggest debugging steps
3. Recommend monitoring improvements
EOF
# Use across all projects
/user:debug
Custom commands can accept arguments using the `$ARGUMENTS` placeholder.
This makes them much more flexible and reusable. For example, a `write_tests.md` command might contain:
Write comprehensive tests for: $ARGUMENTS
Testing conventions:
* Use pytest with Flask's test client
* Place test files in a tests/ directory at the project root, mirroring your app structure
* Name test files as test_[filename].py
* Use conftest.py for shared fixtures and test configuration
Coverage:
* Test happy paths
* Test edge cases
* Test error states
* Test authentication/authorization where applicable
* Test database operations (if applicable)
You can then run this command with a file path:
/write_tests the auth.py file in the routes directory
The arguments don't have to be file paths - they can be any string you want to pass to give Claude context and direction for the task:
/write_tests the /api/deployments endpoint - focus on error handling and validation
/write_tests the EKS cluster creation logic in eks_manager.py
Claude Code configuration allows you to set defaults and security policies that apply automatically to your sessions, reducing the need to specify the same flags repeatedly.
# View all current settings for this project
claude config list
# View global settings
claude config list --global
Set your preferred AI model to avoid specifying it each time:
# Set default model for current project
claude config set model claude-sonnet-4-20250514
# Set default model globally (all projects)
claude config set --global model sonnet
# Why this matters: Without this, you'd need to use --model flag every time:
# claude --model sonnet "analyze this code"
# With config set, you can just use: claude "analyze this code"
Configure which tools Claude can use without prompting you each time:
# Allow safe development tools without prompting
claude config set allowedTools "Bash(git:*),Write,Read"
# Block dangerous operations entirely
claude config add disallowedTools "Bash(rm:*)" "Bash(sudo:*)"
# Why this matters: Without configuration, Claude will prompt you for permission
# every time it wants to run git commands or write files. With allowedTools set,
# it can perform these common operations automatically.
Without configuration, Claude will prompt you for permission. Every time it wants to run git commands or write files. With allowedTools set, it can perform these common operations automatically.
Add or remove tools from your configuration:
# Add multiple dangerous tools to block list
claude config add disallowedTools "Bash(rm:*)" "Bash(sudo:*)" "Bash(chmod:*)"
# Remove a previously allowed tool
claude config remove allowedTools "Bash(git:*)"
# Clear entire tool list
claude config set allowedTools ""
claude config add disallowedTools "Bash(rm:*)" "Bash(sudo:*)" "Bash(chmod:*)" # Remove a previously allowed tool claude config remove allowedTools "Bash(git:*)" # Clear entire tool list claude config set allowedTools ""
# Safe development setup for a React project
claude config set model sonnet
claude config set allowedTools "Bash(git:*),Bash(npm:*),Bash(yarn:*),Write,Read"
claude config set disallowedTools "Bash(rm:*),Bash(sudo:*)"
# Secure production environment setup
claude config set --global disallowedTools "Bash(rm:*),Bash(sudo:*),Bash(chmod:*),Bash(mv:*)"
claude config set --global allowedTools "Bash(git status:*),Bash(git log:*),Read"
Once configured, you can run claude "help me debug this error" instead of claude --model sonnet --allowedTools "Bash(git:*),Write,Read" --disallowedTools "Bash(rm:*)" "help me debug this error"
Claude Code maintains project context through CLAUDE.md files - these act as persistent memory that carries over between sessions. This allows Claude to remember important project details, architecture decisions, and coding standards.
# Start an interactive session
claude
# During conversation, add information to memory by starting a message with #
> # This project uses PostgreSQL with Docker
> # Our API follows REST conventions
> # All database migrations must be backward compatible
> # We use Jest for testing with 80% coverage requirement
# These lines automatically get added to CLAUDE.md
# Claude will remember this information in future sessions
Without this feature, you'd need to:
With the # shortcut, you can add important context immediately as you discover it during development.
# Generate initial CLAUDE.md for your project
claude /init
# Edit memory files directly
claude /memory
# Manual creation (if needed)
cat > CLAUDE.md << 'EOF'
# Project: E-commerce API
## Architecture
- Node.js with Express framework
- PostgreSQL database with Prisma ORM
- Redis for caching
- Docker for containerization
## Coding Standards
- Use TypeScript for all new code
- Follow Airbnb ESLint configuration
- Write unit tests for all business logic
- API responses must include proper HTTP status codes
## Important Notes
- Database connections use connection pooling
- All API endpoints require authentication except /health
- Rate limiting: 100 requests per minute per IP
EOF
You can reference other documentation files within CLAUDE.md:
## Project Documentation
@docs/architecture.md
@README.md
@docs/deployment-guide.md
## API Documentation
@openapi.yml
@docs/api-endpoints.md
When Claude reads CLAUDE.md, it automatically imports the content of these referenced files, giving it access to your existing documentation without duplication.
# Start working on a new feature
claude "help me implement user authentication"
# During development, add discovered information to memory
> # Authentication uses JWT tokens with 24-hour expiration
> # Password hashing uses bcrypt with 12 rounds
> # User sessions are stored in Redis with 'session:' prefix
> # Failed login attempts are rate-limited after 5 attempts
# Later, in a new session:
claude "help me add password reset functionality"
# Claude automatically knows about your authentication system
# from the previous session's memory additions
This memory system ensures Claude maintains context about your project's specific requirements, architecture decisions, and coding standards across all interactions.
# Secure production setup
claude --disallowedTools "Bash(rm:*)" "Bash(sudo:*)" "Bash(chmod:*)" \
--allowedTools "Bash(git:*)" "Read" "Write" \
--verbose
# Enable debug logging for audit trails
export ANTHROPIC_LOG=debug
# Corporate proxy configuration
export HTTPS_PROXY='https://proxy.company.com:8080'
# Shared MCP configuration
claude --mcp-config team-servers.json
# Team-wide custom commands
# Store in .claude/commands/ and commit to version control
# Standardized project setup
claude /init # Creates CLAUDE.md
# Installation
pip install claude-code-sdk
# Basic usage example
from claude_code_sdk import ClaudeCode
client = ClaudeCode()
response = client.chat("refactor this database query for better performance")
# Installation
npm install @anthropic-ai/claude-code
# Usage
import { ClaudeCode } from '@anthropic-ai/claude-code';
const client = new ClaudeCode();
const response = await client.chat("optimize this React component");
# Automated code review script
#!/bin/bash
review_changes() {
local branch=${1:-main}
git diff $branch | claude -p "review these changes for security issues" --output-format json
}
# CI/CD integration
claude -p "analyze test failures" --max-turns 3 < test-output.log
# Batch processing
find . -name "*.py" -type f | while read file; do
claude -p "add type hints to this Python file" < "$file" > "${file}.typed"
done
# Automated commit analysis
git log --oneline -10 | claude -p "generate release notes from these commits"
# PR review automation
git diff main..feature-branch | claude -p "review this pull request for code quality"
# Conflict resolution assistance
git diff --name-only --diff-filter=U | xargs claude -p "help resolve merge conflicts in these files"
Here is an example from my own project:
git log --oneline -n 10 | claude -p "create release notes from commits"
# Release Notes
## Latest Changes
### Features
- **Documentation**: Added project documentation
- **TinyMCE Update**: Updated TinyMCE node module to latest version
- **Pagination Enhancement**: Increased pagination limit from 20 to 200 in promoted posts function
- **Promoted Posts**: Updated promoted posts behavior and pagination in admin and home routes
- **Post Display**: Increased limit of promoted posts from 6 to 10 in home route
### Bug Fixes
- **Post Ordering**: Fixed order of promoted posts to ascending in home route
- **Post Limits**: Updated order and limit of promoted posts in home function
- **Debug Cleanup**: Removed debug print statement and added local storage for posts table length
### Code Quality
- **Formatting**: Cleaned up code formatting and improved logging in admin routes and newsletter functions
- **Template Structure**: Updated card structure in home.html for better readability and styling
---
## Commit Details
- `54faf9b` feat: add documentation
- `4a334a2` refactor: Clean up code formatting and improve logging in admin routes and newsletter functions
- `934b954` feat: update tinymce node module
- `2de0ca6` feat: increase pagination limit from 20 to 200 in promoted_posts function
- `4038241` feat: update promoted posts behavior and pagination in admin and home routes
- `a12c60a` fix: update order and limit of promoted posts in home function
- `8777a1d` fix: change order of promoted posts to ascending in home route
- `9dd55ad` refactor: update card structure in home.html for better readability and styling
- `e2ac548` fix: remove debug print statement and add local storage for posts table length
- `d6bfc21` feat: increase limit of promoted posts from 6 to 10 in home route
# Test failure analysis
pytest --tb=short 2>&1 | claude -p "explain test failures and suggest fixes"
# Code quality assessment
eslint . --format=json | claude -p "prioritize these linting issues" --output-format json
# Documentation generation
claude -p "generate API documentation from this codebase" --output-format json > api-docs.json
# Log analysis
tail -f /var/log/application.log | claude -p "monitor for error patterns and alert on anomalies"
# Performance monitoring
claude -p "analyze these performance metrics and suggest optimizations" < metrics.json
# Installation problems
claude /doctor # Health check
npm list -g @anthropic-ai/claude-code # Verify installation
# Permission issues
claude /permissions # Review current permissions
claude config set allowedTools "" # Reset tool permissions
# MCP server problems
claude mcp list # Check server status
claude --mcp-debug # Debug MCP connections
# Clear conversation context
/clear
# Compact long conversations
/compact "preserve only the current task context"
# Limit processing scope
claude --max-turns 3 -p "focused analysis task"
# Stream processing for large outputs
claude -p "comprehensive project analysis" --output-format stream-json
# Enable verbose logging
claude --verbose
# Debug specific components
claude --mcp-debug
# Check system status
claude /status
# Review session costs
claude /cost
--dangerously-skip-permissions in production environments--disallowedTools for destructive operations--verbose logging for audit trails/permissions/clear between unrelated tasks to reset context/compact for long conversations to maintain focus--max-turns for focused queries.claude/commands/ for team sharing| Flag | Purpose | Example |
|---|---|---|
-p, --print |
Non-interactive mode | claude -p "analyze code" |
--model |
Select AI model | --model sonnet |
--continue |
Continue recent session | claude --continue |
--resume |
Resume specific session | --resume session-id |
--add-dir |
Add working directories | --add-dir ../src |
--allowedTools |
Permit tools without prompts | --allowedTools "Bash(git:*)" |
--disallowedTools |
Block specific tools | --disallowedTools "Bash(rm:*)" |
--output-format |
Set output format | --output-format json |
--max-turns |
Limit conversation turns | --max-turns 5 |
--verbose |
Enable detailed logging | --verbose |
| Model Alias | Full Model Name | Use Case |
|---|---|---|
sonnet |
Latest Sonnet | General development tasks |
opus |
Latest Opus | Complex problem solving |
claude-sonnet-4-20250514 |
Specific version | Production consistency |
List of the models: https://docs.anthropic.com/en/docs/about-claude/models/overview
| Format | Purpose | Use Case |
|---|---|---|
text |
Plain text response | Human-readable output |
json |
Structured data | Automation and parsing |
stream-json |
Real-time streaming | Long-running tasks |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。