Published on

Claude Code: Complete Setup and Latest Features Guide

Authors

Claude Code is Anthropic's official CLI for interacting with Claude AI directly from your terminal. This guide covers installation, configuration, and expert tips to maximize your productivity.

Quick Installation

# Requires Node.js 18+
npm install -g @anthropic-ai/claude-code

# Alternative: Native binary (Alpha)
curl -fsSL claude.ai/install.sh | bash

# Start Claude in your project
cd your-project
claude

Essential Configuration Files

Project Configuration (.claude/settings.json)

{
  "permissions": ["read", "write", "bash"],
  "diff_tool": "auto",
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "prettier --write \"$CLAUDE_FILE_PATHS\""
          }
        ]
      }
    ]
  }
}

Project Documentation (CLAUDE.md)

Create a CLAUDE.md file in your project root to provide context:

# Project Setup

- Run `npm test` for testing
- Use `npm run dev` for development
- Deploy with `npm run build`

# Code Standards

- TypeScript for all new code
- Jest for testing
- ESLint configuration enforced

# Common Commands

- `/test` - Run unit tests
- `/build` - Create production build

Slash Commands

Built-in Commands

/init           # Initialize project with CLAUDE.md
/clear          # Clear conversation (keep summary with /compact)
/config         # Settings configuration
/help           # Show available commands
/hooks          # Configure hooks
/mcp            # MCP server management
/permissions    # Manage permissions
/ide            # Connect to IDE
/doctor         # Check installation
/model          # Switch between Claude models
/terminal-setup # Configure terminal shortcuts

Custom Project Commands

Create custom commands in .claude/commands/:

# Create security review command
mkdir -p .claude/commands
echo "Review code for security vulnerabilities" > .claude/commands/security.md

# Create optimization command
echo "Optimize code performance and identify bottlenecks" > .claude/commands/optimize.md

# Usage
/security
/optimize

Personal Commands (Global)

# Create global commands
mkdir -p ~/.claude/commands
echo "Create comprehensive unit tests" > ~/.claude/commands/test.md
echo "Add detailed documentation" > ~/.claude/commands/document.md

Commands with Arguments

# Command with arguments
echo 'Fix issue #$ARGUMENTS following coding standards' > .claude/commands/fix-issue.md

# Usage
/fix-issue 123

Hooks System

Hooks allow automatic actions based on Claude's activities:

Hook Types

  • PreToolUse: Before tool execution (can block)
  • PostToolUse: After tool completion
  • Notification: On Claude notifications
  • Stop: When Claude finishes
  • SubagentStop: When subagents complete

Example Hook Configuration

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "prettier --write \"$CLAUDE_FILE_PATHS\""
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"$(date): $CLAUDE_TOOL_INPUT\" >> ~/.claude/commands.log"
          }
        ]
      }
    ]
  }
}

MCP (Model Context Protocol) Servers

Adding MCP Servers

# GitHub integration
claude mcp add --transport sse github-server https://api.github.com/mcp

# PostgreSQL database
claude mcp add postgres-server /path/to/server --connection-string "postgresql://..."

# Import from Claude Desktop
claude mcp add-from-claude-desktop

Using MCP Resources

# Reference resources with @ mentions
@github:issue://123
@postgres:schema://users

# Example usage
"Analyze @github:issue://123 and suggest a fix"
"Compare @postgres:schema://users with our model"

IDE Integration

VS Code/Cursor/Windsurf

# Auto-install extension
code .  # or cursor . or windsurf .
claude  # Extension installs automatically

# Connect from external terminal
/ide

JetBrains IDEs

Plugin auto-installs when running claude. For manual installation:

  • Install "Claude Code" from marketplace
  • Requires complete IDE restart

Terminal Optimization

Keyboard Shortcuts

# Set up shortcuts automatically
/terminal-setup

# Configures:
# - Shift+Enter for line breaks
# - Option+Enter as alternative

Line Breaks in Commands

# Method 1: Backslash escape
Type \ followed by Enter

# Method 2: Use configured shortcuts
Shift+Enter or Option+Enter

Usage Patterns

Basic Operations

# Project analysis
"What does this project do?"
"Explain the folder structure"

# Code changes
"Add error handling to user registration"
"Refactor this component to use hooks"
"Add TypeScript types"

# Git operations
"What files have I changed?"
"Commit changes with descriptive message"

Advanced Workflows

# Multi-file operations
"Refactor authentication across all components"
"Add error handling to entire API"

# Testing and debugging
"Add unit tests for new functions"
"Debug memory leak in dashboard"
"Optimize database queries"

