Codex & AI Coding Agents - Learn Agentic Coding

freeCodeCamp.org

Summary

Tom Chant leads a practical course on agentic coding using Scrimba's built-in agent and the OpenAI Codex extension in VS Code. Through interactive exercises on mock web applications, he demonstrates how to reduce ambiguity with task-context-output prompts, imitate model functions via code comments, and persist architectural rules in global, project, and folder-scoped AGENTS.md files. He also covers architectural planning in Plan Mode, building reusable team skills, protecting legacy logic with Vitest characterization tests, and enforcing human business policies through test-driven development.

The second half of the course addresses operational safety and tool extensibility. Chant explains how to keep Git commits small for human review, prevent agents from leaking .env secrets into tracked files or logs, manage 1-million-token context windows, configure sandbox permissions in config.toml, and connect external component registries like shadcn via the Model Context Protocol.

How time-sensitive the topic is: Evergreen

By the numbers

  • 26 seconds: Time taken by the Scrimba coding agent to generate and style a new mineral water sales section from a basic prompt. (Mentioned at 7:27)
  • 29 directories: Number of directories alongside 66 files mapped by the file-tree skill in the Stylist e-commerce project. (Mentioned at 38:54)
  • 64 seconds: Time (1 minute and 4 seconds) taken by the custom /stylist-dev skill to diagnose and fix the sqlite3 version mismatch. (Mentioned at 50:21)
  • 35 tests: Number of Vitest characterization tests that passed to confirm existing scheduling behavior was preserved after refactoring scheduler.js. (Mentioned at 59:53)
  • 51 tests: Total number of passing Vitest checks after implementing the 15% discount code feature via test-driven development. (Mentioned at 1:09:39)
  • 1 million tokens: Approximate context window capacity that decent AI models can handle at the time of recording. (Mentioned at 1:27:43)
  • 61 UI components: Number of available components returned from the shadcn registry via its MCP server in 26 seconds. (Mentioned at 1:48:36)
  • 6 minutes: Approximate time Codex took to refactor the React Kanban board UI using components from the shadcn MCP server. (Mentioned at 1:49:18)

Questions this video answers

Why shouldn't you ask an AI coding agent to write feature code and tests in the same prompt?

When asked to write code and tests simultaneously, an agent will often write tests designed merely to pass the code it just generated, or silently make business policy decisions like how to round fractional pennies. Creating a failing spec test first lets the human verify the exact business rules before the agent writes implementation code.

Tom Chant, 1:01:08 to 1:11:07

From this keypoint: Test-Driven Development Stops AI Policy Decisions

What does an AGENTS.md file do in agentic coding?

An AGENTS.md file stores persistent project specifications such as tech stack, folder structure, and coding conventions like BEM. It is automatically sent and prioritized with every prompt, ensuring context survives truncated conversations and is shared with teammates via Git.

Tom Chant, 19:46 to 26:45

From this keypoint: Persistent AGENTS.md Files Solve Context Loss

How do you safely refactor messy legacy code using an AI coding agent?

Before refactoring tangled code, have the agent write passing characterization tests that lock in the feature's existing inputs and outputs. By adding a rule in AGENTS.md to run those tests after every edit to the file, you can immediately catch any accidental behavior changes.

Tom Chant, 50:38 to 1:01:01

From this keypoint: Characterization Tests Lock In Legacy Behavior

How can an AI coding agent leak secrets even when .env is in .gitignore?

Coding agents have read access to the workspace .env file by default and may hardcode API keys into tracked source files or output them via console.log to make the app work. Developers must avoid pasting secrets in chat, cap API token spending limits, ignore all environment files like .env.local, and manually review diffs before committing.

Tom Chant, 1:16:02 to 1:22:52

From this keypoint: Protecting Secrets From Agent Hardcoding and Logs

How do you structure prompts so AI coding agents write DRY, maintainable code?

Agents naturally prefer adding duplicate code over refactoring existing logic when given vague UI prompts. Structuring prompts into Task, Context, and Output—or pointing the agent to a model function via a TODO(AI) comment—reduces ambiguity and enforces shared logic.

Tom Chant, 9:39 to 15:07

From this keypoint: Task-Context-Output Prompts Prevent Repetitive Code

