Claude Code Tutorial: Complete Guide to Anthropic's AI Coding Assistant

Z

ZharfAI Team

AI Development

December 26, 202515 min read
Claude Code Tutorial: Complete Guide to Anthropic's AI Coding Assistant

Claude Code Tutorial: Complete Guide to Anthropic's AI Coding Assistant

Are you looking for an AI assistant that truly understands your codebase and can help you write, debug, and refactor code directly from your terminal? Claude Code by Anthropic is exactly what you need. In this comprehensive tutorial, we'll walk you through everything from installation to advanced features.

What is Claude Code?

Claude Code is Anthropic's official command-line interface (CLI) tool that brings Claude's AI capabilities directly into your development workflow. Unlike web-based AI assistants, Claude Code operates within your terminal and has direct access to your project files.

Why Choose Claude Code Over Other AI Assistants?

Here's what makes Claude Code unique:

  • Direct File Access: Claude Code can read, write, and edit files in your project with your permission
  • Command Execution: It can run shell commands, build your project, and execute tests
  • Context Awareness: It understands your entire codebase, not just individual files
  • Extensibility: Connect to external services through MCP (Model Context Protocol) servers
  • Privacy Control: Everything runs locally with granular permission controls

Claude Code Interface - AI-powered command line tool for developers
Claude Code Interface - AI-powered command line tool for developers


Part 1: Installation and Setup

System Requirements

Before installing Claude Code, ensure your system meets these requirements:

RequirementMinimum Specification
Operating SystemmacOS 10.15+, Ubuntu 20.04+, Windows 10+ (with WSL or Git Bash)
Memory (RAM)4 GB
Node.jsVersion 18 or higher (only required for npm installation)
NetworkActive internet connection
ShellBash, Zsh, or Fish recommended

Step-by-Step Installation Guide

Method 1: Direct Installation (Recommended)

This is the fastest and most reliable method:

For macOS and Linux:

curl -fsSL https://claude.ai/install.sh | bash

For Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

For Windows Command Prompt:

curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

Method 2: Homebrew Installation (macOS Only)

If you prefer using Homebrew:

brew install --cask claude-code

Method 3: NPM Installation

For developers who prefer npm:

npm install -g @anthropic-ai/claude-code

Verifying Your Installation

After installation, verify everything is working correctly:

claude doctor

This command checks your installation health and reports any issues.

Authentication Setup

Claude Code requires authentication. You have three options:

  1. Claude App Subscription (Recommended): Use your Pro or Max subscription
  2. Claude Console API: Use API credits from console.anthropic.com
  3. Enterprise Solutions: Amazon Bedrock, Google Vertex AI, or Microsoft Foundry

To authenticate, simply run:

claude

Follow the prompts to log in with your preferred method.


Part 2: Basic Usage and Commands

Starting Your First Session

Navigate to your project directory and start Claude Code:

cd /path/to/your/project
claude

You can also start with an initial prompt:

claude "explain this codebase structure"

Essential CLI Commands

CommandWhat It DoesExample
claudeStart interactive sessionclaude
claude "prompt"Start with initial promptclaude "find bugs in auth module"
claude -p "prompt"Run single query and exitclaude -p "what does main.ts do?"
claude -cContinue last conversationclaude -c
claude -r "name"Resume named sessionclaude -r "auth-refactor"
claude updateUpdate to latest versionclaude update

Understanding the Interface

When you start Claude Code, you'll see a prompt where you can:

  • Type natural language questions or commands
  • Reference files using @filename syntax
  • Use slash commands for quick actions
  • Execute shell commands with ! prefix

Claude Code Commands Interface
Claude Code Commands Interface


Part 3: Slash Commands Reference

Slash commands are powerful shortcuts that help you navigate and control Claude Code efficiently.

Session Management Commands

CommandDescription
/resumeResume a previous conversation
/rename <name>Give your current session a memorable name
/clearClear the conversation history
/rewindUndo recent changes to code or conversation
/exitExit Claude Code

Configuration Commands

CommandDescription
/configOpen the settings interface
/permissionsView and modify tool permissions
/modelSwitch between AI models
/statusDisplay version and connection status
/helpShow all available commands

Memory and Context Commands

CommandDescription
/memoryEdit your project's CLAUDE.md file
/contextVisualize how much context is being used
/compactCompress conversation to save tokens
/initCreate a new CLAUDE.md for your project

Advanced Commands

CommandDescription
/costShow token usage and costs
/exportSave conversation to a file
/hooksManage automation hooks
/mcpConfigure MCP servers
/agentsManage AI subagents
/vimEnable vim-style editing

Part 4: Keyboard Shortcuts