File References

# Reference specific files
"Review @src/utils/helpers.js"
"Compare @src/old.js with @src/new.js"
"Add tests to @__tests__/utils.test.js"

Performance Tips

Token Management

  • Use /clear frequently to reset context
  • Reference specific files instead of broad context
  • Run multiple Claude instances for parallel work

Hook Optimization

  • Use specific matchers (Edit|Write not empty string)
  • Set timeouts for long-running hooks
  • Avoid blocking PreToolUse hooks when possible

Troubleshooting

Common Issues

# Check installation
claude doctor

# Permission errors - DON'T use sudo
claude migrate-installer  # Local installation

# IDE extension not working
# 1. Restart IDE completely
# 2. Check extension is enabled
# 3. Run from integrated terminal

# Settings not persisting
ls ~/.claude/settings.json      # User settings
ls .claude/settings.json       # Project settings

Latest 2025 Features

New Capabilities

  • Claude Opus 4: Complex coding tasks with extended thinking
  • Claude Sonnet 4: Fast, efficient for everyday work
  • Native Windows support: No WSL required
  • Remote MCP servers: OAuth authentication support
  • Enhanced hooks: More event types and flexibility
  • Multi-agent workflows: Specialized roles for complex tasks

Model Switching

  • Automatically uses Opus until 50% usage
  • Switches to Sonnet for cost efficiency
  • Manual switching: "Use extended thinking" or "Switch to fast mode"

13 Expert Tips for Claude Code

1. Use in Cursor or VS Code

Run Claude Code within Cursor or VS Code to leverage IDE features. Claude gains reference to open files automatically, making it easier to work with your codebase.

2. Initialize Projects with /init

Use /init to create a CLAUDE.md file that acts as project memory. This file stores project-specific information and is loaded at the beginning of every chat session.

3. Manage Context Effectively

  • /compact - Clears conversation history while keeping a summary
  • /clear - Completely clears conversation history (like "new chat")
  • Context includes all conversation history and project data sent to the model

4. Switch Models with /model

Change between Claude models (Opus/Sonnet) based on your subscription. Default prioritizes Opus 4 for up to 50% usage before switching to Sonnet 4.

5. Change Modes with Shift+Tab

Cycle through different interaction modes:

  • Auto-accept edits: Automatically approves file operations
  • Plan mode: Conversational only, won't write files (useful for planning)

6. Add Files and Screenshots

  • Reference files by dragging into terminal or using @filename
  • Paste screenshots directly (Ctrl+V) for Claude to analyze visual content

7. Use Dedicated Terminal Tab

Open a dedicated Claude Code tab that functions like a regular shell but maintains Claude integration (using command escape mechanism).

8. Create Custom Commands

Define commands in .claude/commands/ folder:

# First line is the command description
echo "Modify VS Code settings for current project" > .claude/commands/project_settings.md

9. Customize Project Settings

Example custom command to modify VS Code appearance:

# /project_settings command
# Creates .vscode/settings.json with custom theme

10. Use Sub-agents for Multi-tasking

Launch multiple concurrent sub-agents for parallel tasks:

# design_iterate command can create multiple UI variations
# Each sub-agent works independently toward specific objectives

11. YOLO Mode (Use Cautiously)

Run with --dangerously-skip-permissions for rapid iteration without permission prompts. Warning: Only for trusted environments!

12. Claude as Utility Function

Integrate Claude into external scripts:

# Example: Raycast script on macOS
# Takes clipboard content → Claude suggests filename → Saves file

13. Configure Hooks for Automation

Set up hooks for specific events:

  • Stop hook: Play audio chime when Claude finishes
  • PreToolUse: Before tool execution
  • PostToolUse: After tool completion
  • Notification: When Claude needs attention
  • SubagentStop: When sub-agents complete
{
  "hooks": {
    "Stop": [
      {
        "type": "command",
        "command": "afplay /System/Library/Sounds/Glass.aiff"
      }
    ]
  }
}

Best Practices

  1. Create CLAUDE.md in every project for context
  2. Set up project-specific commands for common tasks
  3. Configure hooks for automatic formatting/linting
  4. Use MCP servers for external integrations
  5. Reference files explicitly with @ mentions
  6. Clear context regularly to maintain performance
  7. Leverage IDE integration for visual diffs
  8. Use plan mode for complex tasks before execution
  9. Configure Stop hooks for audio feedback
  10. Create utility scripts for repetitive tasks

This comprehensive setup enables efficient AI-assisted development with Claude Code, combining basic features with advanced techniques for maximum productivity.

Related Posts