# How to Run a Specific Lesson's Code from the Command Line in AI Engineering From Scratch

> Learn to run specific AI Engineering From Scratch lesson code from the command line. Discover the simple commands to execute Python or Rust code directly.

- Repository: [Rohit Ghumare/ai-engineering-from-scratch](https://github.com/rohitg00/ai-engineering-from-scratch)
- Tags: how-to-guide
- Published: 2026-06-17

---

**Navigate to the lesson directory under `phases/<phase-slug>/<lesson-slug>/` and execute the run command documented in [`code/README.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/code/README.md), such as `python3 code/main.py` for Python implementations or `cargo run` for Rust.**

The *AI Engineering From Scratch* repository by rohitg00 organizes hands-on curriculum content into structured phase directories. Each lesson includes a self-contained implementation in the `code/` subdirectory that you can execute directly from the terminal to validate concepts and experiment with modifications.

## Locate the Lesson Directory

Every lesson resides at `phases/<phase-slug>/<lesson-slug>/` within the repository root. For example, the "Gradient Checkpointing" lesson lives under `phases/10-llms-from-scratch/34-gradient-checkpointing/`.

Navigate to the lesson root before executing any commands:

```bash
cd phases/10-llms-from-scratch/34-gradient-checkpointing

```

Inside this directory, the `code/` folder contains the implementation files. The [`code/README.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/code/README.md) file documents the exact command required to run that specific lesson.

## Install Required Dependencies

Most lessons are self-contained, but some require third-party packages. The [`code/README.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/code/README.md) specifies the exact installation command for the lesson's programming language.

**Python** lessons typically use:

```bash
pip install -r requirements.txt

```

**TypeScript** lessons require:

```bash
npm install

```

**Rust** lessons handle dependencies automatically through [`Cargo.toml`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/Cargo.toml) when you run `cargo build`, but ensure you have the Rust toolchain installed.

## Execute the Lesson Code

The [`code/README.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/code/README.md) in each lesson specifies the precise command to launch the implementation. The convention varies by language:

- **Python**: `python3 code/main.py`
- **TypeScript**: `npm start` or `npx ts-node code/main.ts`
- **Rust**: `cargo run --manifest-path code/Cargo.toml`
- **Julia**: `julia code/main.jl`

For example, to run the Gradient Checkpointing lesson according to the source code:

```bash
cd phases/10-llms-from-scratch/34-gradient-checkpointing
python3 code/main.py

```

This prints the equivalence check and cost table, then exits with status `0` on success.

For the Terminal-Native Coding Agent TypeScript lesson:

```bash
cd phases/19-capstone-projects/01-terminal-native-coding-agent
npm install
npm start

```

To launch the interactive REPL mode instead:

```bash
npm start -- --repl

```

For Rust implementations like the Pre-training Mini-GPT lesson:

```bash
cd phases/10-llms-from-scratch/04-pre-training-mini-gpt
cargo run --manifest-path code/Cargo.toml

```

## Run the Test Suite

Each lesson includes a `code/tests/` directory containing unit tests. Execute the language-specific test runner to verify the implementation's correctness.

**Python**:

```bash
python3 -m unittest discover code/tests -v

```

**TypeScript**:

```bash
npm test

```

**Rust**:

```bash
cargo test --manifest-path code/Cargo.toml

```

**Julia**:

```bash
julia --project=code -e 'using Pkg; Pkg.test()'

```

All lessons exit with status `0` when tests pass. A non-zero exit status indicates a failure in the lesson's self-test suite.

## Summary

- Each lesson in *AI Engineering From Scratch* follows the path `phases/<phase>/<lesson>/` with implementation files in the `code/` subdirectory.
- The [`code/README.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/code/README.md) file contains the exact terminal command required to run that lesson's code.
- **Python** lessons execute via `python3 code/main.py`, **TypeScript** via `npm start`, **Rust** via `cargo run --manifest-path code/Cargo.toml`, and **Julia** via `julia code/main.jl`.
- Install dependencies using `pip install -r requirements.txt` or `npm install` as documented in the lesson's README before running.
- Run the test suite using language-specific commands like `python3 -m unittest discover code/tests` or `cargo test` to verify correctness.

## Frequently Asked Questions

### How do I find the correct command to run a specific lesson?

Check the [`code/README.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/code/README.md) file inside the lesson directory. This file explicitly documents the run command, such as `python3 code/main.py` for Python lessons or `npm start` for Node.js projects, along with any required dependencies and flags.

### What should I do if a lesson requires external packages?

Install the dependencies listed in the lesson's [`code/README.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/code/README.md). Python lessons typically provide a [`requirements.txt`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/requirements.txt) file for `pip install`, while TypeScript lessons require running `npm install` to fetch packages like `hono` or `zod` before executing `npm start`.

### How do I verify that a lesson executed correctly?

All lessons exit with status `0` on successful completion. The output will display the lesson's results, such as benchmark tables or equivalence checks. For additional verification, run the unit tests in `code/tests/` using the appropriate language test runner.

### Can I run lessons interactively or modify the code?

Yes. After navigating to the lesson directory, you can edit `code/main.<ext>` directly. For interactive sessions, some lessons support specific flags; for example, the Terminal-Native Coding Agent supports `npm start -- --repl` to launch an interactive REPL instead of the scripted demo.