OpenCode prompt construction: system prompt, tools, agents, and assembly pipeline Here is a factual summary of the article: OpenCode constructs the LLM's system prompt by combining dynamic environment data (model name, working directory, date) with a provider-specific prompt file selected based on the model ID (e.g., Claude uses `anthropic.txt`, GPT models use `beast.txt`). The system prompt is assembled from contributions by `system.ts`, `instruction.ts` (which gathers AGENTS.md/CLAUDE.md files), and `llm.ts`, with a plugin hook allowing modifications and special handling for Anthropic's prompt caching. Additionally, small `.txt` files are injected into the message array based on session state (e.g., plan mode, step limits), and instruction files are discovered both at system prompt time and during tool execution to provide context. This document explains how OpenCode assembles everything the LLM sees: system prompt, tool definitions, agent configuration, and instruction files. It focuses on what's dynamic and why. All paths are relative to the repo root. Four files collaborate to produce the system prompt. The orchestrator is packages/opencode/src/session/prompt.ts , which runs the agentic loop. Each iteration, it asks two other modules for content: system.ts provides an environment block model name, working directory, platform, today's date and selects a provider-specific prompt file, while instruction.ts walks the filesystem for AGENTS.md / CLAUDE.md files and fetches any URL-based instructions from config. These pieces are handed to llm.ts , which assembles the final system message array and calls streamText . The provider prompt is chosen by matching the model ID string: Claude gets anthropic.txt , GPT/o1/o3 get beast.txt , Gemini gets gemini.txt , GPT-5 gets codex header.txt , Trinity gets trinity.txt , and everything else falls back to qwen.txt . These are static .txt files in packages/opencode/src/session/prompt/ . If the active agent defines its own prompt like explore or compaction , that replaces the provider prompt entirely. For OpenAI Codex OAuth sessions, the provider prompt is sent via a separate options.instructions field rather than the system message. After assembly, a plugin hook experimental.chat.system.transform gives plugins a chance to mutate the system array — adding, removing, or replacing entries. There's a safety fallback: if a plugin empties the array, the original is restored. The system array is also restructured for Anthropic's prompt caching — if the first element survived plugin transforms unchanged, the rest is joined into a single string to maintain a cacheable 2-part structure. Several small .txt files are injected into the message array not the system prompt based on session state. When plan mode is active, plan.txt is appended to the last user message. When switching from plan to build, build-switch.txt is appended with the plan file path interpolated in experimental mode . When the model exceeds its step limit, max-steps.txt is injected as a fake assistant message to force a summary. packages/opencode/src/session/instruction.ts handles AGENTS.md , CLAUDE.md , and CONTEXT.md deprecated . It searches for these filenames in order and stops at the first one found at any directory level. Discovery happens at two points: At system prompt time: it walks from the working directory up to the worktree root, checks global config directories and ~/.claude/CLAUDE.md , and resolves any paths or URLs from the instructions config key. Each file is prefixed with Instructions from: