OpenCode Working Memory works out-of-the-box with sensible defaults. Configuration is defined in src/types.ts as constants.
const LONG_TERM_LIMITS = {
maxRenderedChars: 3600, // Maximum characters in system prompt
targetRenderedChars: 3000, // Target characters (leave buffer)
maxEntries: 28, // Maximum number of entries
maxEntryTextChars: 260, // Maximum characters per entry text
maxRationaleChars: 180, // Maximum characters per entry rationale
};Recommendations:
- Keep
maxRenderedCharsunder 5500 to avoid context bloat - Defaults are calibrated from observed rendered usage that was typically under ~2000 characters
maxEntriesof 28 provides good coverage without overwhelming- Entry text limits ensure entries stay concise
Workspace memory retention uses strength-based decay. These constants live in src/workspace-memory.ts:
const BASE_HALF_LIFE_DAYS = 45;
const REINFORCEMENT_HALFLIFE_FACTOR = 0.85;
const REINFORCEMENT_MAX_COUNT = 6;
const WORKSPACE_DORMANT_AFTER_DAYS = 14;
const DORMANT_DECAY_MULTIPLIER = 0.25;Initial strength uses type, source, and user importance factors. Confidence is stored for compatibility but is not used for retention scoring.
Rendered type caps prevent one type from filling all workspace memory slots:
| Type | Rendered cap |
|---|---|
feedback |
10 |
decision |
10 |
project |
8 |
reference |
6 |
Old or stale-marked memories are not hard-pruned by age; they lose rendered space through strength and cap competition. The deprecated safetyCritical field is preserved for compatibility but no longer affects strength or type caps.
const HOT_STATE_LIMITS = {
maxRenderedChars: 700, // Maximum characters in system prompt
maxActiveFilesStored: 20, // Maximum files tracked in state
maxActiveFilesRendered: 8, // Maximum files shown in prompt
maxOpenErrorsStored: 5, // Maximum errors tracked
maxOpenErrorsRendered: 3, // Maximum errors shown in prompt
maxRecentDecisionsStored: 8, // Maximum decisions tracked
};Recommendations:
- Keep
maxRenderedCharsunder 1500 for fast prompts - Defaults are calibrated from observed rendered usage around ~500 characters or less
maxActiveFilesRenderedof 8 provides good context coveragemaxOpenErrorsRenderedof 3 avoids overwhelming error lists
| Type | Purpose | Rendered cap |
|---|---|---|
feedback |
User preferences for workspace | 10 |
project |
Project-level information | 8 |
decision |
Important decisions | 10 |
reference |
Key references | 6 |
| Source | Confidence | Description |
|---|---|---|
explicit |
1.0 | User explicitly said "remember this" |
compaction |
0.75 | Extracted during conversation compaction |
manual |
varies | Added programmatically |
Files are ranked by action type:
| Action | Weight | Description |
|---|---|---|
write |
4 | File created/overwritten |
edit |
3 | File modified |
read |
2 | File read |
grep |
1 | Grep searched in file |
Score formula: count * action_weight * recency_decay
| Category | Recognition Pattern |
|---|---|
typecheck |
TS errors, TypeScript failures |
test |
Test failures |
lint |
ESLint warnings/errors |
build |
Build failures |
runtime |
Uncaught errors, Node exceptions |
tool |
Tool execution failures |
~/.local/share/opencode-working-memory/
└── workspaces/
└── {workspaceKey}/
├── workspace-memory.json # Long-term memory
└── sessions/
└── {hashedSessionID}.json # Session state (hashed)
// First 16 characters of SHA-256 hash
const workspaceKey = sha256(realpath(workspaceRoot)).slice(0, 16);// Hashed session ID for privacy
const hashedSessionID = sha256(sessionID).slice(0, 32);To customize limits, edit the constants in src/types.ts:
// Example: Increase workspace memory limit
export const LONG_TERM_LIMITS = {
maxRenderedChars: 6000, // Increased from 3600
maxEntries: 35, // Increased from 28
// ...
};Note: After customization, rebuild the plugin:
npm run build// Reduce memory overhead
const HOT_STATE_LIMITS = {
maxRenderedChars: 800, // Reduced
maxActiveFilesRendered: 5, // Reduced
maxOpenErrorsRendered: 2, // Reduced
};// Preserve more context
const LONG_TERM_LIMITS = {
maxEntries: 40, // Increased
targetRenderedChars: 5000, // Increased
};// Strict limits
const LONG_TERM_LIMITS = {
maxRenderedChars: 3000,
maxEntries: 15,
};
const HOT_STATE_LIMITS = {
maxRenderedChars: 600,
maxActiveFilesRendered: 4,
};# Workspace memory
cat ~/.local/share/opencode-working-memory/workspaces/*/workspace-memory.json | jq
# Session state
cat ~/.local/share/opencode-working-memory/workspaces/*/sessions/*.json | jqFrom a source checkout, maintainers can inspect stored vs rendered memory behavior:
bun scripts/memory-diag.ts healthThe health output includes stored active memories, rendered candidates, type caps, global cap overflow, dormancy status, retention monitoring alerts, and strength-ranked top/weakest entries.
# Remove workspace memory (start fresh)
rm ~/.local/share/opencode-working-memory/workspaces/*/workspace-memory.json# Remove all session states
rm ~/.local/share/opencode-working-memory/workspaces/*/sessions/*.json-
Workspace Memory Hygiene:
- Let OpenCode Working Memory extract memories automatically
- Use explicit "remember this" for important information
- Don't manually edit memory files unless testing
-
Session State:
- Let OpenCode Working Memory track active files automatically
- Errors are cleared when commands succeed
- No manual intervention needed
-
Memory Extraction:
- Use
Memory candidates:during compaction - Follow the pattern:
- [type] text - Quality gate rejects invalid candidates
- Use
Last Updated: April 2026
Configuration File: src/types.ts