Master these shortcuts to dramatically improve your productivity.

Essential Shortcuts

ShortcutAction
Ctrl+CCancel current operation
Ctrl+DExit Claude Code
Ctrl+LClear the terminal screen
Ctrl+RSearch through command history
/ Navigate through previous commands
Esc + EscRewind recent changes
Shift+TabCycle through permission modes

Multiline Input Methods

MethodHow to Use
BackslashType \ then press Enter
Option+EntermacOS default
Shift+EnterAfter running /terminal-setup
Ctrl+JWorks on all systems

Quick Input Prefixes

PrefixWhat It Does
#Add note to CLAUDE.md memory
/Execute slash command
!Run shell command directly
@Reference a file
?Show available shortcuts

Part 5: Configuration and Settings

Understanding the Settings Hierarchy

Claude Code uses a layered configuration system. Settings are applied in this order (highest priority first):

  1. Enterprise Settings: Organization-wide policies
  2. Command-line Arguments: Flags passed when starting Claude
  3. Local Project Settings: .claude/settings.local.json (not committed to git)
  4. Shared Project Settings: .claude/settings.json (committed to git)
  5. User Settings: ~/.claude/settings.json (your personal defaults)

Configuration File Locations

Enterprise (macOS):     /Library/Application Support/ClaudeCode/managed-settings.json
Enterprise (Linux):     /etc/claude-code/managed-settings.json
Enterprise (Windows):   C:\Program Files\ClaudeCode\managed-settings.json

User Settings:          ~/.claude/settings.json
Project (Shared):       .claude/settings.json
Project (Local):        .claude/settings.local.json

Complete Settings Example

Here's a comprehensive settings file with explanations:

{
  "permissions": {
    "allow": [
      "Bash(npm run:*)",
      "Bash(git status:*)",
      "Bash(git log:*)",
      "Read"
    ],
    "ask": [
      "Bash(git push:*)",
      "Write",
      "Edit"
    ],
    "deny": [
      "Read(.env)",
      "Read(.env.*)",
      "Read(secrets/**)",
      "Bash(rm -rf:*)",
      "Bash(curl:*)"
    ],
    "defaultMode": "default",
    "additionalDirectories": ["../shared-libs"]
  },
  "model": "claude-sonnet-4-5-20250929",
  "outputStyle": "Explanatory",
  "alwaysThinkingEnabled": true,
  "enableAllProjectMcpServers": true
}

Permission Modes Explained

ModeBehaviorBest For
defaultAsks permission on first use of each toolDaily development
acceptEditsAutomatically accepts file editsTrusted projects
planRead-only mode, no modifications allowedCode review
bypassPermissionsSkips all permission promptsUse with extreme caution

Part 6: The Hooks System - Automation Made Easy

Hooks allow you to run custom scripts before or after Claude performs actions. This is incredibly powerful for automation.

What Are Hooks?

Hooks are event-driven scripts that execute automatically when certain actions occur. Think of them as "triggers" that fire when Claude does something.

Available Hook Events

EventWhen It FiresCan Block Action?
PreToolUseBefore Claude uses any toolYes
PostToolUseAfter a tool completesNo
PermissionRequestWhen Claude requests permissionYes
UserPromptSubmitWhen you submit a promptYes
StopWhen Claude finishes respondingNo
SessionStartWhen a new session beginsNo
SessionEndWhen session endsNo

Hook Configuration Structure

Add hooks to your settings file:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "your-script-here"
          }
        ]
      }
    ]
  }
}

Practical Hook Examples

Example 1: Auto-Format Code After Every Edit

Automatically run Prettier whenever Claude edits a file:

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{
        "type": "command",
        "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
      }]
    }]
  }
}

Example 2: Block Access to Sensitive Files

Prevent Claude from modifying environment files:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{
        "type": "command",
        "command": "python3 -c \"import json,sys; d=json.load(sys.stdin); path=d.get('tool_input',{}).get('file_path',''); sys.exit(2 if '.env' in path or 'secret' in path.lower() else 0)\""
      }]
    }]
  }
}

Example 3: Log All Shell Commands

Keep a record of every command Claude executes:

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": "jq -r '.tool_input.command' >> ~/.claude/command-history.log"
      }]
    }]
  }
}

Part 7: MCP Servers - Extending Claude Code's Capabilities

What is MCP (Model Context Protocol)?

MCP stands for Model Context Protocol. It's an open standard developed by Anthropic that allows AI assistants to connect with external tools and services.

Think of MCP servers as "plugins" for Claude Code. They enable Claude to:

  • Access databases and query data
  • Interact with APIs (GitHub, Slack, Notion, etc.)
  • Connect to cloud services
  • Use specialized tools