When should you use Plan Mode in an AI coding agent?

Plan Mode is best for complex or ambiguous features where multiple architectural choices exist, because it forces the agent to propose file changes and storage decisions without editing code. This allows developers to review assumptions and add edge-case handling, such as skipping deleted articles in localStorage, prior to implementation.

Tom Chant, 28:50 to 36:34

From this keypoint: Plan Mode Resolves Edge Cases Before Coding

What are custom skills in Codex and how do they differ from standard prompts?

Skills are portable folders containing a SKILL.md instruction file and optional scripts that encode team-specific house styles, repo quirks, and pinned dependency rules an AI model cannot intuit. Unlike chat prompts that get lost over time, skills live in the file system and can be invoked anytime with a slash or dollar-sign command.

Tom Chant, 36:39 to 44:57

From this keypoint: Custom Skills Encode Team Standards and House Style

What happens when an AI coding agent's context window gets full?

Before hitting the model's hard token limit, the agent automatically reduces context size through either summary compaction or truncation of earlier messages. Because both processes are lossy and can cause erratic behavior, developers should start a fresh session for each distinct task.

Tom Chant, 1:22:59 to 1:34:20

From this keypoint: Setting Up Codex in VS Code and Managing Context

How do you change the default AI model and permission settings in Codex?

You can customize approval policies, workspace sandbox modes, and the default model by editing the config.toml file in your project's .codex folder or your home directory's global .codex folder. After saving changes and reloading the VS Code window, Codex applies the new defaults unless overridden by organization policy or untrusted repo settings.

Tom Chant, 1:34:25 to 1:43:48

From this keypoint: Controlling Permissions and Models via config.toml

How does the Model Context Protocol (MCP) help AI coding agents build better UIs?

MCP provides a standardized interface for agents to query external servers and tool registries in a loop. By registering the shadcn MCP server in config.toml, Codex can directly inspect 61 ready-made React components and refactor an inconsistent UI with uniform components.

Tom Chant, 1:43:55 to 1:50:42

From this keypoint: Connecting External Tools with MCP and shadcn

Credible AI™ signals

Confidence: Hands-On Technical Instruction. Tom Chant demonstrates every concept live inside Scrimba and VS Code, showing real agent outputs, failing tests, and configuration files rather than relying on abstract claims.

Bias: Pragmatic Human-In-Loop Focus. While promoting Scrimba's interactive platform and focusing primarily on OpenAI's Codex, the instruction consistently emphasizes human oversight, testing discipline, and security over blind AI automation.

Originality (82%): Bespoke Interactive Exercises. The course uses custom mock applications like a dental scheduler and an e-commerce store to expose subtle agentic pitfalls such as rounding policy bugs and duplicated event handlers.

Depth (84%): Systematic Workflow Mechanics. Rather than stopping at basic prompting, the curriculum examines context window truncation, file scope hierarchies, characterization testing, and TOML configuration.

Key points (14)

  • Short (24 min): key points 4, 9 and 11
  • Medium (47 min): key points 1, 4, 6, 8, 9 and 11
  • Relaxed (1h 42min): all 14 key points

1. Tom Chant Defines Agentic Coding and Human Oversight

Timestamp: 00:00:42 to 00:04:56 (4 min)

Speaker: Tom Chant

Agentic coding places an autonomous AI directly inside the editor to read files, run commands, execute tests, and iterate on broken code until a task succeeds. Because agents can still expose secrets or write messy code, human developers remain essential from ideation to deployment. While the course focuses on OpenAI's Codex inside an IDE, its core principles apply across tools like Claude Code, Cursor, and Windsurf.

Impact: High. Why it matters: Frames AI coding agents as powerful execution loops that elevate rather than replace the need for human architectural judgment and security review.

“And as we go, you're going to see that the human developer is still the key cog in the machine because from ideation through development to deployment, human input is not just desirable, it's a necessity.”

In the video: Tom Chant, at 2:44

2. Task-Context-Output Prompts Prevent Repetitive Code

Timestamp: 00:09:39 to 00:15:07 (5 min)

Speaker: Tom Chant

