opencodeagt - One-shot execution of Opencode agents from markdown files
opencodeagt [AGENT_NAME] [FLAGS...]
opencodeagt facilitates a workflow for using custom Opencode agents defined in the .opencode/agent/ directory.
Opencode allows you to place custom agent definitions in .opencode/agent/. This script parses out the model from the YAML frontmatter and the prompt from the file body. It then runs the agent as a one-shot task using the opencode run command.
This enables you to define reusable, pre-configured agent prompts and models in your project repository and trigger them quickly from the command line without manual configuration every time.
NOTE: This tool passes any additional command-line arguments directly to opencode run.
To use this function permanently, append it to your shell configuration:
cat opencodeagt.sh >> ~/.zshrcOr source it in your current session:
source opencodeagt.shThe function is designed for zsh but should be compatible with bash.
The function expects the following directory structure in your project:
.
└── .opencode
└── agent
└── [AGENT_NAME].md
Agent files must be Markdown files with YAML frontmatter specifying the model. The content after the frontmatter is used as the prompt.
Example (.opencode/agent/DataTester.md):
---
model: opencode/gemini-3-flash
---
Run regression tests and export the results to CSV...Basic usage: Run the 'DataTester' agent:
opencodeagt DataTesterWith additional flags:
Pass flags supported by opencode run directly to the script:
opencodeagt DataTester --print-logs --log-level DEBUGThe tool seems to hang:
If the tool appears to hang or stop responding, it is likely waiting for user approval on stdin (if the underlying model or configuration requires it).
To fix this:
- Check the terminal for any prompt requests.
- Check
opencode run --helpfor any flags that might control interactivity or permissions in your specific version.
opencode(1)