Why Use MCP Servers?

Without MCP, Claude Code is limited to your local files and shell commands. With MCP, you can:

  • Pull GitHub issues directly into your conversation
  • Query your production database safely
  • Send Slack messages
  • Access documentation from external sources
  • And much more!

MCP Server Architecture
MCP Server Architecture

How to Add MCP Servers

Adding a Remote HTTP Server

claude mcp add --transport http <server-name> <server-url>

Examples:

# Add GitHub MCP server
claude mcp add --transport http github https://api.githubcopilot.com/mcp/

# Add Notion MCP server
claude mcp add --transport http notion https://mcp.notion.com/mcp

Adding a Local Stdio Server

claude mcp add --transport stdio <server-name> -- <command>

Example with environment variables:

claude mcp add --transport stdio postgres \
  --env DATABASE_URL=postgresql://localhost:5432/mydb \
  -- npx -y @modelcontextprotocol/server-postgres

Managing Your MCP Servers

CommandDescription
claude mcp listShow all configured servers
claude mcp get <name>View server details
claude mcp remove <name>Delete a server
claude mcp reset-project-choicesReset server permissions

Popular MCP Servers

ServerWhat It Does
GitHubManage repositories, PRs, issues
PostgreSQLQuery databases
SlackSend and read messages
NotionAccess Notion pages and databases
SentryMonitor application errors
FigmaAccess design files
AWSInteract with cloud resources

MCP Configuration File

You can also configure MCP servers in a .mcp.json file:

{
  "mcpServers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/"
    },
    "postgres": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://localhost:5432/mydb"
      }
    }
  }
}

Part 8: Project Memory with CLAUDE.md

What is CLAUDE.md?

CLAUDE.md is a special markdown file that teaches Claude about your project. When Claude starts, it automatically reads this file to understand:

  • Your project's architecture
  • Coding conventions
  • Common commands
  • Important context

Creating Your CLAUDE.md

Run this command to create a CLAUDE.md file:

/init

CLAUDE.md Best Practices

Here's a well-structured template. Create a file called CLAUDE.md in your project root with sections like:

Project Overview - Brief description of what this project does

Tech Stack - List your technologies (React, Node.js, PostgreSQL, etc.)

Project Structure - Describe your folder organization:

  • src/components/ - Reusable UI components
  • src/pages/ - Route components
  • src/hooks/ - Custom React hooks
  • src/services/ - API client functions
  • src/utils/ - Helper functions

Coding Standards - Your team's conventions:

  • Indentation style (2 spaces, 4 spaces, tabs)
  • Quote style (single or double)
  • Maximum line length
  • TypeScript strict mode settings

Common Commands - Frequently used scripts:

  • npm run dev - Start development server
  • npm run build - Create production build
  • npm run test - Run test suite
  • npm run lint - Check code style

Git Workflow - Your branching strategy and commit conventions

Environment Variables - Required variables (without actual values)

Memory Hierarchy

Claude Code reads multiple memory files in this order:

  1. Enterprise Memory: Organization-wide instructions
  2. Project Memory: ./CLAUDE.md or ./.claude/CLAUDE.md
  3. Modular Rules: ./.claude/rules/*.md
  4. User Memory: ~/.claude/CLAUDE.md
  5. Local Memory: ./CLAUDE.local.md (gitignored, personal)

Claude Code Memory System
Claude Code Memory System


Part 9: IDE Integrations

VS Code Integration

Installation Steps

  1. Open VS Code
  2. Press Cmd+Shift+X (macOS) or Ctrl+Shift+X (Windows/Linux)
  3. Search for "Claude Code"
  4. Click Install

VS Code Shortcuts

ShortcutAction
Cmd/Ctrl+EscFocus Claude Code panel
Cmd/Ctrl+Shift+EscOpen in new tab
Alt+KInsert @-mention with line numbers
Cmd/Ctrl+NStart new conversation

Key Features

  • Inline Diffs: See changes side-by-side before accepting
  • File References: Use @filename:line to reference specific code
  • Plan Mode: Review proposed changes before execution
  • Multiple Tabs: Run parallel conversations

JetBrains IDE Integration

Supported IDEs

  • IntelliJ IDEA
  • PyCharm
  • WebStorm
  • PhpStorm
  • GoLand
  • Android Studio

Installation Steps

  1. Go to SettingsPluginsMarketplace
  2. Search "Claude Code"
  3. Click Install
  4. Restart your IDE

JetBrains Shortcuts

ShortcutAction
Cmd/Ctrl+EscQuick launch Claude
Cmd+Option+K (macOS)Insert file reference
Alt+Ctrl+K (Windows/Linux)Insert file reference

Part 10: Advanced Features

Extended Thinking Mode

For complex problems, enable extended thinking:

ultrathink: design a microservices architecture for an e-commerce platform

This gives Claude more "thinking time" for better solutions.

Subagents

Claude Code can spawn specialized subagents for specific tasks:

/agents

Built-in subagent types:

  • General Purpose: Complex, multi-step tasks
  • Plan: Research and architecture planning
  • Explore: Fast codebase searching

Background Tasks

Run long operations in the background:

Ctrl+B  # Move current operation to background
/bashes # List all background tasks

Plan Mode

Review before executing:

claude --permission-mode plan

Or switch during a session with Shift+Tab.


Part 11: Security Best Practices

Protecting Sensitive Files

Always deny access to sensitive files:

{
  "permissions": {
    "deny": [
      "Read(.env)",
      "Read(.env.*)",
      "Read(secrets/**)",
      "Read(**/*.pem)",
      "Read(**/*.key)",
      "Read(**/credentials*)"
    ]
  }
}