Simply asking an agent for a UI feature often produces repetitive, non-DRY code because agents prefer adding new logic over refactoring existing functions. Structuring prompts around task, context, and expected output reduces ambiguity and guides the agent to share event handlers. Prompting explicitly for code quality alongside UI outcomes yields cleaner, more maintainable JavaScript.

Impact: High. Why it matters: Gives developers a repeatable three-part prompting framework that stops AI agents from bloating codebases with copy-pasted logic.

“The agent would rather add more code than refactor existing code and that can lead to bloated inelegant code which is ultimately harder to maintain.”

In the video: Tom Chant, at 11:36

3. Comment Prompts and Model Functions Guide Style

Timestamp: 00:15:14 to 00:19:41 (4 min)

Speaker: Tom Chant

Because coding agents excel at imitation over abstract interpretation, pointing them to a model function in the file is often faster than explaining syntax rules. Placing a comment like TODO(AI) above a target function lets the agent replicate async/await and error-handling patterns from an adjacent example in 20 seconds. Using local comments and concrete code examples reduces ambiguity and prevents overbuilding.

Impact: Medium. Why it matters: Shows how in-file comments and reference functions let developers standardize syntax across a codebase with minimal typing.

“Codeex is actually better at imitation than interpretation. So if you care about the style, structure or patterns of your code, it might be a good idea to show rather than tell.”

In the video: Tom Chant, at 15:14

4. Persistent AGENTS.md Files Solve Context Loss

Timestamp: 00:19:46 to 00:26:45 (7 min)

Speaker: Tom Chant

Relying solely on chat history creates two major problems: teammates do not receive prior prompt history when sharing a repo, and long conversations eventually get truncated when they exceed model limits. Running the /init slash command generates an AGENTS.md file in the project root that records the tech stack, structure, and coding conventions like BEM. Because the agent attaches and prioritizes AGENTS.md on every prompt, keeping it updated ensures continuity across collaborators and sessions.

Impact: High. Why it matters: Establishes AGENTS.md as the foundational project memory file that keeps multi-developer teams and long AI sessions aligned.

“So now this file gets sent off with every prompt and it's given special priority. So whatever the agent does, it's going to have all of these specs in mind when it does it.”

In the video: Tom Chant, at 25:07

5. Plan Mode Resolves Edge Cases Before Coding

Timestamp: 00:28:50 to 00:36:34 (8 min)

Speaker: Tom Chant

For complex or ambiguous features, toggling Plan Mode instructs the agent to outline its implementation strategy and file edits without touching the codebase. When planning a recently viewed articles feature for a React blog, the agent proposes using localStorage and capping the list at five items, allowing the developer to spot missing logic for deleted articles. Iterating on the plan to silently skip deleted article IDs ensures a clean implementation once approved.

Impact: High. Why it matters: Demonstrates how separating architectural planning from code generation catches edge cases before an agent edits multiple files.

“Now, in plan mode, the agent will not change or add to the code. It means you can throw around ideas without breaking anything.”

In the video: Tom Chant, at 29:03

6. Custom Skills Encode Team Standards and House Style

Timestamp: 00:36:39 to 00:44:57 (8 min)

Speaker: Tom Chant

A skill is a portable, reusable prompt wrapper stored in the .agent/skills directory that can be invoked via slash or dollar-sign commands. While basic skills simply run scripts like generating a file tree, powerful skills encode team-specific opinions and house coding styles that an AI model cannot guess. Using the built-in skills-creator to inspect five existing server modules allows the agent to build a /house-style skill that cleanly refactors convoluted payment code.

Impact: High. Why it matters: Shows teams how to package codebase conventions into portable slash commands that enforce uniform refactoring across projects.

“But the real power of skills come when you give the skill not just instructions but also knowledge and opinion. Because what you're doing then is giving the skill something that an AI model cannot know.”

In the video: Tom Chant, at 39:23

7. Repo-Specific Dev Skills Speed Up Debugging

Timestamp: 00:45:03 to 00:50:30 (5 min)

Speaker: Tom Chant

When an e-commerce app fails to render due to a mysterious runner error, a generic debugging checklist is less helpful than a skill built from repository documentation. Prompting the skills-creator to scan the repo for guardrails, platform constraints, and pinned dependencies produces a custom /stylist-dev skill. Invoking that skill immediately diagnoses that sqlite3 was upgraded to 6.0.1 instead of the required 5.1.7, fixing the broken site in just over a minute.

