---
title: "Chapter 01: Environment Setup"
description: "Understand why mise/bun/OpenRouter, then install and smoke-test each piece before scaffolding the project."
type: lesson
order: 1
chapter: "01-setup"
---

# Chapter 01: Environment Setup

## Objective

Set up a **reproducible** local environment: `mise` (tool versions), `bun` (TypeScript runtime), and an OpenRouter API key so later chapters can call LLMs without reinventing setup.

Your tutor walks this **gate by gate** — one install, one verify — not one mega paste.

---

## Concept: Why this stack

| Piece | Job |
|--------|-----|
| **mise** | Pins runtimes/tools so “works on my machine” is a config file, not luck |
| **bun** | Fast TS runtime/package runner for the agent project |
| **OpenRouter** | One API key → many models; swap models with an env var |

You are not installing “random tools.” You are making the rest of the course **repeatable**.

---

## Concept check

**Q1.** Why pin tools with `mise` instead of “install whatever Node is on the laptop”?

**Q2.** What problem does OpenRouter solve compared to separate keys for every model vendor?

<details>
<summary>Concept answer key — attempt first</summary>

## Answer key (concept)

### Q1

**Model answer:** Reproducible versions across machines/sessions; the project declares what it needs.

**Pass criteria:** reproducibility / version pin

### Q2

**Model answer:** One gateway/key; easy model swaps without re-plumbing auth.

**Pass criteria:** single key / multi-model routing

</details>

---

## Gate: Install mise

```bash
curl https://mise.run | sh
```

Restart the terminal if needed. **Verify:**

```bash
mise --version
```

Stop if this fails.

---

## Gate: Install bun via mise

```bash
mise use bun
bun --version
```

**Pass:** version string prints.

---

## Gate: OpenRouter key + project dir

1. Create a key at [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys)  
2. Create the project:

```bash
mkdir weekend-coding-agent
cd weekend-coding-agent
```

3. Env + gitignore:

```bash
echo 'OPENROUTER_API_KEY=sk-or-v1-your-key-here' > .env
echo 'AGENT_MODEL=google/gemini-3-pro-preview' >> .env
echo '.env' >> .gitignore
```

**Never commit `.env`.**

Optional model: `anthropic/claude-opus-4.5`.

4. Lock tools:

```toml
# mise.toml
[tools]
bun = "latest"
```

**Pass:** `ls` shows `.env`, `.gitignore`, `mise.toml`; tutor confirms you did **not** paste the real key into chat.

---

## What We Have Now

```text
weekend-coding-agent/
├── .env              # OPENROUTER_API_KEY and AGENT_MODEL
├── .gitignore        # includes .env
└── mise.toml         # bun version locked
```

Later chapters build `src/` step by step. Do not jump ahead until this gate is green.

---

## Check your understanding

**Q3.** What is the smoke test for “bun is ready” in this lesson?

**Q4.** Why does the lesson put secrets in `.env` and force `.gitignore` before any agent code?

<details>
<summary>Answer key — attempt every question first</summary>

## Answer key

### Q3

**Model answer:** `bun --version` (after mise use) succeeds.

**Pass criteria:** version command

### Q4

**Model answer:** Avoid committing API keys; separate config from code from the start.

**Pass criteria:** secrets hygiene

</details>

---

[← Part 1 Index](/build-ai-coding-agent/01-setup/) · [Next: Chapter 02 →](/build-ai-coding-agent/01-setup/02-bootstrap/)
