Essential Claude Code Commands

Commands Covered 15+
Time to Master ~30 min
Skill Level Beginner

Claude Code is Anthropic's official CLI that brings Claude's powerful AI capabilities directly into your terminal. Whether you're debugging code, generating documentation, or building entire features, mastering the command set will dramatically boost your productivity.

This guide covers all essential commands, configuration options, and power-user tricks to help you get the most out of Claude Code.

Prerequisites: You'll need Claude Code installed and an API key configured. Check out the Getting Started Guide if you haven't set it up yet.

Basic Commands

These are the core commands you'll use daily. Each one is designed to be intuitive and powerful.

/help - Get Command Info

The most important command to learn. Use it anytime you're stuck or want to discover new features.

Bash
# Show all available commands
/help

# Get help on a specific command
/help compact

# Show keyboard shortcuts
/help shortcuts

/clear - Reset Context

Clears the conversation history and starts fresh. Useful when switching between unrelated tasks.

Bash
# Clear conversation
/clear

# Clear with confirmation
/clear --confirm
Warning: /clear permanently removes conversation history. Use /compact instead if you want to preserve important context while reducing token usage.

/compact - Optimize Context

The power-user's secret weapon. /compact intelligently compresses your conversation history, keeping essential information while drastically reducing token count.

Bash
# Basic compact
/compact

# Compact with specific instructions
/compact Keep architectural decisions, discard verbose test output

# Compact after tests
/compact Preserve test summary and failures

# Emergency compact
/compact Keep only: current task, active errors, recent decisions
⚡ When to Use /compact
After Tests Always
After Commits Recommended
Token Usage >70%
Task Switch Optional

/cost - Track API Usage

Monitor your Claude API costs in real-time. Essential for budget-conscious development.

Bash
# Show current session costs
/cost

# Show detailed breakdown
/cost --detailed

# Show monthly costs
/cost --month

Configuration

Settings

Claude Code can be configured through a JSON settings file or environment variables.

JSON
{
  "model": "claude-opus-4-5",
  "temperature": 0.7,
  "maxTokens": 4096,
  "systemPrompt": "You are a helpful coding assistant",
  "autoCompact": true,
  "compactThreshold": 0.8,
  "enableHooks": true,
  "mcpServers": ["filesystem", "github"]
}

CLAUDE.md - Project Instructions

The CLAUDE.md file is your project's instruction manual for Claude. Place it in your project root to provide context about architecture, conventions, and workflows.

Markdown
# My Project

## Architecture
- Frontend: React + TypeScript
- Backend: Node.js + Express
- Database: PostgreSQL

## Conventions
- Use functional components
- Follow ESLint rules strictly
- Write tests for all features

## Important Files
- `/src/components` - Reusable UI components
- `/src/api` - API client functions
- `/tests` - Jest test suites
Pro Tip: Claude automatically reads and follows instructions in CLAUDE.md. This is the best way to ensure consistency across sessions without repeating yourself.

Hooks

Hooks are scripts that run at specific points in Claude's workflow. They're perfect for automation, backup, and custom workflows.

Bash
#!/bin/bash
# .claude/hooks/pre_tool_use.sh

# Backup files before editing
if [[ "$TOOL_NAME" == "Edit" ]] || [[ "$TOOL_NAME" == "Write" ]]; then
    FILE_PATH="$TOOL_PARAM_file_path"
    BACKUP_DIR=".claude/backups"

    mkdir -p "$BACKUP_DIR"
    cp "$FILE_PATH" "$BACKUP_DIR/$(basename $FILE_PATH).backup"
    echo "Backed up: $FILE_PATH"
fi

Available Hooks:

  • pre_tool_use - Before any tool is executed
  • post_tool_use - After tool execution completes
  • pre_compact - Before context compacting
  • post_compact - After compacting finishes
  • session_start - When session begins
  • session_end - When session ends

MCP Servers

Model Context Protocol (MCP) servers extend Claude's capabilities with external integrations. Think of them as plugins that connect Claude to your tools and services.

JSON
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "your_token_here"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://localhost/mydb"
      }
    }
  }
}

Popular MCP Servers:

  • filesystem - Enhanced file operations and search
  • github - Create issues, PRs, and manage repos
  • postgres - Query and manage databases
  • slack - Send messages and notifications
  • aws - Interact with AWS services
Learn More: Check out the complete MCP Servers Guide for detailed setup instructions and advanced configurations.

Tips & Tricks

1. Use Subagents for Complex Research

When you need to explore multiple files or perform open-ended research, ask Claude to use a subagent. This keeps your main context clean.

Prompt
Use a subagent to search the codebase for authentication patterns
and summarize the findings.

2. Chain Commands with &&

Execute multiple commands sequentially in Bash operations.

Bash
npm test && npm run lint && git add . && git commit -m "fix: resolved linting issues"

3. Leverage Memory Archiving

Claude Code automatically archives context before compacting. You can review past decisions later.

Bash
# View archived contexts
ls .claude/memory/pre-compact/

# Read specific archive
cat .claude/memory/pre-compact/2025-11-05_14-30.md

4. Create Custom Agents

Build specialized agents for recurring tasks by creating prompt templates.

Bash
# .claude/agents/code-reviewer.md

You are an expert code reviewer focused on:
- Security vulnerabilities
- Performance bottlenecks
- Best practices
- Test coverage

Review the provided code and give actionable feedback.

5. Monitor Costs Proactively

Set up cost alerts to avoid surprises on your bill.

Bash
# Check daily budget
/cost --daily

# Set alert threshold (requires configuration)
export CLAUDE_COST_ALERT=50  # Alert at $50/day

Conclusion

Mastering Claude Code commands transforms it from a simple chatbot into a powerful development assistant. Start with the basic commands, experiment with configuration, and gradually adopt hooks and MCP servers as your needs grow.

"The difference between a casual Claude Code user and a power user is knowing when to compact, how to configure, and which tools to integrate."