Skip to main content

Your First Automation

Let's build a simple but practical automation: a personal AI assistant that knows about your projects and can answer questions using context from files.

What We'll Build

A personal assistant that:

  • Reads your project information from a file
  • Answers questions about your work
  • Updates project status when you tell it to
  • Maintains a history of interactions

Step 1: Create Context Files

First, let's create a context file with information about your projects:

mkdir -p ~/.opencode/context

Create ~/.opencode/context/projects.md:

# My Projects

## Marea.dev
**Status:** Active Development
**Goal:** Launch AI automation framework by Nov 15, 2025
**Tech Stack:** TypeScript, Node.js, Docusaurus
**Next Steps:**
- Complete documentation site
- Build 3 example automations
- Launch Discord community

## Personal Website
**Status:** Maintenance
**Goal:** Share technical writing and portfolio
**Tech Stack:** Next.js, React, Tailwind
**Next Steps:**
- Write blog post about AI automation
- Update portfolio with recent projects

Step 2: Create Your First Prompt

Create a reusable prompt that tells the AI about its role:

Create ~/.opencode/prompts/assistant.md:

You are a personal AI assistant with access to the user's project information.

Your capabilities:
- Read project status from context files
- Answer questions about active projects
- Update project information when requested
- Maintain project history

Be concise and helpful. When asked about projects, reference the specific details from the context files.

Step 3: Run Your First Query

Now ask your assistant a question:

opencode --context context/projects.md \
--prompt prompts/assistant.md \
"What projects am I working on?"

You should see a response like:

You're currently working on two projects:

1. **Marea.dev** (Active Development)
- Building an AI automation framework
- Target launch: Nov 15, 2025
- Next: Complete docs, build examples, launch community

2. **Personal Website** (Maintenance)
- Next.js portfolio and blog
- Next: Write AI automation blog post, update portfolio

Your main focus appears to be the Marea.dev launch.

Step 4: Update Project Status

Now let's update a project status:

opencode --context context/projects.md \
--prompt prompts/assistant.md \
"I finished the documentation site for Marea.dev. Update the project status and remove that from next steps."

OpenCode will:

  1. Read the current projects.md file
  2. Update the content to reflect completion
  3. Write the updated file back
  4. Confirm the change

Check the updated file:

cat ~/.opencode/context/projects.md

You should see the "Complete documentation site" removed from the next steps.

Step 5: Make It Easier with an Alias

Add this to your shell profile (~/.zshrc or ~/.bashrc):

alias ask="opencode --context ~/.opencode/context/projects.md --prompt ~/.opencode/prompts/assistant.md"

Reload your shell:

source ~/.zshrc

Now you can simply:

ask "What should I work on next?"

Understanding What Happened

Let's break down the magic:

  1. Context Loading: OpenCode read your projects.md file and gave it to the AI
  2. Tool Calling: The AI decided which tools to use (read file, write file, etc.)
  3. Natural Language: You didn't write any code - just asked in plain English
  4. File Persistence: Changes are saved to files you can version control with git
  5. Model Agnostic: This works with Claude, GPT, Gemini - whatever you configured

Next Steps

Now that you've built your first automation, explore:

  • Context Files (coming soon) - Learn more about organizing context
  • Custom Tools (coming soon) - Add your own CLI tools
  • Advanced Patterns (coming soon) - Build complex workflows
  • Examples (coming soon) - See more real-world automations

Common Patterns

Daily Standup

ask "Give me a summary of all projects and what I should focus on today"

Adding a New Project

ask "Add a new project called 'Mobile App' with status In Planning and tech stack React Native"

Project Report

ask "Create a weekly report of all active projects and their progress"

Version Control

Since everything is in files, you can track changes:

cd ~/.opencode
git init
git add .
git commit -m "Initial project setup"

# After updates
git diff # See what changed
git commit -am "Updated Marea.dev status"

Troubleshooting

"Context file not found"

Make sure the file exists:

ls -la ~/.opencode/context/projects.md

"No changes made"

The AI might not have permission to write. Check file permissions:

chmod 644 ~/.opencode/context/projects.md

"API rate limit"

If you're using a free tier API, you might hit rate limits. Wait a moment and try again, or upgrade your API plan.