Skip to main content

Lesson 2: Basic Operations

Learning Objectives

After completing this lesson, you will be able to:

  • Communicate effectively with Claude in chat mode
  • Ask Claude to read and analyze files
  • Request edits to existing files
  • Understand how permissions work
  • Use essential CLI flags (-p, -c, -r)
  • Exit sessions properly

Prerequisites

  • Completed Lesson 1 - You should have Claude Code installed and authenticated
  • A code editor - For viewing files alongside Claude Code
  • Terminal access - For running Claude Code commands

Estimated Time: 25 minutes


Chat Mode Fundamentals

Chat mode is the primary way you'll interact with Claude Code. It's a conversational interface where you describe what you want, and Claude helps you accomplish it.

How Chat Mode Works

  1. You type a message describing what you want

  2. Claude responds with:

    • Questions to clarify your request
    • Explanations of code or concepts
    • Proposed changes (using tools)
    • Direct answers to questions
  3. Tools execute when Claude needs to:

    • Read files
    • Edit files
    • Create new files
    • Run commands

Conversation Flow

You → [Request]

Claude ← [Response + Tool Use]

You ← [Confirm Permission]

System → [Execute Tool]

You ← [See Result]

[Continue Conversation]

Reading Files

One of Claude's most powerful capabilities is reading and understanding your code.

Asking Claude to Read Files

Simply ask Claude to read a file:

You> Can you read the file src/main.py and explain what it does?

Claude will:

  1. Request permission to read the file
  2. Display the request showing which file will be accessed
  3. Wait for your approval
  4. Read and analyze the file after you approve

Permission Request Example

When Claude asks to read a file, you'll see:

📖 Read src/main.py

This will read the file contents. Proceed? [Y/n]

Options:

  • Y or Enter - Allow this operation
  • n - Deny this operation
  • Ctrl+C - Cancel the entire operation

Reading Multiple Files

You can ask Claude to read multiple files:

You> Read all the Python files in the src/ directory

Claude will request permission for each file individually.

Reading Without Explicit Requests

Claude may also request to read files when:

  • You ask a question that requires file context
  • You reference code in a file
  • You're working on a task that needs understanding of existing code

Example:

You> How do I add a new user to the system?

Claude: [Will request to read relevant files to understand the current implementation]

Making Edits

Claude can edit files for you, but always asks permission first.

Requesting Edits

Describe the change you want:

You> Update the greet function in src/main.py to include a timestamp

Claude will:

  1. Read the file (if needed)
  2. Propose changes using the Edit tool
  3. Show you the exact diff of what will change
  4. Request your approval

Edit Permission Example

✏️ Edit src/main.py

--- a/src/main.py
+++ b/src/main.py
@@ -1,3 +1,4 @@
def greet(name):
- return f"Hello, {name}!"
+ from datetime import datetime
+ return f"Hello, {name}! Time: {datetime.now()}"

Apply this edit? [Y/n]

Creating New Files

Claude can also create new files:

You> Create a new file called utils.py with a function to format dates

Claude will:

  1. Show you the proposed file contents
  2. Ask for permission to create the file
  3. Create the file in the specified location

Understanding Permissions

Permissions are central to how Claude Code works. They ensure you stay in control of what happens to your codebase.

Why Permissions Exist

  • Safety: Prevent accidental changes
  • Awareness: Keep you informed of what's happening
  • Control: You decide what executes
  • Learning: Understand what Claude is doing

Permission Flow

Every tool use requires permission:

Claude wants to use a tool

System displays the request

You approve or deny

Tool executes (if approved)

Result is shown

Types of Tool Permissions

ToolPermission PromptWhat It Does
Read📖 Read fileView file contents
Edit✏️ Edit fileModify existing file
Write📝 Write fileCreate new file
Bash⚡ Run commandExecute terminal command

Responding to Permission Requests

Always: Y or press Enter Never: n Cancel: Ctrl+C

