Claude Code in Action
Install, Configure, and Program with AI from Scratch: 120 Exercises with Claude Code CLI in the Terminal, Also on Windows
Fran Orellana
Free sample · First chapters
This book is intended for students, junior developers, self-taught learners, and technical professionals who have basic programming knowledge and want to use Claude Code from the terminal thoughtfully. You do not need any previous experience with AI agents, but you should know how to navigate folders, run simple commands, and read basic code. The next chapter, “Set Up Your Environment,” explains step by step how to install Claude Code and prepare everything you need, including on Windows. After that, you will find eight progressive sections. Each section begins with a lesson titled “What You Need to Know,” which introduces only the concepts needed to complete its exercises. The challenges progress from your first commands and queries to controlled editing, testing, Git, debugging, automation, and a final project. Read the objective before you begin, phrase your requests precisely, and always review the changes the agent proposes. The solutions appear at the end of the book: try to solve each exercise before consulting them, then compare your approach with the proposed solution. If something goes wrong, return to the previous exercise and check which concept is missing.
For example, to open Claude Code and ask it to review a file, you only need a computer, a terminal, and a Claude account with access to Claude Code. You do not need to install a special editor or know how to use artificial intelligence.
To work through the exercises, you will need:
Claude Code is not completely free software. Access depends on your Claude plan or API usage. Git, Python, Visual Studio Code, and the terminals mentioned in this chapter, on the other hand, are free.
You do not need to know Git or Python before you begin. Here, you will only prepare what you need to follow the exercises.
A terminal is a window where you type commands. Claude Code runs inside it.
If you use macOS, open the Terminal application:
Command + Space.Terminal.Return.If you use Linux, open the application called Terminal.
If you use Windows, you have two recommended options:
To begin, PowerShell is sufficient. Open it like this:
PowerShell.Type this command to check that the terminal responds:
BASH
echo Hello
You should see:
CÓDIGO
Hello
If you see that text, the terminal is working. If an error message appears, close the window, open it again, and repeat the command.
Git keeps a history of changes to your files. This lets you see what has changed and restore an earlier version.
On macOS, install Git with Apple’s developer tools:
BASH
xcode-select --install
If it is already installed, macOS will tell you. Accept the installation if a window appears.
On Ubuntu or another Debian-based distribution, type:
BASH
sudo apt update sudo apt install git
Linux may ask for your password. You will not see any letters on the screen while typing it. This is normal. Type the password and press Return.
On Windows, install Git for Windows from Git’s official website:
CÓDIGO
https://git-scm.com/
During installation, you can keep the options that are selected by default.
When it finishes, close and reopen the terminal. Check Git with this command:
BASH
git --version
You will see a version similar to this:
CÓDIGO
git version 2.49.0
The number may be different. The important thing is that git version appears.
Python lets you run simple programs. It can also be used to create test files during some exercises.
First, check whether you already have it.
On macOS or Linux:
BASH
python3 --version
On Windows:
POWERSHELL
py --version
The result should include Python 3, for example:
CÓDIGO
Python 3.13.2
If Python does not appear, install it from its official website:
CÓDIGO
https://www.python.org/
On Windows, during installation, check Add Python to PATH before clicking the installation button. This option lets you use Python from the terminal.
After installing it, close the terminal, open a new one, and repeat the check.
You do not need to install any Python packages yet. The exercises will tell you if one is needed.
You need to be able to read and modify files. You can use a free editor such as Visual Studio Code, available from its official website:
CÓDIGO
https://code.visualstudio.com/
Install it using the default options.
You can also use an editor that already comes with your system. Do not use a word processor such as Word to edit code. These programs add invisible formatting and can damage the files.
When Claude Code changes a file, open it with your editor and read it. The editor does not replace the terminal: you will use both.
Claude Code is installed from the terminal. Use the method corresponding to your system.
On macOS or Linux, type:
BASH
curl -fsSL https://claude.ai/install.sh | bash
In Windows PowerShell, type:
POWERSHELL
irm https://claude.ai/install.ps1 | iex
The installer will download Claude Code and add it to your user account. This may take a few minutes.
When it finishes, close the terminal and open a new one. This allows the terminal to load the installation.
Check that the command exists:
On macOS or Linux:
BASH
claude --version
In Windows PowerShell:
POWERSHELL
claude --version
You should see a version number, for example:
CÓDIGO
2.1.0
The number may be different. If a version appears, the installation is ready.
Do not copy installation commands found on unknown websites. Use the instructions in the official Claude Code documentation:
CÓDIGO
https://docs.claude.com/
Claude Code needs to know which account it can use.
Type:
BASH
claude
The first time, Claude Code will display instructions for signing in. It will normally open a browser page. If it does not, it will show you an address that you can copy and paste into your browser.
Do not enter your password inside Claude Code. Only enter it on the official browser page.
When sign-in is complete, you will see the Claude Code interface and a place to type. If it does not appear, press Return or follow the message shown in the terminal.
To exit without changing any files, type:
CÓDIGO
/exit
You can also press Ctrl + C.
Do not run Claude Code in a folder containing important documents. Create a folder exclusively for this book.
On macOS or Linux:
BASH
mkdir claude-code-exercises cd claude-code-exercises
In Windows PowerShell:
POWERSHELL
mkdir claude-code-exercises cd claude-code-exercises
Check where you are.
On macOS or Linux:
BASH
pwd
In Windows PowerShell:
POWERSHELL
Get-Location
The displayed path should end in claude-code-exercises.
From now on, open Claude Code inside this folder:
BASH
claude
Claude Code will be able to read the files in this folder and, when you give it permission, modify them. It will not be able to work as expected if you open it somewhere else.
Inside the exercises folder, configure your name and email address for Git. You can use a name and email address that are not public:
BASH
git config --global user.name "Your Name" git config --global user.email "your-email@example.com"
Initialize the folder’s history:
BASH
git init
You should see a message similar to this:
CÓDIGO
Initialized empty Git repository
If the folder already contained a repository, Git will indicate that it has already been initialized. This is not a problem.
Before asking Claude Code to make important changes, you can save a checkpoint with:
BASH
git add . git commit -m "Initial checkpoint"
If Git says there is nothing to save because the folder is empty, that is normal too. You can save the first file created by an exercise later.
Each exercise follows this cycle:
For example, if Claude Code proposes modifying saludo.py, do not accept automatically. First check that the filename is the expected one. If it tries to delete a folder or touch files unrelated to the exercise, say no and review the request.
Claude Code may ask for permission before running a command. Read the entire command. Press y only if you recognize it and want to run it. If you are unsure, press n or cancel the operation.
It is not enough for Claude Code to say “done.” Check the result yourself.
Use three checks:
To see the Git status, type:
BASH
git status
To see the specific changes:
BASH
git diff
If git diff shows many lines you did not expect, stop and read them before continuing.
When everything is correct, save the result:
BASH
git add . git commit -m "Complete the exercise"
The message can be different, but it should briefly explain what you saved.
If a command displays an error, do not delete files or repeat many random commands. Do this:
If claude is not recognized, close the terminal, open another one, and try:
BASH
claude --version
If it still does not work, repeat the official installation for your system.
If Claude Code cannot sign in, check your Internet connection and confirm that your account has access to the service.
If Claude Code changes something you did not want changed, do not continue. Review the change with:
BASH
git diff
If you had not yet saved any important changes, you can undo modifications to files tracked by Git with:
BASH
git restore .
Use this command only after reviewing git diff, because it deletes unsaved changes.
If you receive an error you do not understand, you can ask Claude Code for an explanation without asking it to modify anything. Include the complete error and write clearly: “Only explain the error. Do not change any files.”
With this preparation, you can begin the first exercise with a separate folder, a verified installation, and a safe way to review every change.
You will learn how to start a session, find your way around the project, and request information without modifying files. You will practice basic dialogue with the agent before delegating tasks to it.
What it does: indicates the folder whose files Claude Code will be able to inspect. For example, if your project is in my_project, you should open the terminal in that folder before starting Claude Code.
How to write it:
In Windows PowerShell:
POWERSHELL
cd C:\Users\YourName\Documents\my_project
On macOS or Linux:
BASH
cd ~/Documents/my_project
To check that you are in the right place, type:
BASH
pwd
In Windows PowerShell, you can also use:
POWERSHELL
Get-Location
Worked example:
Suppose the project is in a folder called agenda inside Documents. You type:
POWERSHELL
cd C:\Users\Ana\Documents\agenda Get-Location
The terminal displays a path that ends in agenda. You are now in the correct working directory.
The typical mistake is typing a path that does not exist or leaving an incorrect space. If a message such as “the path cannot be found” appears, check the name of each folder and use the Tab key to complete names.
What it does: opens a Claude Code session associated with the directory you are currently in. Claude will be able to work with the files in that project, depending on the permissions you grant it.
How to write it:
After navigating to the project folder, type:
BASH
claude
Press Enter. The first time, you may be asked to sign in or authorize access. Follow the instructions that appear on the screen. When the process is complete, you will see an area where you can type messages.
Worked example:
POWERSHELL
cd C:\Users\Ana\Documents\agenda claude
Then type:
CÓDIGO
What working directory have you detected?
Claude may indicate that it is working in a path such as C:\Users\Ana\Documents\agenda. That path confirms that the session was started in the expected project.
The typical mistake is running claude from the wrong folder. If this happens, exit the session, return to the correct directory with cd, and run claude again.
What it does: context is the information Claude has available to answer you. When starting a session, the most important detail is the working directory. Claude should not assume that it knows all the files or every detail of the project: you can ask it to examine them.
How to write it: there is no mandatory special command. Write a normal question and mention what you want it to check.
Worked example:
CÓDIGO
Before doing anything, state your working directory and summarize what type of project seems to be there. Do not modify any files.
Claude may read some files to answer and explain that it found, for example, a Python program with several modules. The phrase “do not modify any files” makes it clear that you only want information.
The typical mistake is writing “look at the project” without specifying what you need. A specific request produces a more useful answer and lets you check whether Claude is looking at the right folder.
What it does: provides an organized list of the available contents: folders, important files, and, if requested, a brief description of each item.
How to write it: indicate the level of detail and ask Claude not to edit anything.
Worked example:
CÓDIGO
Make an inventory of the project. Group the items by folder, indicate each file's extension, and explain in one sentence what each one seems to be used for. Do not open unnecessary files or modify anything.
A useful response might include a list like this:
CÓDIGO
- main.py: entry point of the program. - utilities.py: helper functions. - data/: folder containing information files.
The inventory does not have to show every hidden or automatically generated file. If you need a complete list, say so explicitly: “also include hidden files and configuration files.”
The typical mistake is confusing an inventory with a complete explanation of the program. The inventory indicates what is there; to understand how a file works, you need to request a separate explanation.
What it does: locates where a function is created, even if it is in another file. A definition is the place where the function's code first appears, usually after a word such as def in Python.
How to write it: provide the exact name of the function and ask for the path and line numbers, if available.
Worked example:
CÓDIGO
Find the definition of the function calculate_total in all the files in the project. Give the file name, line number, and a few lines of context. Do not modify anything.
Claude may respond:
CÓDIGO
The calculate_total function is defined in billing.py, on line 18. It is also used in main.py, on line 42.
The definition and the use are not the same thing: the definition creates the function; the use calls it to execute it.
The typical mistake is typing the name with a different character, such as calculate-total instead of calculate_total. Copy the name exactly as it appears in the code and clarify whether you are looking for the definition or the calls.
What it does: helps you understand the purpose of a file and the general order of its operations without requesting code changes.
How to write it: mention the file and divide the explanation into sections: purpose, input data, main steps, functions used, and result.
Worked example:
CÓDIGO
Explain the main.py file without modifying it. Organize the answer into: 1. purpose of the file; 2. data it receives; 3. steps it performs; 4. functions it calls; 5. result it produces. Use simple words and mention the names of the important functions.
Claude should describe the flow: for example, read a piece of data, call a calculation function, display the result, and finish. If it does not understand part of it, it should say so instead of inventing an explanation.
The typical mistake is asking “explain this file” without specifying the level of detail. If the answer is too general, ask again about a specific section or function.
What it does: distinguishes between asking for an explanation and asking Claude to modify files. This difference is essential: an informational question should produce text; a change request may propose or make edits and ask for confirmation.
How to write it: use expressions such as “explain,” “state,” or “why?” when asking a question. Use “modify,” “create,” “delete,” or “reorganize” only when you want to request an action.
Worked example:
Informational question:
CÓDIGO
Why does the validate_user function return False when the password is empty? Explain the condition and do not change the code.
The response should explain the condition. It should not include an edit proposal applied to the file.
Change request:
CÓDIGO
Modify validate_user so that it also checks the minimum password length. Before editing, explain which files you would change.
Here Claude can analyze the task and ask for authorization before writing. Always read the change summary before accepting it.
The typical mistake is saying “fix this” when you only wanted to know what is happening. If you do not want any changes, always write “do not modify any files.”
What it does: closes the current conversation without deleting the project files.
How to write it: inside Claude Code, type:
CÓDIGO
/exit
and press Enter. You can also press Ctrl+D in a compatible terminal. If Claude is performing an operation, wait for it to finish or press Ctrl+C to interrupt it before exiting.
Worked example:
CÓDIGO
/exit
Claude Code returns to the normal terminal prompt. Your files remain in the folder; exiting does not automatically undo or save changes.
The typical mistake is closing the window and thinking that the project has been deleted. The session and the files are separate things: closing the session only ends the conversation.
What it does: continues the most recent Claude Code conversation in the current directory.
How to write it: from the terminal, return to the project folder and run:
BASH
claude --continue
You can also use the short form:
BASH
claude -c
Worked example:
POWERSHELL
cd C:\Users\Ana\Documents\agenda claude --continue
When the session opens, type:
CÓDIGO
Continue from the previous conversation and remind me which file we were analyzing. Do not make any changes yet.
If it cannot find a conversation to continue, start a new session with claude and briefly explain the pending work.
The typical mistake is using claude --continue from another folder. First navigate to the same project; otherwise, Claude may not find the expected session.
claude./exit to exit and claude --continue to resume.Exercises 1 through 6.
Level: Easy
You have a working folder called practica-claude on your computer. Open a terminal, go to that folder, and check the current directory. Then start Claude Code from there. When the session appears, identify which folder it considers its working context and confirm that you have not yet asked it to modify any files. You do not need to create files or make any changes to the project. The response should show the commands used and a brief description of what you observe when the session begins.
Example
$ cd practica-claude
$ pwd
/home/ana/practica-claude
$ claude
Claude Code is ready.
Working directory: /home/ana/practica-claude
> _
Result: Claude Code has started in practica-claude, and no changes have been requested yet.
HINT
First go to the folder and check the path before starting Claude Code. The folder from which you run claude determines the initial context.
Level: Easy
In the practica-claude folder, there is a small project with these elements: calculadora.py, notas.txt, and the datos folder, which contains ejemplo.txt. Start Claude Code from that folder and ask it for an inventory of the project. The request should ask for a brief description of the available files and folders, without asking it to open, change, create, or delete anything. Check that the response distinguishes the files from the folder and mentions the three elements in the main directory.
Example
> Make a brief inventory of this project. Indicate which files and folders there are, including the contents of the folders. Do not modify any files.
Claude Code:
calculadora.py: Python file.notas.txt: text file.datos/: folder containing ejemplo.txt.No changes have been made.
HINT
Formulate an informational request and clearly limit its scope: you want to learn about the structure, not modify it. Claude Code can review the available content from its working directory.
Level: Easy
The project contains three Python files: principal.py, usuarios.py, and informes.py. The function you need to use is called calcular_total. Start Claude Code from the project folder and ask it to locate the definition of that function. It should indicate which file it is defined in and show the line or snippet that makes it identifiable. Do not ask it to change it or use it from another file. The expected result is a specific location, not a general explanation of the project.
Example
> Locate the definition of the calcular_total function. Indicate the file and show the definition line. Do not modify anything.
Claude Code:
The calcular_total function is defined in informes.py:
PYTHON
def calcular_total precios:
No definition with that name appears in principal.py or usuarios.py.
No changes were made.
HINT
Include the exact name of the function and explicitly ask for its definition. Clarify that you only want to locate it to prevent Claude Code from proposing modifications.
Level: Easy
The project contains the file saludo.py. You want to understand it before touching it. Start Claude Code from the project folder and ask it for a structured explanation of that file. The explanation should cover its purpose, the data it receives, the main operations, and the result it produces. State explicitly that you only want to read and explain the file, without editing it or creating any other files. Then review the response and confirm that Claude Code has provided information about the program flow.
Example
> Explain saludo.py in a structured way: indicate its purpose, what data it receives, what steps it performs, and what result it produces. I only want an explanation; do not edit or create any files.
Claude Code:
Purpose: generate a greeting for a person.
Data it receives: a name.
Flow: the crear_saludo function receives the name, constructs the greeting text, and returns it.
Result: a string such as Hola, Ana.
The file has not been modified.
HINT
Ask for an explanation, not an improvement. You can list the aspects you want to learn about so that the response has a clear structure.
Level: Easy
In calculadora.py, there is a function called es_par(numero) that returns a Boolean value. You want to resolve a specific question: find out what the function returns when it receives the number 7. Start Claude Code from the project directory and ask that question as an informational query. Do not ask it to make changes, add a test, or modify the file. Check that the response explains the result and that the file remains unchanged. Distinguish between asking for information and giving an editing command.
Example
> In calculadora.py, what does es_par(7) return, and why? I only want an informational answer; do not modify any files.
Claude Code:
es_par(7) returns False because 7 is not evenly divisible by 2.
The query was answered without modifying calculadora.py.
HINT
Ask about the behavior of a specific input and make it clear that you are not authorizing any modifications. A question about the code can be answered by reading its definition.
Level: Easy
Open a terminal and navigate to the folder of a project containing at least README.md and saludos.py. Start Claude Code from that folder and ask it to list the project files. Then close the session without modifying any files. Run Claude Code again from the same folder using the option that allows you to continue the previous session, and ask for the file list again. Check that you can continue working on the same project and that the second session recognizes the previous context. Do not edit or create files in this exercise.
Example
CÓDIGO
$ cd practica-claude $ pwd /home/ana/practica-claude $ claude > List the project files without modifying anything. I found: - README.md - saludos.py > /exit Session closed. $ claude --continue > Repeat the inventory of files we saw earlier, without modifying anything. The project contains: - README.md - saludos.py
HINT
The session is closed from Claude Code, but to resume it, you must be back in the project folder. Use the continuation option from the terminal.
Want to know what happens next? Get the full book:
Prices checked in the stores on 4 Nov 2026; they may change.
Back to the book page