Skip to content

Session 01

OpenCode CLI & Context Engineering

Introduction to the OpenCode CLI agent and the basics of context engineering.

01. Install Node.js

Node.js is a JavaScript runtime that lets you run JS outside the browser. You need it for npm, build tools, and running OpenCode.

  1. Go to nodejs.org
  2. Download the LTS version
  3. Run the installer — accept all defaults, no changes needed
  4. Restart your terminal after installation

Verify it worked:

$ node --version
v22.x.x
$ npm --version
10.x.x

If you see version numbers, Node.js is installed correctly.

02. Install OpenCode

OpenCode is an open-source AI coding agent that lives in your terminal. It reads your codebase and helps you write, debug, and understand code using AI.

$ curl -fsSL https://opencode.ai/install | bash

Option B — Install via npm (works on all OS)

$ npm i -g opencode-ai

Option C — Install via Homebrew (Mac only)

$ brew install anomalyco/tap/opencode

Verify it worked:

$ opencode --version

If it prints a version, you’re good to go.

03. Start Using OpenCode

Navigate to any project folder and launch OpenCode. It will read your files and understand your codebase automatically.

Linux / Mac:

$ mkdir my-project && cd my-project
$ opencode

Windows (PowerShell):

$ mkdir my-project; cd my-project
$ opencode

Once OpenCode is running, you can talk to it naturally. Here are some prompts to try:

Create a simple HTML page with a form that has name and email fields

Add validation to check that the email is valid before submitting

Style this page with a dark theme and centered layout

04. Context Engineering

The quality of AI output depends entirely on the quality of your input. Context engineering is the skill of giving AI the right information so it can help you effectively.

Be specific about the problem

Bad: “fix this bug”
Good: “There’s a TypeError on line 42 when the user submits the form — the email field is undefined because the input name attribute doesn’t match the destructured variable”

Show the surrounding code

AI works better when it can see the function calling the broken code, not just the broken line. Include the parent function, imports, and any related types.

State your constraints

Tell the AI what you can’t change: “I can’t modify the database schema”, “this must work with React 18”, “the API endpoint is fixed”. This prevents suggestions that don’t fit your situation.

Ask “why” not just “how”

Don’t just copy the generated code. Ask OpenCode to explain why it chose that approach. This is how you actually learn, not just produce output.

05. Deploy to Cloudflare Pages

Once your project works locally, deploy it for free on Cloudflare Pages. You get a live URL, HTTPS, and a global CDN — all on the free tier.

Method A — Direct Upload (quickest)

No GitHub needed. Just build your project and drag the folder to Cloudflare.

  1. Build your project: npm run build
  2. Find the output folder — usually called dist or build
  3. Go to dash.cloudflare.com
  4. Navigate to Workers & Pages → Create application → Pages
  5. Click Upload assets
  6. Name your project and click Create project
  7. Drag your dist folder into the upload area
  8. Click Deploy — done! You get a your-project.pages.dev URL

Every time you make changes, just run npm run build again and re-upload the dist folder.

Method B — Git Integration (auto-deploy)

Push to GitHub and Cloudflare auto-deploys on every commit. More setup, but better long-term.

Push to GitHub first:

$ git init
$ git add .
$ git commit -m "first commit"
$ git remote add origin https://github.com/YOU/repo.git
$ git push -u origin main

Then on Cloudflare:

  1. Go to dash.cloudflare.com
  2. Navigate to Workers & Pages → Create application → Pages → Connect to Git
  3. Select your GitHub repo
  4. Set build command: npm run build, output directory: dist
  5. Click Save and Deploy

Now every git push automatically redeploys your site.

Summary

  1. Installed Node.js — the JavaScript runtime
  2. Installed OpenCode — your AI coding agent
  3. Started using OpenCode — running it in your project
  4. Learned context engineering — how to talk to AI effectively
  5. Deployed a project to Cloudflare Pages