Impact: Medium. Why it matters: Illustrates how encoding repository quirks and pinned dependency rules into a custom skill turns opaque runtime crashes into one-minute fixes.

“The version at the moment is 6.0.1 but the project requires exactly 5.1.7. So, it looks like that package has been upgraded and it's now not compatible with the rest of the codebase.”

In the video: Tom Chant, at 49:38

8. Characterization Tests Lock In Legacy Behavior

Timestamp: 00:50:38 to 01:01:01 (10 min)

Speaker: Tom Chant

Real-world codebases often accumulate messy business logic with intricate rules, such as a dental appointment scheduler handling weekday hours, Friday early closing, and lunch overlaps. Before refactoring tangled code in scheduler.js, developers can instruct the agent to write passing Vitest characterization tests using a fixed future week. Recording a rule in AGENTS.md to run npm test after any edit to scheduler.js ensures all 35 tests verify existing behavior during refactoring.

Impact: High. Why it matters: Provides a practical safety net for refactoring legacy code with AI agents without accidentally breaking undocumented business rules.

“At a high level, what you need to understand about a characterization test is that we use it to protect the character or behavior of a feature so that that behavior doesn't get changed during refactor or when adding new features.”

In the video: Tom Chant, at 53:12

9. Test-Driven Development Stops AI Policy Decisions

Timestamp: 01:01:08 to 01:11:07 (10 min)

Speaker: Tom Chant

Asking an agent to build a 15% discount feature and write tests in the same pass leads the agent to mark its own homework and silently choose how fractional pennies are rounded. Reverting the code and instead prompting for a failing spec test first forces the human to define whether discounts apply to the basket total and round up to two decimal places. Once the 51 Vitest checks reflect human-approved business policy, the agent writes the feature code to make the failing test pass.

Impact: High. Why it matters: Exposes the critical flaw of single-pass AI code-and-test generation and establishes test-driven development as the safeguard for business logic.

“So the take-home here is don't ask the agent to write code and create tests for it in the same pass. In the worst case scenarios, the agent will be marking its own homework just writing tests which pass the code it's just created.”

In the video: Tom Chant, at 1:04:59

10. Small Git Commits and Shared Configs Aid Review

Timestamp: 01:11:14 to 01:15:57 (5 min)

Speaker: Tom Chant

Because coding agents will happily generate 800-line changes across unrelated features, developers must rein them in with small, coherent tasks that map to focused Git commits for human reviewers. Project-level instruction files like AGENTS.md belong to the codebase and should be pushed to GitHub so collaborators share the same guardrails. When teammates use competing tools that generate CLAUDE.md alongside AGENTS.md, the codebase owner must reconcile conflicts while keeping personal config files out of the repository.

Impact: Medium. Why it matters: Sets clear version-control standards for AI-assisted teams so human code reviews remain manageable and agent instructions stay synchronized.

“But the take-home is rein in the agent and give it small, precise, coherent tasks and treat each task as a commit. The reviewer would much rather review a bunch of focused small commits than one tangled web of code.”

In the video: Tom Chant, at 1:13:27

11. Protecting Secrets From Agent Hardcoding and Logs

Timestamp: 01:16:02 to 01:22:52 (7 min)

Speaker: Tom Chant

While developers store API keys and credentials in .env files listed in .gitignore, coding agents can still read those files by default and risk hardcoding secrets into tracked files or printing them via console.log. Developers should never type secrets into chat, must set short expirations and tight spending limits on API tokens, and must inspect diffs before pushing to GitHub. Auditing a sample project reveals three classic leaks: a logged secret, a hardcoded key in commented code, and an unignored .env.local file.

Impact: High. Why it matters: Highlights how autonomous agents bypass traditional .gitignore habits by copying secrets from .env into tracked source files.

“In a classic example, the agent reads the M file. The agent hardcodes a secret in a file. And remember, the agent is concerned with making the app work. And so agents do sometimes cut corners and take risks.”

In the video: Tom Chant, at 1:18:18

12. Setting Up Codex in VS Code and Managing Context

Timestamp: 01:22:59 to 01:34:20 (11 min)

