Claude Code & CLI Tools
Getting Started with Claude Code
4 min read
Claude Code is Anthropic's official terminal-based AI coding assistant. If you live in the terminal, this is your tool.
Why Claude Code?
Claude Code excels when you:
- Prefer terminal over GUI
- Work with complex, multi-step tasks
- Need agentic capabilities (autonomous work)
- Want deep git integration
- Require MCP (Model Context Protocol) connections
Installation
Prerequisites
- Node.js 18+ installed
- npm or yarn
- Anthropic API key
Install Globally
npm install -g @anthropic-ai/claude-code
Verify Installation
claude --version
# Output: Claude Code v2.0.76 (or latest)
First-Time Setup
claude config set api-key YOUR_ANTHROPIC_API_KEY
Or use environment variable:
export ANTHROPIC_API_KEY=your-key-here
Basic Usage
Start an Interactive Session
cd your-project
claude
This opens an interactive REPL where you can chat with Claude about your code.
Single Command
claude "Explain what this project does"
With File Context
claude "Review this file for security issues" --file src/auth.ts
The Interface
┌─────────────────────────────────────────────────────────────┐
│ Claude Code v2.0.76 │
│ Working directory: ~/projects/my-app │
│ Model: claude-3-5-sonnet-20241022 │
├─────────────────────────────────────────────────────────────┤
│ │
│ You: Create a utility function for date formatting │
│ │
│ Claude: I'll create a date formatting utility for you. │
│ │
│ [Creating file: src/utils/dateFormat.ts] │
│ │
│ ```typescript │
│ export function formatDate(date: Date): string { │
│ return date.toLocaleDateString('en-US', { │
│ year: 'numeric', │
│ month: 'long', │
│ day: 'numeric' │
│ }); │
│ } │
│ ``` │
│ │
│ [Apply changes? (y/n)] │
│ │
├─────────────────────────────────────────────────────────────┤
│ > _ │
└─────────────────────────────────────────────────────────────┘
Essential Commands
Slash Commands
| Command | Description |
|---|---|
/help |
Show available commands |
/clear |
Clear conversation history |
/model |
Change AI model |
/config |
View/edit configuration |
/checkpoint |
Save current state |
/restore |
Restore from checkpoint |
/cost |
Show API usage cost |
Keyboard Shortcuts
| Key | Action |
|---|---|
| Ctrl+C | Cancel current operation |
| Ctrl+D | Exit Claude Code |
| Up/Down | Navigate history |
| Tab | Autocomplete file names |
Configuration
View Current Config
claude config list
Important Settings
# Set default model
claude config set model claude-3-5-sonnet-20241022
# Enable auto-apply (don't ask for confirmation)
claude config set auto-apply true
# Set thinking mode
claude config set thinking-mode extended
# Configure max tokens
claude config set max-tokens 8192
Project-Level Configuration
Create .claude/config.json in your project:
{
"model": "claude-3-5-sonnet-20241022",
"autoApply": false,
"thinkingMode": "normal",
"context": {
"includeGitHistory": true,
"maxFiles": 50
},
"rules": [
"Use TypeScript for all new files",
"Follow the existing code style",
"Include JSDoc comments for public functions"
]
}
Your First Task
Let's complete a real task:
Step 1: Navigate to Project
cd ~/my-project
Step 2: Start Claude Code
claude
Step 3: Ask Claude
Create a simple API endpoint that returns the server health status.
Include timestamp and memory usage.
Step 4: Review Changes
Claude will show you the proposed changes with diffs.
Step 5: Apply or Modify
- Type
yto apply all changes - Type
nto reject - Type
eto edit before applying
IDE Integration
VS Code Extension
- Install "Claude Code" from VS Code marketplace
- Press ⌘/Ctrl + Shift + P
- Type "Claude Code: Open Terminal"
- Claude Code runs in integrated terminal
JetBrains Integration
- Install "Claude Code" plugin
- Open Terminal panel
- Run
claudecommand
Comparison with Cursor
| Feature | Claude Code | Cursor |
|---|---|---|
| Interface | Terminal | GUI |
| Best for | Complex tasks, automation | Visual editing |
| Learning curve | Higher | Lower |
| Customization | Extensive | Moderate |
| Checkpoints | Built-in | Manual |
| MCP Support | Native | Limited |
Use Both: Many developers use Cursor for daily coding and Claude Code for complex refactoring or automation tasks.
Troubleshooting
Command Not Found
# Ensure global npm bin is in PATH
export PATH="$PATH:$(npm bin -g)"
API Key Issues
# Verify key is set
claude config get api-key
# Test with simple command
claude "Say hello"
Model Unavailable
# List available models
claude config list-models
# Use a different model
claude --model claude-3-5-sonnet-20241022 "Your prompt"
Terminal Power: Claude Code gives you AI assistance without leaving your terminal workflow. In the next lesson, we'll explore the agentic features that make it uniquely powerful. :::