Basic Commands Beginner

Learn the essential commands and interactions in Claude Code. This lesson covers starting a session, asking questions, using slash commands, managing permissions, and understanding how Claude Code uses tools behind the scenes.

Starting Claude Code

The simplest way to start Claude Code is to type claude in your terminal. Always navigate to your project directory first — Claude Code uses your current directory as context.

Terminal
# Navigate to your project
$ cd ~/projects/my-app

# Start interactive mode
$ claude

# Or start with an initial prompt
$ claude "explain the project structure"

# Or pipe input from another command
$ cat error.log | claude "what's causing these errors?"

Command-Line Flags

Claude Code accepts several useful flags when starting:

Flag Description Example
--version Show the installed version claude --version
--help Show help and available options claude --help
--model Specify which Claude model to use claude --model claude-sonnet-4-20250514
--allowedTools Restrict which tools Claude can use claude --allowedTools Read,Grep
--print / -p Non-interactive mode: print response and exit claude -p "what does this repo do?"
--continue / -c Continue the most recent conversation claude -c
--resume Resume a specific conversation by ID claude --resume abc123

Asking Questions About Your Code

Once inside a Claude Code session, you simply type natural language messages. There is no special syntax needed — just describe what you want.

Claude Code Session
# Ask about project structure
Claude > What is the overall architecture of this project?

# Ask about specific code
Claude > How does the authentication middleware work?

# Ask for explanations
Claude > Explain what the useEffect hook in UserProfile.tsx does

# Ask for suggestions
Claude > What are potential performance issues in this codebase?

# Reference specific files
Claude > Look at src/utils/helpers.ts and suggest improvements
Be Specific: The more specific your request, the better the results. Instead of "fix the bug," say "fix the bug where the login form doesn't validate email addresses with plus signs in src/components/LoginForm.tsx."

The /help Command

Type /help at any time to see a list of available slash commands and keyboard shortcuts:

Claude Code Session
Claude > /help

Available commands:
  /help           Show this help message
  /compact        Compact the conversation (reduce context usage)
  /clear          Clear conversation history
  /model          Change the AI model
  /commit         Create a git commit
  /review         Review a pull request
  /pr             Create a pull request
  /config         View/edit configuration
  /cost           Show token usage and cost
  /doctor         Check system health
  ...

Slash Commands Reference

Slash commands are special commands prefixed with / that control Claude Code's behavior. Here is a complete reference:

Command Description When to Use
/help Display available commands and shortcuts When you need a reminder of available options
/compact Summarize conversation to reduce token usage When conversation is getting long and you want to free up context
/clear Clear the entire conversation history When starting a completely new task in the same session
/model View or change the active Claude model When you want to switch between Sonnet and Opus
/commit Create a git commit with an AI-generated message After making changes you want to commit
/review Review the current diff or a specific PR Before committing or when reviewing someone's PR
/pr Create a pull request with AI-generated description When ready to submit a PR
/cost Show token usage and estimated cost for the session When you want to monitor your API spending
/config View or modify Claude Code configuration When you need to adjust settings
/doctor Run diagnostics to check for common issues When something is not working correctly

Reading Files

Claude Code can read any file in your project. You do not need to use a special command — just reference the file in your message, and Claude will read it.

Claude Code Session
# Claude will automatically read the file
Claude > What does src/index.ts do?

# Ask about specific parts
Claude > Show me the exports from src/utils/helpers.ts

# Compare files
Claude > Compare the error handling in api/v1/routes.ts vs api/v2/routes.ts

Behind the scenes, Claude Code uses tools like Read (to read file contents), Glob (to find files by pattern), and Grep (to search for text across files).

Running Shell Commands

Claude Code can run shell commands on your behalf. This is useful for running tests, checking build output, or any terminal operation.

Claude Code Session
# Run tests
Claude > Run the test suite and tell me what fails

# Check project status
Claude > Run npm build and show me any errors

# Check git status
Claude > Show me the git log for the last 5 commits

# Run arbitrary commands
Claude > Run ls -la src/ to see all files in the src directory
Safety First: By default, Claude Code will ask for your permission before running shell commands. This is a safety feature — always review the command before approving, especially for commands that modify files, install packages, or access the network.

Permission Modes

Claude Code has a permission system that controls how much autonomy it has. You can choose the level of control that suits your comfort level.

Mode Behavior Best For
Default (Ask) Asks permission for file edits and shell commands. Read-only operations are automatic. General use. Recommended for most users.
Auto-accept edits Automatically accepts file edits but still asks for shell commands. When you trust Claude's edits but want to review commands.
Full auto-accept Automatically accepts both edits and commands. CI/CD pipelines, automated workflows. Use with caution.
Terminal
# Start with default permissions (recommended)
$ claude

# Start with auto-accept for file edits
$ claude --allowedTools Edit,Write,Read,Glob,Grep

# Non-interactive mode (for scripts/CI)
$ claude -p "fix the linting errors" --dangerously-skip-permissions
Caution: The --dangerously-skip-permissions flag bypasses all safety checks. Only use this in controlled environments like CI/CD pipelines where the code is sandboxed. Never use it on your main development machine without understanding the risks.

Understanding Tool Use

When Claude Code processes your request, it uses a set of tools to interact with your system. Understanding these tools helps you understand what Claude Code is doing and why.

Tool Purpose Requires Permission
Read Read the contents of a file No (read-only)
Glob Find files matching a pattern (e.g., **/*.ts) No (read-only)
Grep Search for text patterns across files No (read-only)
Edit Make targeted edits to existing files Yes (modifies files)
Write Create new files or overwrite existing ones Yes (modifies files)
Bash Run shell commands in the terminal Yes (executes commands)

During a session, you will see Claude Code announce which tool it is using. For example:

Claude Code Output
Claude > Fix the login validation bug

Claude is using: Grep
  Searching for "login" in **/*.ts

Claude is using: Read
  Reading src/components/LoginForm.tsx

Claude is using: Edit
  Editing src/components/LoginForm.tsx
  Replace: const emailRegex = /^[a-zA-Z0-9]+@/
  With:    const emailRegex = /^[a-zA-Z0-9._%+-]+@/

  Accept this edit? (y/n)

Keyboard Shortcuts

Shortcut Action
Ctrl+C Cancel the current operation / interrupt Claude
Ctrl+D Exit Claude Code
Up Arrow Recall previous message
Escape Cancel current input

Try It Yourself

Start a Claude Code session in any project directory and try these exercises:

  1. Type /help to see available commands
  2. Ask Claude to explain the project structure
  3. Ask a question about a specific file
  4. Use /cost to check your token usage
  5. Use /compact to summarize the conversation