External context is live documentation fetched from external libraries and frameworks (via Context7 API or official docs). Instead of re-fetching on every task, we persist external context to .tmp/external-context/ so main agents can pass it to subagents.
Key Principle: ExternalScout fetches once → persists to disk → main agents reference → subagents read (no re-fetching)
.tmp/external-context/
├── .manifest.json # Metadata about all cached external docs
├── drizzle-orm/
│ ├── modular-schemas.md # Fetched: "How to organize schemas modularly"
│ ├── postgresql-setup.md # Fetched: "PostgreSQL setup with Drizzle"
│ └── typescript-config.md # Fetched: "TypeScript configuration"
├── better-auth/
│ ├── nextjs-integration.md # Fetched: "Better Auth + Next.js setup"
│ ├── drizzle-adapter.md # Fetched: "Drizzle adapter for Better Auth"
│ └── session-management.md # Fetched: "Session handling"
├── next.js/
│ ├── app-router-setup.md # Fetched: "App Router basics"
│ ├── server-actions.md # Fetched: "Server Actions patterns"
│ └── middleware.md # Fetched: "Middleware configuration"
└── tanstack-query/
├── server-components.md # Fetched: "TanStack Query + Server Components"
└── prefetching.md # Fetched: "Prefetching strategies"
Package name (directory): Exact npm package name (kebab-case)
drizzle-orm, better-auth, next.js, @tanstack/react-querydrizzle, nextjs, tanstack-queryFile name (topic): Kebab-case description of the topic
modular-schemas.md, nextjs-integration.md, server-components.mdmodular schemas.md, NextJS Integration.md, ServerComponents.mdLocation: .tmp/external-context/.manifest.json
Purpose: Track what's cached, when it was fetched, and from which source
Structure:
{
"last_updated": "2026-01-28T14:30:22Z",
"packages": {
"drizzle-orm": {
"files": [
"modular-schemas.md",
"postgresql-setup.md",
"typescript-config.md"
],
"last_updated": "2026-01-28T14:30:22Z",
"source": "Context7 API",
"official_docs": "https://orm.drizzle.team"
},
"better-auth": {
"files": [
"nextjs-integration.md",
"drizzle-adapter.md",
"session-management.md"
],
"last_updated": "2026-01-28T14:25:10Z",
"source": "Context7 API",
"official_docs": "https://better-auth.com"
},
"next.js": {
"files": [
"app-router-setup.md",
"server-actions.md",
"middleware.md"
],
"last_updated": "2026-01-28T14:20:05Z",
"source": "Context7 API",
"official_docs": "https://nextjs.org"
}
}
}
Each external context file has a metadata header followed by the documentation content.
Template:
---
source: Context7 API
library: Drizzle ORM
package: drizzle-orm
topic: modular-schemas
fetched: 2026-01-28T14:30:22Z
official_docs: https://orm.drizzle.team/docs/goodies#multi-file-schemas
---
# Modular Schemas in Drizzle ORM
[Filtered documentation content from Context7 API]
## Key Concepts
[Relevant sections only]
## Code Examples
[Practical examples from official docs]
---
**Source**: Context7 API (live, version-specific)
**Official Docs**: https://orm.drizzle.team/docs/goodies#multi-file-schemas
**Fetched**: 2026-01-28T14:30:22Z
Main Agent (e.g., OpenAgent)
↓
Detects: "User is asking about Drizzle + Better Auth + Next.js"
↓
Calls: ExternalScout to fetch live docs
ExternalScout
↓
1. Detects libraries: Drizzle, Better Auth, Next.js
↓
2. Fetches from Context7 API (primary) or official docs (fallback)
↓
3. Filters to relevant sections
↓
4. Persists to .tmp/external-context/{package-name}/{topic}.md
↓
5. Updates .manifest.json
↓
Returns: File paths + formatted documentation
Main Agent
↓
Creates session: .tmp/sessions/{session-id}/context.md
↓
Adds section: "## External Context Fetched"
↓
Lists files:
- .tmp/external-context/drizzle-orm/modular-schemas.md
- .tmp/external-context/better-auth/nextjs-integration.md
- .tmp/external-context/next.js/app-router-setup.md
↓
Delegates to TaskManager with session path
TaskManager (or CoderAgent, TestEngineer, etc.)
↓
Reads: .tmp/sessions/{session-id}/context.md
↓
Extracts: "## External Context Fetched" section
↓
Reads: .tmp/external-context/{package-name}/{topic}.md files
↓
Uses: External docs to inform implementation
↓
NO RE-FETCHING needed ✅
Add this section to .tmp/sessions/{session-id}/context.md:
## External Context Fetched
These are live documentation files fetched from external libraries. Subagents should reference these instead of re-fetching.
### Drizzle ORM
- `.tmp/external-context/drizzle-orm/modular-schemas.md` — Schema organization patterns
- `.tmp/external-context/drizzle-orm/postgresql-setup.md` — PostgreSQL configuration
### Better Auth
- `.tmp/external-context/better-auth/nextjs-integration.md` — Next.js integration guide
- `.tmp/external-context/better-auth/drizzle-adapter.md` — Drizzle adapter setup
### Next.js
- `.tmp/external-context/next.js/app-router-setup.md` — App Router basics
- `.tmp/external-context/next.js/server-actions.md` — Server Actions patterns
**Important**: These files are read-only and should not be modified. They're cached for reference only.
When TaskManager creates subtask JSONs, it should include external context files:
{
"id": "01-drizzle-schema-setup",
"title": "Set up Drizzle schema with modular organization",
"context_files": [
".opencode/context/core/standards/code-quality.md",
".opencode/context/core/standards/test-coverage.md"
],
"reference_files": [
"package.json",
"src/db/schema.ts"
],
"external_context": [
".tmp/external-context/drizzle-orm/modular-schemas.md",
".tmp/external-context/drizzle-orm/postgresql-setup.md"
],
"instructions": "Set up Drizzle schema following modular patterns from external context..."
}
External context files should be cleaned up when:
Manual cleanup (ask user first):
rm -rf .tmp/external-context/{package-name}/
# Update .manifest.json to remove package entry
Automatic cleanup (future enhancement):
After deleting external context files, update .manifest.json:
{
"last_updated": "2026-01-28T15:00:00Z",
"packages": {
// Remove entries for deleted packages
}
}
.tmp/external-context/Main Agent Flow:
1. User asks: "Set up Drizzle + Better Auth in Next.js"
2. Main agent calls ExternalScout
3. ExternalScout fetches:
- drizzle-orm/modular-schemas.md
- drizzle-orm/postgresql-setup.md
- better-auth/nextjs-integration.md
- better-auth/drizzle-adapter.md
- next.js/app-router-setup.md
4. ExternalScout persists all files to .tmp/external-context/
5. Main agent creates session with "## External Context Fetched" section
6. Main agent delegates to TaskManager with session path
7. TaskManager reads external context, creates subtasks
8. CoderAgent implements using external docs (no re-fetching)
Session Context File:
## External Context Fetched
### Drizzle ORM
- `.tmp/external-context/drizzle-orm/modular-schemas.md`
- `.tmp/external-context/drizzle-orm/postgresql-setup.md`
### Better Auth
- `.tmp/external-context/better-auth/nextjs-integration.md`
- `.tmp/external-context/better-auth/drizzle-adapter.md`
### Next.js
- `.tmp/external-context/next.js/app-router-setup.md`
Main Agent Flow:
1. User asks: "How do I use TanStack Query with Next.js Server Components?"
2. Main agent calls ExternalScout
3. ExternalScout fetches:
- tanstack-query/server-components.md
- tanstack-query/prefetching.md
- next.js/server-components.md
4. ExternalScout persists to .tmp/external-context/
5. Main agent creates session with external context references
6. Subagents read and implement using external docs
Problem: Subagent can't find .tmp/external-context/{package-name}/{topic}.md
Solution:
.manifest.json to see what's cachedProblem: External docs are outdated (>7 days old)
Solution:
rm -rf .tmp/external-context/{package-name}/.manifest.jsonProblem: .manifest.json doesn't match actual files
Solution:
bash
find .tmp/external-context -name "*.md" | sort
.manifest.json to match.opencode/agent/subagents/core/externalscout.md — Fetches and persists external docs.opencode/context/core/workflows/task-delegation.md — How to reference external context in sessions.opencode/context/core/workflows/session-management.md — Session lifecycle.opencode/skill/context7/library-registry.md — Supported libraries and query patterns