OpenCode Capstone Project

Introduction: Building a Complete Project

Welcome to the final lesson of the Foundation course. Over the previous units, you have learned how to install OpenCode, manage sessions, configure the agent's behavior, and leverage its autonomous capabilities. Now it is time to combine everything into a realistic development workflow.

In this lesson, we will take an incomplete todo list application and transform it into polished, production-ready software. You will plan improvements, implement features, refactor messy code, add new modules, and write documentation — all through natural conversation with your AI assistant.

Setting Up Your Workspace

Before we begin coding, we need to ensure OpenCode starts in the correct directory. The agent is context-aware, meaning it automatically reads the file structure of whatever folder you launch it from. Starting in an empty directory means the agent knows nothing about your project. Starting inside your project folder gives it immediate access to your codebase.

Navigate to your project and launch OpenCode:

cd todo-app
opencode

Once the interface loads, the agent can already see files like app.py, tasks.py, and config.py. You do not need to manually tell it about your project structure — it discovers this automatically.

Planning Before Building

When facing a complex task, rushing to write code often leads to poor decisions. Instead, we will start by switching to the Plan agent to create a strategy. The Plan agent analyzes your code and proposes solutions without modifying any files, giving you a chance to review the approach before committing to it.

Press Tab to switch from Build mode to Plan mode. You will see the status bar change to reflect this. Then ask the agent to review your codebase:

> Review this codebase and create a plan to complete the missing features: data persistence in app.py and task validation in tasks.py

The agent reads your files and produces a structured implementation plan:

● Reading app.py...
● Reading tasks.py...

Here's my implementation plan:

**Phase 1: Data Persistence in app.py**
The save_tasks() function needs:
  - JSON file handling with error recovery
  - Atomic writes to prevent data corruption
  - Backup creation before overwriting

**Phase 2: Task Validation in tasks.py**
The create_task() function needs:
  - Input sanitization for task descriptions
  - Date validation for due dates
  - Prevention of duplicate tasks

This plan becomes your roadmap. You can ask clarifying questions, request adjustments, or approve it as-is before moving forward.

Implementing the Plan

With a solid strategy in place, switch back to the Build agent by pressing Tab again. Because the agent remembers your entire conversation, you do not need to repeat the plan — simply tell it to proceed:

> Implement the plan

The agent executes the strategy across multiple files in a single turn:

● Editing app.py...
✓ Modified app.py - Added persistence logic

● Editing tasks.py...
✓ Modified tasks.py - Added validation

Done! Added data persistence to app.py and validation to tasks.py.

Notice how the agent applied file handling with proper error recovery in app.py and added validation checks to tasks.py — all based on the plan you reviewed together. This Plan → Build workflow prevents the agent from making hasty decisions and ensures you maintain control over the direction of your project.

Targeting Specific Files

Sometimes you want to improve a single file without touching the rest of your project. The @ syntax lets you focus the agent's attention on exactly the file you care about. This is especially useful for refactoring, where you want to clean up code structure without changing functionality.

Let's say your tasks.py works correctly but has a long chain of repetitive if/elif statements for task priority handling. You can target it directly:

> @tasks.py The set_priority function is messy. Refactor it to be cleaner and more readable.

The agent focuses exclusively on this file:

● Reading tasks.py...
● Refactoring set_priority...

✓ Modified tasks.py

Refactored! The code is now:
  - Uses an enum for priority levels
  - Has clear validation logic
  - Includes proper docstrings

By using @tasks.py, you ensured that app.py and config.py remained untouched. This targeted approach reduces risk and keeps your changes predictable.

Creating New Modules

OpenCode is not limited to editing existing files — it can create entirely new ones and integrate them with your codebase. Let's add a filtering system to easily search and display tasks by category or due date.

Rather than cramming this logic into an existing file, we will ask for a new module:

> Add a task filtering feature so users can search by category or due date. Create a new file called filters.py and integrate it with app.py.

The agent creates the new file and updates your existing code to use it:

● Creating filters.py...
✓ Created filters.py

● Editing app.py...
✓ Modified app.py - Integrated filtering

Done! Created filters.py with category and date filters and integrated it with app.py.

In a single request, the agent wrote a TaskFilter class with by_category() and by_due_date() methods, added the import statement to app.py, and modified the display logic to support filtered views. This demonstrates how complex, multi-file tasks can be handled through simple natural language requests.

Handling Errors Automatically

One of the most powerful aspects of agentic AI is self-correction. When code fails, you do not need to diagnose the problem yourself — the agent reads the error output and fixes it autonomously.

Suppose you ask the agent to run your application and something goes wrong:

> Run the app

● Running: python app.py

Traceback (most recent call last):
  File "app.py", line 3, in <module>
    from filters import TaskFilter
ModuleNotFoundError: No module named 'filters'

Instead of manually debugging, simply ask for help:

> There's an error, can you fix it?

● Reading error output...
● Checking file structure...
● Creating missing filters.py...

✓ Fixed! The filters module was missing. I've created it and the app should work now.

The agent diagnosed the missing module, created the necessary file, and resolved the issue. This self-correction loop dramatically reduces debugging frustration and keeps you focused on building features rather than chasing errors.

Documentation and Testing

A project is not complete without clear documentation. Since the agent has read all your code and understands every feature you built together, it is perfectly positioned to write accurate documentation:

> Create a README.md with usage instructions and run the app to make sure everything works

The agent generates comprehensive documentation and verifies the application:

● Creating README.md...
✓ Created README.md

● Running: python app.py

Todo List Manager
-----------------
1. Buy groceries (Due: 2024-03-15) [High]
2. Write report (Due: 2024-03-16) [Medium]

The app is working correctly!

Here's the README I created:
# Todo List Manager
A simple command-line todo list application with filtering support...

The agent confirms your application runs properly and provides clear documentation for future users.

Wrapping Up and Moving Forward

When you are finished working, exit cleanly with /quit. You can return later with opencode --continue to pick up exactly where you left off.

You have now experienced the complete development workflow: planning with the Plan agent, implementing with the Build agent, targeting specific files with @ syntax, creating new modules, letting the agent self-correct errors, and generating documentation. This is the same process you will use on real projects — the only difference is scale.

In the practice exercises that follow, you will apply these skills independently to build a different application from scratch. By the end, you will be ready to collaborate with OpenCode on any project you can imagine.

Congratulations on completing Foundation - Getting Started with OpenCode! You now have the foundational skills to work effectively with AI-assisted development and are ready to tackle real-world projects with confidence.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal