The information available to the LLM during a session.
Context is everything the language model can "see" when generating a response. It is the working memory of an AI session — the system prompt, your conversation, tool outputs, file contents, and project-specific rules all packed into a single token budget.
In OpenCode, context is the combined set of information fed to the LLM on each turn. It includes:
read, output from bash, search results, etc.AGENTS.md or files in .opencode/rules/"instructions" field in opencode.jsonContext is session-scoped. It is not shared between different sessions. Each session starts with its own clean context that grows as you interact.
Context has a finite size (measured in tokens). Here is roughly how it fills up:
┌─────────────────────────────────┐
│ System Prompt │ ← OpenCode's base instructions
├─────────────────────────────────┤
│ Rules / Instructions │ ← AGENTS.md, .opencode/rules/
├─────────────────────────────────┤
│ Conversation History │ ← Messages from this session
├─────────────────────────────────┤
│ Tool Outputs │ ← File contents, bash output, etc.
├─────────────────────────────────┤
│ MCP Tool Descriptions │ ← Schemas from connected servers
├─────────────────────────────────┤
│ Skill Content │ ← Loaded on-demand by skills
└─────────────────────────────────┘
When this fills up, compaction kicks in to summarize and reduce the token count while preserving important state.
Context is assembled at runtime for each session. The pieces come from:
opencode.json - the "instructions" field points to extra context filesAGENTS.md - project root, contains agent instructions.opencode/rules/ - directory of rule files loaded into contextYou do not "create" context manually. OpenCode assembles it. But you can influence what goes into it:
# Add project instructions
cat > AGENTS.md <<'EOF'
# Project Rules
- Use TypeScript strict mode
- Prefer named exports over default exports
- Run `npm run lint` before committing
EOF
# Add more rule files
mkdir -p .opencode/rules
cat > .opencode/rules/testing.md <<'EOF'
# Testing Rules
- Write tests for all new functions
- Use vitest, not jest
- Test file goes next to source file with .test.ts suffix
EOF
# Point to additional context in opencode.json
cat > opencode.json <<'EOF'
{
"instructions": ["./docs/ARCHITECTURE.md", "./docs/API.md"]
}
EOF
A project with well-structured context:
# Project structure
my-project/
AGENTS.md # General agent instructions
.opencode/
rules/
architecture.md # Architecture decisions
coding-style.md # Code conventions
plugins/
lint-on-edit.ts # Plugin with hooks
opencode.json
# { "instructions": ["./docs/CONTRIBUTING.md"] }
# When you start a session, context includes:
# - System prompt (built-in)
# - AGENTS.md content
# - All .opencode/rules/*.md files
# - docs/CONTRIBUTING.md content
# - Conversation history (grows as you chat)
# - Tool outputs (file reads, searches, etc.)
--continue to resume that session.
session.compacted event fires, and the experimental.session.compacting hook lets you customize this process.