# Claude Code Commands Reference

A reference for Claude Code CLI commands: authentication, scripting, MCP servers including the Docker MCP Gateway, and fixes for common problems.

- Author: Jatin Bansal (https://jatinbansal.com/)
- Published: 2025-07-10
- Canonical: https://jatinbansal.com/notes/claude-code-commands/
- Topic: Tools

---

A comprehensive guide to essential Claude Code CLI commands for efficient AI-powered development workflows, with special focus on Docker MCP Gateway integration.

## Docker MCP Gateway Management
I prefer to use MCP servers through the Docker MCP Gateway. It provides a unified way for managing MCP servers across different tools like Cursor, Claude, and other AI clients without manual configuration for each tool.

**Key Benefits:**
- Centralized MCP server management
- Container-based isolation and security
- Unified configuration across clients
- Built-in secret management
- Server catalog discovery

Learn more: **[Docker MCP Gateway: Open Source, Secure Infrastructure for Agentic AI ↗](https://www.docker.com/blog/docker-mcp-gateway-secure-infrastructure-for-agentic-ai/)**

### Docker MCP Gateway Configuration

#### Basic Gateway Configuration (Claude Desktop)
```json
{
  "globalShortcut": "Alt+Space",
  "mcpServers": {
    "DOCKER": {
      "command": "env",
      "args": [
        "PATH=/Applications/Docker.app/Contents/Resources/bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin",
        "/Applications/Docker.app/Contents/Resources/bin/docker",
        "mcp",
        "gateway",
        "run"
      ]
    }
  }
}
```

#### Advanced Gateway Configuration
```bash
# Run gateway with security features enabled
docker mcp gateway run \
  --verify-signatures \
  --log-calls \
  --block-secrets

# Run gateway with specific servers and transport
docker mcp gateway run \
  --transport=sse \
  --servers=wikipedia-mcp \
  --tools=get_article,get_summary,get_related_topics

# Servers I have currently enabled  
docker mcp server list
# context7, docker, duckduckgo, fetch, filesystem, sequentialthinking, time  
```

### Server Catalog Management
```bash
# View available MCP servers in catalog
docker mcp catalog show

# Enable specific servers
docker mcp server enable google-maps brave

# Disable servers
docker mcp server disable <server-name>
```

### Secret and Configuration Management
```bash
# Set API keys and secrets
docker mcp secret set 'brave.api_key=YOUR_API_KEY'
docker mcp secret set 'github.token=YOUR_GITHUB_TOKEN'

# View current configuration
docker mcp config read
```

### Gateway Security Features
- **Container Isolation**: Each MCP server runs in isolated Docker containers
- **Signature Verification**: Verify provenance of MCP container images
- **Secret Scanning**: Block secrets in inbound/outbound payloads
- **Network Restrictions**: Controlled network access for servers
- **Resource Limits**: CPU and memory constraints per server

## Traditional MCP Server Management

### List MCP Servers
```shell
claude mcp list
```
**Purpose**: Display all configured MCP (Model Context Protocol) servers and their status.

### Add MCP Servers from Claude Desktop
```shell
claude mcp add-from-claude-desktop -s user
```
**Purpose**: Import MCP server configurations from Claude Desktop application to Claude Code CLI.

### Remove MCP Server
```shell
claude mcp remove <server-name> -s user
```
**Purpose**: Remove an MCP server configuration.

### Add MCP Servers (Manual Configuration)
```bash
# Add stdio server
claude mcp add <server-name> <command> [args...]

# Add SSE server
claude mcp add --transport sse <server-name> <url>

# Add HTTP server
claude mcp add --transport http <server-name> <url>

# Add with specific scope
claude mcp add --scope user <server-name> <command>
claude mcp add --scope project <server-name> <command>
```

### Get Server Details
```bash
claude mcp get <server-name>
```
**Purpose**: Display detailed information about a specific MCP server configuration.

## Output Formats & Scripting

### JSON Output for Automation
```bash
# Get structured JSON response
claude -p "analyze this code" --output-format json

# Stream JSON for real-time processing
claude "process large dataset" --output-format stream-json

# Combine with jq for parsing
claude -p "list project dependencies" --output-format json | jq '.content'
```

### Scripting Examples
```bash
# Automated code review
claude -p "review changes in $(git diff --name-only)" > review.md
git diff | claude "review these changes" -p
```

## Configuration & Settings

### View Settings File
```shell
cat ~/.claude/settings.json
```
response:
```json
{
  "permissions": {
    "allow": [
      "mcp__DOCKER__get-library-docs",
      "mcp__DOCKER__resolve-library-id",
      "mcp__DOCKER__sequentialthinking",
      "mcp__DOCKER__fetch",
      "mcp__DOCKER__search",
      "WebFetch(domain:docs.anthropic.com)",
      "WebFetch(domain:*)",
      "Bash(npm run lint)",
      "mcp__DOCKER__fetch_content",
      "mcp__DOCKER__list_directory",
      "mcp__DOCKER__read_multiple_files",
      "mcp__DOCKER__read_file"
    ],
    "deny": []
  }
}
```
**Purpose**: Display current Claude Code configuration including MCP servers, shortcuts, and allowed tools. I use this configuration to auto allow of these tools

## Session Management

### Start Interactive Session
```shell
claude chat
```
**Purpose**: Begin a new interactive conversation with Claude.

### Resume Previous Session
```shell
claude --resume
# or
claude -c
```
**Purpose**: Continue from your last conversation session.

## Enhanced Development Workflow

### Model Selection & Performance
```shell
# Use specific model
claude --model claude-3-7-sonnet-latest
claude --model claude-3-5-sonnet-20241022
claude --model claude-3-5-haiku-20241022

# Model comparison workflow
claude --model claude-3-5-sonnet-20241022 "complex analysis task"
claude --model claude-3-5-haiku-20241022 "simple quick task"
```

### Advanced Command Execution
```shell
# Single command with print flag
claude "your prompt here" -p
claude "your prompt here" --print

# Continue conversation from command
claude -c "follow up question"

# Verbose execution for debugging
claude --debug "debug this issue"
```

### File and Directory Operations
```shell
# Add multiple directories to context
claude --add-dir /path/to/src --add-dir /path/to/tests

# Process file input
claude < analysis-prompt.txt

# Save formatted output
claude "generate report" -p --output-format json > report.json

# Pipe operations
git diff | claude "review these changes" -p
```

## Troubleshooting & Debug

### Get Help
```shell
claude --help
```
**Purpose**: Display available commands and options.

### Show Version
```shell
claude --version
```
**Purpose**: Display Claude Code version information.

### Debug Mode
```shell
claude --debug
```
**Purpose**: Run with detailed debugging information.

## Advanced MCP Server Management

### Project-Level Configuration
```bash
# Create project-specific MCP configuration
echo '{
  "mcpServers": {
    "project-tools": {
      "command": "npm",
      "args": ["run", "mcp-server"],
      "scope": "project"
    }
  }
}' > .mcp.json

# Use project configuration
claude --mcp-config .mcp.json chat
```

### Multi-Server Workflows
```bash
# Enable multiple complementary servers
claude mcp add filesystem-server file-tools
claude mcp add database-server db-tools  
claude mcp add api-server http-client
```

## Advanced Usage & Integrations

### Useful Alias
```bash
# Terminal integration
alias c='claude -p'
alias cr='claude --resume'
```

### Background Processing
```shell
# Run long tasks in background
claude "analyze large codebase" &
# output:- [1] pid
ps pid
```

### Performance Optimization
```bash
# Use faster model for simple tasks
claude --model claude-3-5-haiku-20241022 "quick syntax check"

# Cache frequently used prompts
echo "Review code for security vulnerabilities" > security-review.prompt
claude < security-review.prompt
```

### Debug MCP Issues
```shell
claude --debug mcp list
```

## Troubleshooting & Performance Tips

### Common Issues & Solutions

#### MCP Server Connection Problems
```bash
# Check server status
claude mcp list --debug
```

### Performance Optimization Tips
1. **Choose Right Model**: Use Haiku for simple tasks, Sonnet for complex analysis
2. **Cache Prompts**: Save frequently used prompts to files
3. **Batch Operations**: Group related tasks together
4. **Clean Sessions**: Regularly remove old conversation history

## Resources & References

### Official Documentation
- [Claude Code Documentation ↗](https://docs.anthropic.com/en/docs/claude-code)
- [MCP Specification ↗](https://modelcontextprotocol.io/specification)
- [Docker MCP Gateway ↗](https://www.docker.com/blog/docker-mcp-gateway-secure-infrastructure-for-agentic-ai/)

### Community Resources
- [MCP Server Registry ↗](https://github.com/modelcontextprotocol/servers)
- [Docker MCP Catalog ↗](https://hub.docker.com/mcp)
- [Claude Code GitHub ↗](https://github.com/anthropics/claude-code)

### Quick Command Reference
```bash
# Essential commands
claude --help                    # Get help
claude chat                      # Start interactive session
claude -p "query"               # One-time query
claude --resume                 # Resume last session

# MCP management
claude mcp list                 # List servers
claude mcp add <name> <cmd>     # Add server
claude mcp get <name>           # Server details
claude mcp remove <name>        # Remove server

# Docker Gateway
docker mcp gateway run          # Start gateway
docker mcp catalog show         # Browse catalog
docker mcp server enable <name> # Enable server
docker mcp secret set 'key=val' # Set secrets
```

This comprehensive reference covers Claude Code CLI usage with special focus on Docker MCP Gateway integration. For the latest features and updates, always refer to `claude --help` or the [official documentation ↗](https://docs.anthropic.com/en/docs/claude-code).