Pro Tip: You can set different permission modes (covered in Lesson 4) to automatically approve certain types of operations.


Basic CLI Flags

Claude Code supports several command-line flags for different use cases.

Single-Prompt Mode (-p)

Execute a single prompt and exit:

claude -p "List all Python files in the current directory"

Use cases:

  • Quick questions
  • One-off tasks
  • Scripting/automation

Example:

claude -p "Create a simple HTTP server in Python"

Command Mode (-c)

Run a shell command with Claude's assistance:

claude -c "npm install"

Claude will:

  • Execute the command
  • Show you the output
  • Help interpret any errors
  • Suggest fixes if things go wrong

Use cases:

  • Running build commands
  • Installing dependencies
  • Executing tests

Read Mode (-r)

Have Claude read and process a file:

claude -r src/main.py -p "Explain this code"

This combines file reading with a prompt about the file.

Use cases:

  • Code review
  • Documentation generation
  • Quick analysis

Combining Flags

You can combine flags:

claude -r app.js -p "Find potential bugs and suggest fixes"

Exiting Sessions

Clean Exit

Always exit sessions properly to ensure:

  • Session history is saved
  • Resources are freed
  • Any background tasks are handled

Methods:

  • Type /exit
  • Press Ctrl+D
  • Type exit

What Gets Saved

When you exit:

  • Conversation history is saved for resumption
  • Pending tasks are noted
  • Session context is preserved

You can resume previous sessions (covered in Lesson 8).


Practical Example: Hello World Project

Let's create a simple project to practice what you've learned.

Step 1: Set Up Project Directory

cd ~/claude-test
mkdir hello-world
cd hello-world

Step 2: Start Claude Code

claude

Step 3: Create a Python Script

You> Create a Python script called hello.py that prints "Hello, World!" five times

Expected flow:

  1. Claude proposes the file contents
  2. You approve the Write operation
  3. File is created

Step 4: Read the File

You> Read the hello.py file and explain what each line does

Expected flow:

  1. Claude requests permission to read
  2. You approve
  3. Claude explains the code

Step 5: Make an Edit

You> Update hello.py to print each line with a number (1, 2, 3, 4, 5)

Expected flow:

  1. Claude proposes an edit
  2. You see the diff
  3. You approve
  4. File is updated

Step 6: Run the Script

You> Run the hello.py script using Bash

Expected flow:

  1. Claude requests to run python hello.py
  2. You approve
  3. You see the output

Step 7: Exit

You> /exit

✅ Check Your Understanding

  1. What happens when you ask Claude to read a file?

    • It reads immediately
    • It asks for permission first
    • It requires a special flag
    • It can't read files
  2. Which flag runs a single prompt and exits?

    • -c
    • -p
    • -r
    • -s
  3. How do you properly exit a Claude Code session?

    • Close the terminal window
    • Press Ctrl+C
    • Type /exit or press Ctrl+D
    • Just close your laptop
  4. True or False: Claude can edit files without your permission.

    • True
    • False
  5. What does the -c flag do?

    • Creates a new file
    • Runs a command with Claude's assistance
    • Reads a file
    • Configures settings

Answers: 1-b, 2-b, 3-c, 4-False, 5-b


Summary

In this lesson, you learned:

  • Chat mode - Conversational interface for interacting with Claude
  • Reading files - Ask Claude to read, approve the request
  • Making edits - Request changes, review diffs, approve
  • Permissions - Every tool use requires your approval
  • CLI flags - -p for single prompts, -c for commands, -r for reading
  • Exiting - Use /exit or Ctrl+D for clean shutdown

Next Steps

In Lesson 3: Working with Your Codebase, you'll learn:

  • How Claude understands project context
  • Searching files with Grep and Glob
  • Using @ for file references
  • Asking intelligent questions about code
  • Performing simple refactoring

Further Reading


Continue to Lesson 3: Working with Your Codebase