Restricting Dangerous Commands

Block potentially harmful shell commands:

{
  "permissions": {
    "deny": [
      "Bash(rm -rf:*)",
      "Bash(curl:*)",
      "Bash(wget:*)",
      "Bash(sudo:*)"
    ]
  }
}

Using Validation Hooks

Add pre-execution validation for extra safety:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "prompt",
        "prompt": "Analyze this command for security risks. Respond with {\"action\": \"allow\"} if safe or {\"action\": \"deny\", \"reason\": \"explanation\"} if dangerous."
      }]
    }]
  }
}

Part 12: Tips and Best Practices

Writing Effective Prompts

Be Specific:

❌ "Fix the bug"
✅ "Fix the authentication bug in src/auth/login.ts where users see a blank screen after entering incorrect credentials"

Use Step-by-Step Instructions:

1. Create a new migration for the users table
2. Add email verification field
3. Update the User model
4. Write unit tests for the changes

Reference Files Directly:

Explain how @src/auth/middleware.ts validates JWT tokens and integrates with @src/services/user.ts

Session Management Tips

# Name your sessions for easy recall
/rename feature-user-auth

# Resume later
claude -r feature-user-auth

# Export important conversations
/export auth-implementation-notes.md

Productivity Workflow

  1. Start in Plan Mode: Use /plan to explore before making changes
  2. Reference Your CLAUDE.md: Keep it updated with project conventions
  3. Use Background Tasks: Long builds don't block your workflow
  4. Leverage Subagents: Delegate complex research tasks

Quick Reference Card

Daily Commands

claude                    # Start session
claude "task"            # Start with prompt
claude -c                # Continue last session
claude -r "name"         # Resume named session

@filename                # Reference file
/memory                  # Edit CLAUDE.md
/config                  # Settings
/cost                    # Token usage
/help                    # All commands

Environment Variables

ANTHROPIC_API_KEY        # API authentication
DISABLE_AUTOUPDATER      # Disable auto-updates
DISABLE_TELEMETRY        # Opt out of telemetry
MAX_THINKING_TOKENS      # Extended thinking budget
CLAUDE_DEBUG             # Enable debug mode

File Locations

~/.claude/settings.json   # User settings
~/.claude/CLAUDE.md       # User memory
.claude/settings.json     # Project settings (shared)
.claude/settings.local.json # Project settings (personal)
CLAUDE.md                 # Project memory
.mcp.json                 # MCP server config

Conclusion

Claude Code represents a fundamental shift in how developers interact with AI assistants. By operating directly in your terminal with full codebase access, file editing capabilities, and extensibility through hooks and MCP servers, it transforms from a simple chatbot into a genuine coding partner.

Key Takeaways

  1. Start Simple: Begin with basic commands and gradually explore advanced features
  2. Configure Your Environment: Set up permissions and CLAUDE.md for your workflow
  3. Use MCP Servers: Extend capabilities with external integrations
  4. Automate with Hooks: Create custom automations for repetitive tasks
  5. Stay Secure: Always protect sensitive files and limit dangerous commands

Ready to Get Started?

Install Claude Code today:

curl -fsSL https://claude.ai/install.sh | bash
claude

Start coding smarter, not harder!


This tutorial is maintained by the ZharfAI team. For the latest updates, visit our blog regularly.

#Claude Code#AI Coding Assistant#Anthropic Claude#CLI Tools#Developer Tools#AI Programming#MCP Servers#Code Automation#AI Tutorial

Related Posts

Ready to Start Your AI Project?

Get in touch with our team to discuss how we can help your business.