Speaker: Tom Chant

Installing the official OpenAI Codex extension in VS Code lets developers adjust reasoning effort, model capability, and speed to balance token cost against task complexity. Although modern models handle context windows of 1 million tokens or more, approaching the limit triggers automatic compaction or truncation that can lose nuance. Starting a fresh session for each task via /clear or reloading the VS Code window keeps context clean, while mid-task handoff prompts preserve progress.

Impact: Medium. Why it matters: Equips developers with practical habits for controlling token costs and avoiding degraded agent performance in long coding sessions.

“But what you do need to know is that this process is lossy and that means some information or nuance is being lost from the conversation and that can lead to erratic behavior from the agent.”

In the video: Tom Chant, at 1:29:17

13. Controlling Permissions and Models via config.toml

Timestamp: 01:34:25 to 01:43:48 (9 min)

Speaker: Tom Chant

Codex offers three UI permission levels—Ask for approval, Approve for me, and Full access—alongside granular configuration via a project or global config.toml file. Inside config.toml, developers can set approval_policy to on-request, untrusted, or never, restrict file access via sandbox_mode, and downgrade the default model from 5.6 to 5.4 to save money across sessions. If project-level config.toml changes fail to apply after reloading VS Code, developers must check organization policy overrides or explicitly mark the project path as trusted in the global config.

Impact: Medium. Why it matters: Shows how to enforce safety boundaries and persistent cost-saving model defaults across every Codex workspace.

“The default is workspace, write, and that means Codex can edit files in the current workspace, but not elsewhere on your machine.”

In the video: Tom Chant, at 1:38:15

14. Connecting External Tools with MCP and shadcn

Timestamp: 01:43:55 to 01:50:42 (7 min)

Speaker: Tom Chant

The Model Context Protocol (MCP) acts as a standardized USB-C style interface that lets coding agents call external servers, query databases, and pull live resources in an iterative loop. To fix a React Kanban board with inconsistent borders, buttons, and shadows, prompting Codex to set up the shadcn MCP server registers the tool in config.toml and adds components.json. Querying the server exposes 61 shadcn UI components in 26 seconds, allowing Codex to refactor the entire board into a clean, uniform layout in about six minutes.

Impact: High. Why it matters: Demonstrates how MCP connects coding agents to verified component registries and external tools like Playwright and GitHub.

“MCP stands for model context protocol, and it's designed to be the USBC for AI, allowing AI assistants to securely connect to external tools and data sources.”

In the video: Tom Chant, at 1:44:21

Conflicts of interest (1)

Scrimba Platform Self-Promotion

Commercial conflict, Medium severity

Instructor Tom Chant is Head of Education at Scrimba and uses Scrimba's proprietary interactive coding agent throughout the lessons.

Sources: Tom Chant, Scrimba

Significance: The course steers viewers toward Scrimba's paid interactive platform and recommended Git course to complete the hands-on challenges.

Key sources

  • Tom Chant: Head of Education at Scrimba
  • YouTube: freeCodeCamp.org: Course Publisher and Intro Narrator

Who's in this

  • Scrimba
  • Codex
  • OpenAI
  • Claude Code
  • Anthropic
  • VS Code
  • Vitest
  • Git
  • GitHub
  • shadcn

Also mentioned

  • JavaScript (First mentioned at 10:18)
  • React (First mentioned at 29:49)
  • TypeScript (First mentioned at 29:49)
  • ChatGPT (First mentioned at 1:05)
  • Devin (First mentioned at 3:09)
  • Windsurf (First mentioned at 3:09)
  • Cursor (First mentioned at 3:13)
  • Windows (First mentioned at 27:46)
  • Mac (First mentioned at 27:46)
  • SQLite3 (First mentioned at 49:31)
  • Stack Overflow (First mentioned at 0:50)
  • GitHub Copilot (First mentioned at 3:09)
  • JSONPlaceholder (First mentioned at 15:57)
  • Linux (First mentioned at 27:46)
  • Amazon (First mentioned at 1:04:25)
  • Playwright (First mentioned at 1:50:26)

This analysis was generated by skim (skim.plus), an AI-powered content analysis platform by Credible AI. Scores and classifications represent the platform's AI-generated assessment and should be considered alongside other sources.