Loading lesson...
Loading lesson...
cd, ls, and pwd commands with confidencepip and npm from the command lineModule 2 ended with the agent loop: perceive, think, act, observe. Before you can build anything that runs that loop, you need fluency with the environment where agent code lives. This module gives you exactly the command-line skills required to install, configure, and run agent frameworks.
With the learning outcomes established, this module begins by examining the terminal and why you need it in depth.
A terminal (also called a shell or command line) is a text-based interface to your computer's operating system. On macOS and Linux this is usually bash or zsh; on Windows it is PowerShell or Command Prompt. You type commands and the operating system executes them. The terminal is faster than clicking through menus, scriptable for automation, and often the only interface available on remote servers.
Most AI agent frameworks, from LangGraph to CrewAI to the Anthropic SDK, are installed and run from the command line. Python and Node.js are managed from the command line. API (Application Programming Interface) keys are set as environment variables in the terminal. If you want to build AI agents, the command line is non-negotiable. This module covers exactly what you need and nothing more.
Open the terminal on your system: on macOS, use Spotlight (Cmd + Space) and type "Terminal." On Windows, search for "PowerShell." On Linux, the keyboard shortcut varies by distribution, but Ctrl + Alt + T works on most.
“The POSIX standard defines a shell command language to provide a consistent interface across conforming systems. Portable applications should use only the features defined herein.”
The Open Group Base Specifications Issue 7, 2018 edition - Section 2, Shell Command Language
POSIX (Portable Operating System Interface) standardises shell commands so that scripts written on macOS work on Linux servers without modification. The commands in this module: cd, ls, pwd, mkdir, rm, export, and echo, are all POSIX-compliant and will work on any system you are likely to deploy to.
Your first four commands cover the majority of daily navigation. pwdprints your current working directory, the full path to where you are in the file system. ls lists the files and directories at your current location.ls -la adds hidden files (those beginning with a dot, such as.env and .gitignore) and file permissions. clearclears the screen so you can see your last output without scrolling.
With an understanding of the terminal and why you need it in place, the discussion can now turn to navigating and managing files, which builds directly on these foundations.
cd (change directory) moves you to a different location. cd Desktopmoves into a folder called Desktop inside your current location. cd ..moves up one level to the parent directory. cd ~ returns to your home directory from anywhere. cd /absolute/path moves to an exact location regardless of where you start.
mkdir my-agent creates a new directory called my-agent. touch main.pycreates an empty file called main.py. These two commands together are how you start every new project: create a directory, move into it, and create your first files.
rm removes files permanently. There is no recycle bin on the command line.rm old-file.txt deletes a file; rm -rf old-directory/ deletes a directory and everything inside it. The -r flag means recursive (apply to all contents) and -f means force (do not ask for confirmation). Double-check the path before running this command. Many engineers have lost important work this way.
Common misconception
“rm -rf is fine to run as long as you are in the right directory.”
Being in the right directory is necessary but not sufficient. rm -rf deletes the directory path you specify, which may be relative or absolute. Running rm -rf . deletes your entire current directory. Running rm -rf / (on systems without protection) would delete the entire file system. Always verify the exact path you are targeting before executing any rm command. A safer habit is to print the path first using echo and confirm it is what you expect.
With an understanding of navigating and managing files in place, the discussion can now turn to environment variables and the .env pattern, which builds directly on these foundations.
An environment variable is a named value stored in the operating system's environment, accessible to any process running in that session. Environment variables configure applications without hardcoding sensitive values like API keys into source code. export GREETING="hello" sets a variable for the current terminal session. echo $GREETING prints its value. The variable disappears when you close the terminal.
The PATH variable is a colon-separated list of directories where the operating system searches for executable programmes. When you type python, the OS searches each directory in PATH in order until it finds an executable named python. Running echo $PATH shows you the current list. You can prepend a new directory with export PATH="/opt/my-tool/bin:$PATH". To make this permanent, add that line to ~/.zshrc (zsh) or ~/.bashrc (bash).
Hardcoding API keys in source code is a serious security risk. The standard practice is to store secrets in a .env file at the project root. This file contains key-value pairs: ANTHROPIC_API_KEY=sk-ant-xxxx. The file must be added to .gitignore immediately. In Python, the python-dotenvlibrary reads this file into environment variables at runtime with a single call toload_dotenv().
The Uber incident described above happened because a developer skipped this step. The two commands that prevent the same mistake from happening to you are:touch .env to create the file, and echo ".env" >> .gitignoreto exclude it from version control. Run both before writing any credentials.
“Secrets that are stored in source code or checked into version control are exposed to anyone who can access the repository, including future employees, contractors, and, in the case of public repositories, the entire internet.”
OWASP Secrets Management Cheat Sheet - cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
OWASP (Open Web Application Security Project) publishes widely adopted security guidance. The Secrets Management Cheat Sheet is the industry reference for credential handling in development environments. The .env pattern this module teaches is the first control listed in that cheat sheet.
With an understanding of environment variables and the .env pattern in place, the discussion can now turn to package managers: pip and npm, which builds directly on these foundations.
pip is the package installer for Python. pip install anthropicdownloads and installs the Anthropic SDK from the Python Package Index (PyPI).pip install -r requirements.txt installs all packages listed in a requirements file, which is how you reproduce an environment on a new machine.pip list shows what is installed; pip show anthropicshows version and dependency information for a specific package.
npm is the package manager for Node.js. npm init -ycreates a package.json file that describes your project and its dependencies. npm install @anthropic-ai/sdk downloads and installs the Anthropic SDK for Node.js and records it in package.json. npm install(with no package name) installs all dependencies listed in package.json, which is how you set up an existing project after cloning it.
Installing Python packages globally, meaning without a virtual environment, is a common mistake that causes dependency conflicts between projects. The next module covers virtual environments in detail. For now, be aware that the pip commands above should always be run inside an activated virtual environment.
Common misconception
“pip install just downloads a package. It does not affect anything else.”
pip install modifies the Python environment it targets. If you run it without an active virtual environment, it modifies your system Python or your user Python installation. This can break other projects that depend on different versions of the same package. The fix is always to create and activate a virtual environment (covered in Module 4) before running any pip install command.
With an understanding of package managers: pip and npm in place, the discussion can now turn to reading error messages, which builds directly on these foundations.
The terminal displays two types of output: standard output (stdout) and standard error (stderr). Both appear in the terminal by default. Error messages in Python are called tracebacks, and they read from the bottom up: the last line states the error type and cause; the lines above show the call stack leading to that error.
A traceback that ends with anthropic.AuthenticationError: invalid x-api-keytells you exactly what happened: the API key is wrong or missing. The lines above show where in the code the error occurred and which library function raised it. Start at the bottom, identify the error type, read the message, then look at the file and line number in your own code (not in the library code) to find where to fix it.
ModuleNotFoundError: No module named 'anthropic' means the package is not installed in the current Python environment. The fix is pip install anthropic, run inside an activated virtual environment. This is the most common error beginners encounter, and understanding its cause prevents hours of confusion.
The Open Group Base Specifications Issue 7, 2018 edition
Section 2, Shell Command Language (POSIX)
Authoritative standard for shell command behaviour across POSIX-compliant systems. Quoted in Section 3.1 to establish that the commands taught here are portable across macOS, Linux, and any server you are likely to deploy to.
OWASP Secrets Management Cheat Sheet
cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
Industry standard guidance on handling API keys and other secrets in development and production. Quoted in Section 3.3 to establish the .env pattern as a recognised security control rather than informal best practice.
pip.pypa.io/en/stable/user_guide/
Official documentation for the Python package installer. Referenced in Section 3.4 as the authoritative reference for pip install, pip list, pip show, and requirements file management.
docs.npmjs.com
Official reference for the Node.js package manager. Referenced in Section 3.4 for npm init, npm install, and package.json management.
github.com/theskumar/python-dotenv
The standard library for loading .env files in Python projects. Referenced in Section 3.3 as the implementation of the .env pattern in Python agent code.
You can now navigate the filesystem, install packages with pip and npm, and store secrets in environment variables instead of source code. The next module puts these skills to work: you will configure a local Python environment, install the Anthropic SDK, and send your first API call to Claude - the foundation every agent framework builds on.
Module 3 of 25 in Foundations