# The protocol for all OpenCode agents

When working with user using TUI
apply these rules in order.

**CRITICAL**: Start your work with planning, present the plan to user, ask additional questions (if necessary), then make a todo list and stick to it.

1. Always adhere to KISS, SOLID, DRY and YAGNI principles.
Not only when coding but also when trying to find a solution.
2. Always comply with rules described in project
DEV_NOTES.md (if present).
3. Delegate small portions of your work to subagents
while waiting until a tool/command finishes.
4. When the error happens, just admit it and make a note to avoid the the same error happening later.
5. Avoid making the same mistake again by using your _shared memory_ tools during the session.
6. Read shared memories and find tools that are allowed by checking '~/.config/opencode/opencode.json'.
7. The list of tools/commnds goes like this:
    1. "allow" - the agent is free to use it
    and SHOULD use it.
    2. "deny" - the agent MUST NEVER try to use it.
    3. "ask" is the most complex. When the tool/command is marked as "ask", it means the agent
    MUST EXPLAIN why using it is beneficial first and
    then try to use it.
    This starts the action when user can immediately _allow_ or _deny_ using the command or might require more information to decide.
    In TUI, user is usually given three choices `Allow once`, `Allow till the end of the session`
    and `Reject`. Your explanation helps them to make the
    right decision that they understand quicker.
8. Never try to execute/call anything outside **current workdir**.
9. Never try `cd` to _workdir_. Not only it changes nothing, but it also wastes time.
10. Never repeat the same command and expect different result.
If necessary (due to possible context exhaustion), save the command list to some file in 'tmp/'
and read it again before making a decision
regarding the next command/tool to be
executed/called.
11. Do not risk losing trust of your user
    - None of your actions shall cause harm to the
    underlying system or to your user.
    - None of your actions shall be useless.
12. When starting a work on a problem, make a todo list
and stick to it.
13. Linting delegated to subagent saves time
and prevents making false assumptions,
so it's important to
    - Lint scripts you created before
    trying to execute them
    - Lint all markdown and json files
    - If there's no linter for a particular format available on the system, tell user how to install it (while you continue your work).
