- TypeScript 86.3%
- Shell 12.9%
- JavaScript 0.8%
| commands | ||
| skills/repo-analysis | ||
| tests | ||
| tools | ||
| .gitignore | ||
| jest.config.js | ||
| MEMORY_INSTRUCTIONS.md | ||
| opencode-anchor-config.example.json | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| setup.sh | ||
| tsconfig.json | ||
Opencode + Anchor Memory Integration
Custom Opencode tools, skills, and commands that integrate with Anchor Memory for semantic memory management during development sessions.
Quickstart
Get up and running in 5 minutes.
Prerequisites
- Opencode installed and configured
- Anchor Memory running (easiest via docker-compose)
- bun installed (required for dependency management)
Installation
-
Clone and navigate to the repository:
git clone https://github.com/anomalyco/opencode-anchor.git cd opencode-anchor -
Run the setup script:
./setup.shThe interactive script will:
- Configure your Anchor Memory connection URL
- Set search scoping preferences
- Install dependencies with bun
- Copy tools, skills, and commands to
~/.config/opencode/
-
Configure Opencode instructions:
Edit
~/.config/opencode/opencode.jsonand add:{ "instructions": ["MEMORY_INSTRUCTIONS.md"] } -
Restart Opencode to load the new tools
Verify Installation
Check that everything is installed:
# Config exists
cat ~/.config/opencode/opencode-anchor-config.json
# Tools are copied
ls -la ~/.config/opencode/tools/
# Instructions are in place
cat ~/.config/opencode/MEMORY_INSTRUCTIONS.md
First Use
Ask Opencode to analyze your repository:
/remember quick
This will scan your README and config files, then remember key information to Anchor Memory (~30 seconds).
Next steps:
- Run
/remember allfor a full repository analysis (~5-10 minutes) - See Tools for anchor-recall and anchor-remember details
- See Configuration for advanced settings
Prerequisites (Detailed)
- Anchor Memory running (default:
http://localhost:3160) - Opencode installed and configured
- Node.js and npm installed
Installation
- Install dependencies:
npm install
- Configure Anchor Memory connection:
cp opencode-anchor-config.example.json .opencode/opencode-anchor-config.json
# Edit .opencode/opencode-anchor-config.json with your settings
Tools
repo-scanner
Scan repository structure and return file listings.
Usage: Used by the repo-analysis skill to discover files in the repository.
Parameters:
depth: Scan depth (quickfor key files only,deepfor all files)
Returns: JSON with file paths, extensions, and sizes (no semantic analysis).
Limits:
- Files >100KB are automatically skipped
- Excludes: node_modules, .git, dist, build, coverage, .next
Example:
{
"repoName": "opencode-anchor",
"keyFiles": {
"readme": "README.md",
"configs": ["package.json", "tsconfig.json"],
"docs": ["README.md", "CONTRIBUTING.md"]
},
"stats": {
"totalFiles": 15,
"totalSize": "45.2 KB"
}
}
anchor-recall
Recall from Anchor Memory for relevant past knowledge.
Usage: The LLM automatically calls this tool when it detects a need for historical context.
Parameters:
query: Search query in natural languagelimit: Maximum results (default: 10)tags: Filter by specific tags (optional)repoScope: Limit to current repo (default: true)
Example:
Recall past authentication decisions
→ Found 3 results about JWT implementation, OAuth setup, and session management
anchor-remember
Save important decisions, patterns, and documentation to Anchor Memory.
Usage: The LLM calls this tool when it recognizes valuable knowledge to preserve.
Parameters:
content: The knowledge to save (required, max 20k tokens)contentType: Type of content (required):decision: Technical/architectural decisions with rationalepattern: Reusable patterns, best practices, conventionsdocumentation: API docs, README updates, verified referencestroubleshooting: Bug fixes, root cause analysis, workaroundsreference: Verified external resources, correct documentation
tags: Array of tags (required, lowercase, no spaces, max 50 chars, alphanumeric + dash)
Validation:
- All fields are validated before remembering
- Invalid input returns helpful error messages with suggestions
- Anchor Memory handles deduplication automatically
Example:
anchor-remember(
content: "Decision: Using Redis for caching due to sub-millisecond latency...",
contentType: "decision",
tags: ["decision", "architecture", "caching"]
)
→ ✓ Saved to Anchor Memory. ID: abc123, Bucket: repo:my-project, Tags: decision, architecture, caching
Skills
repo-analysis
Scans repositories and remembers important information into Anchor Memory.
Usage: Loaded automatically when you run the /remember command.
Modes:
- quick: Fast scan, no questions, only plainly obvious content
- all: Full scan, asks questions about ambiguous content
What it does:
- Scans repository structure using
repo-scanner - Reads and analyzes documentation and code
- Remembers content with appropriate tags (Anchor Memory handles deduplication)
Tags applied:
repo-analysis- All analyzed contentanalysis-quickoranalysis-all- Mode used- Content type tags:
documentation,pattern,decision,reference,troubleshooting - Technology tags:
typescript,react, etc. - Domain tags:
architecture,testing,api, etc.
Commands
/remember
Scan repository and remember to Anchor Memory.
Usage:
/remember quick # Fast scan, no questions, only obvious content
/remember all # Full scan, asks questions about ambiguous content
Quick mode:
- Scans README and config files only
- No questions asked
- Only remembers plainly obvious content (explicit docs, clear configs)
- Silently skips ambiguous content
- Takes ~30 seconds
All mode:
- Scans all files
- Asks questions about inferred or ambiguous content
- Follows linked documents
- Takes ~5-10 minutes
Example:
User: /remember all
Agent: [Loads repo-analysis skill]
[Scans repository with repo-scanner]
[Reads documentation files]
[Remembering content...]
[✓ Analyzed 25 files, remembered 12 items]
Configuration
Copy opencode-anchor-config.example.json to .opencode/opencode-anchor-config.json and edit:
{
"anchorMemory": {
"url": "http://localhost:3160",
"searchRepoScoped": true,
"showConnectionWarnings": true,
"tagCacheDuration": 3600,
"maxContentTokens": 20000
}
}
Options:
url: Anchor Memory API endpointsearchRepoScoped: Limit searches to current repositoryshowConnectionWarnings: Warn when Anchor Memory is unavailabletagCacheDuration: Cache tags for X seconds (default: 3600)maxContentTokens: Maximum tokens per ingestion (default: 20000)
Tag Format
Tags must follow these rules:
- Lowercase only
- No spaces (use dashes:
api-authnotapi auth) - Maximum 50 characters
- Alphanumeric and dashes only
Valid: architecture, api-auth, database-migration, performance-optimization
Invalid: Architecture, api auth, very-long-tag-name-that-exceeds-fifty-characters-limit
Tag Scope
Tags are fetched from all repositories connected to your Anchor Memory instance (global scope), but their meaning is specific to each repository.
For example:
- In
repo:auth-service: tagapimight mean "authentication API endpoints" - In
repo:payment-service: tagapimight mean "payment gateway integration"
When the tool suggests tags, it shows the global list. Choose tags that are meaningful
within the context of your current repository. The bucket (repo:<name>) ensures
knowledge is properly isolated even when using the same tag names.
Repository Scoping
Tools automatically detect the current repository using git and scope operations to repo:<name> bucket. This keeps knowledge isolated per project.
Project Structure
opencode-anchor/
├── skills/
│ └── repo-analysis/
│ └── SKILL.md # Repository analysis skill
├── commands/
│ └── remember.md # /remember command
├── tools/
│ ├── repo-scanner.ts # Repository scanning tool
│ ├── anchor-recall.ts # Recall tool implementation
│ ├── anchor-remember.ts # Remember tool implementation
│ └── shared.ts # Shared utilities
├── tests/
│ └── validation.test.ts # Unit tests
├── opencode-anchor-config.example.json # Configuration template
├── package.json # Dependencies
├── jest.config.js # Test configuration
└── README.md # This file
Testing
Run validation tests:
npm test
Troubleshooting
Anchor Memory not responding:
- Ensure Anchor Memory is running:
curl http://localhost:3160 - Check URL in
.opencode/opencode-anchor-config.json - Check Anchor Memory logs
Validation errors:
- Review error messages for specific issues
- Ensure contentType is one of: decision, pattern, documentation, troubleshooting, reference
- Ensure tags follow format rules
- Check content length (max 20k tokens ≈ 80k characters)
Tag fetch failures:
- Tags are required for remembering
- Check Anchor Memory is accessible
- Tag cache expires after configured duration (default: 1 hour)
/remember command not working:
- Ensure skill is installed:
ls ~/.config/opencode/skills/repo-analysis/SKILL.md - Ensure command is installed:
ls ~/.config/opencode/commands/remember.md - Restart Opencode after installation
- Specify depth:
/remember quickor/remember all
Skill not loading:
- Check skill name matches directory name
- Verify SKILL.md has required frontmatter (name, description)
- Check permissions in opencode.json
Migration from Previous Version
If you previously installed this package with the old tool names:
# Remove old tools
rm ~/.config/opencode/tools/anchor-{search,ingest}.ts
# Remove old command
rm ~/.config/opencode/commands/analyze.md
# Re-run setup
./setup.sh
Development
Tools are loaded from the repo root. After making changes:
- Save your changes
- Restart Opencode to reload the tools
License
MIT