Skip to content

Basic CLI Commands

Learn the essential terminal commands and shortcuts that make Claude Code CLI efficient to use.

What You'll Learn

  • Slash commands for quick actions in the terminal
  • Keyboard shortcuts for terminal interaction
  • CLI session management
  • Getting help from the command line

Slash Commands

Slash commands start with / and perform specific actions. Type them at the prompt:

Essential Commands

Command What It Does
/help Show all available commands
/exit End the session
/clear Clear conversation history
/compact Summarize conversation to save context

Example Session

> /help

Available commands:
  /help       - Show this help message
  /exit       - Exit Claude Code
  /clear      - Clear conversation history
  /compact    - Summarize and compact conversation
  /config     - View/edit configuration
  ...

> /clear

Conversation cleared. Starting fresh.

>

CLI Invocation Options

Claude Code CLI supports various command-line arguments. These are typed in your terminal before starting an interactive session.

Basic Start

# Interactive mode in current directory
claude

With Initial Prompt

# Start with a question (terminal argument)
claude "explain what this project does"

# Start and immediately begin a task
claude "find all TODO comments in this codebase"

Continue Previous Session

# Resume your last conversation
claude --continue
# or
claude -c

This restores context from your previous terminal session - useful when you need to step away and come back.

Non-Interactive Mode (Scripting)

Perfect for shell scripts and automation:

# Get an answer and exit (no interactive session)
claude -p "what does the main function do"

# Pipe output to a file
claude -p "explain this codebase" > explanation.md

# Use in shell scripts
RESULT=$(claude -p "what testing framework is used")
echo "This project uses: $RESULT"

Specify a Directory

# Work in a different directory without cd-ing
claude --cwd /path/to/project

Terminal Keyboard Shortcuts

These keyboard shortcuts work at the Claude Code CLI prompt (similar to other terminal tools like bash):

Shortcut Action
Enter Send message
Shift+Enter New line (multiline input)
Ctrl+C Cancel current operation
Ctrl+C (twice) Exit Claude Code CLI
Up Arrow Previous message in history
Down Arrow Next message in history
Ctrl+L Clear terminal screen (keeps conversation)
Tab Auto-complete (where supported)

Multiline Input

For longer prompts, use Shift+Enter to add new lines:

> Here's my requirements:
  - User authentication
  - Password hashing
  - JWT tokens

  Please create a basic auth module.

Session Management

Checking Status

> /status

Shows current session info like working directory and conversation length.

Compacting Long Conversations

As conversations grow, they use more context. Use /compact to summarize:

> /compact

Compacting conversation...
Previous context summarized. Continuing with fresh context.

This preserves key information while reducing token usage.

Configuration

> /config

View and modify settings like: - Default model - Auto-permission settings - Theme preferences

Getting Help

In-Session Help

> /help

Asking Claude

You can ask Claude about its own capabilities:

> What can you do?

> How do I create a git commit with you?

> Can you run docker commands?

Documentation

> /docs

Opens the official documentation.

Practical Examples

Example 1: Quick Project Overview

cd ~/some-project
claude "give me a quick overview of this codebase"

Example 2: Continue Working

# Yesterday you were debugging
claude -c
# Claude remembers your context

> Let's continue fixing that bug we found

Example 3: One-Off Question

# Quick question, no session
claude -p "what's the difference between let and const in javascript"

Example 4: Focused Session

# Start fresh in a specific directory
claude --cwd ./src "I want to refactor the utils folder"

Try It Yourself

Exercise: Command Practice

  1. Start Claude Code:

    claude
    

  2. Try each of these commands:

    > /help
    > /status
    > /clear
    

  3. Practice multiline input:

    > Create a function that:
      - Takes a list of numbers
      - Filters out negatives
      - Returns the sum
    

  4. Exit and restart with continue:

    > /exit
    
    claude -c
    

  5. Verify it remembers your conversation:

    > What function did we just create?
    

CLI Quick Reference Card

Print this out or keep it handy in your terminal:

┌───────────────────────────────────────────────────────┐
│ CLAUDE CODE CLI QUICK REFERENCE                       │
├───────────────────────────────────────────────────────┤
│ TERMINAL COMMANDS (before starting)                   │
│   claude              Start interactive session       │
│   claude "prompt"     Start with initial prompt       │
│   claude -c           Continue last session           │
│   claude -p "q"       Non-interactive (for scripts)   │
│   claude --cwd DIR    Work in specific directory      │
│   claude --version    Show CLI version                │
│   claude --help       Show all CLI options            │
├───────────────────────────────────────────────────────┤
│ SLASH COMMANDS (inside session)                       │
│   /help               Show help                       │
│   /exit               Exit session                    │
│   /clear              Clear conversation history      │
│   /compact            Summarize to save context       │
│   /config             View/edit settings              │
├───────────────────────────────────────────────────────┤
│ KEYBOARD SHORTCUTS                                    │
│   Ctrl+C              Cancel / Exit (2x)              │
│   Shift+Enter         Multiline input                 │
│   Up/Down             History navigation              │
│   Ctrl+L              Clear terminal screen           │
└───────────────────────────────────────────────────────┘

What's Next?

You know the CLI commands - now let's learn how Claude Code CLI works with files in 03-file-operations.


Summary: - Terminal commands (claude, claude -c, claude -p) - typed in your shell - Slash commands (/help, /exit, /clear) - typed inside a session - Use claude -p for shell scripting and automation - Use Shift+Enter for multiline prompts in the terminal - /compact keeps conversations manageable in long sessions


Learning Resources

NetworkChuck: AI in the Terminal - Commands Section (3.6M subscribers)

Deep dive into Claude Code CLI commands, slash commands, keyboard shortcuts, and productivity tips.

Additional Resources

Type Resource Description
🎬 Video 800+ Hours Learning Claude Code Edmund Yong - Advanced tips and shortcuts
📚 Official Docs CLI Reference Complete command documentation
📖 Tutorial How I Use Claude Code Builder.io practical guide
🎓 Free Course AI in Terminal Guide NetworkChuck's companion repository
💼 Commercial AI Coding Crash Course Udemy - Comprehensive AI coding