Augment opencode with a memory
  • TypeScript 86.3%
  • Shell 12.9%
  • JavaScript 0.8%
Find a file
2026-03-12 07:03:16 +01:00
commands change nomenclature 2026-03-12 00:57:57 +01:00
skills/repo-analysis change nomenclature 2026-03-12 00:57:57 +01:00
tests change nomenclature 2026-03-12 00:57:57 +01:00
tools change nomenclature 2026-03-12 00:57:57 +01:00
.gitignore initial ready to test 2026-03-11 23:53:29 +01:00
jest.config.js works locally 2026-03-11 18:49:34 +01:00
MEMORY_INSTRUCTIONS.md change nomenclature 2026-03-12 00:57:57 +01:00
opencode-anchor-config.example.json change nomenclature 2026-03-12 00:57:57 +01:00
package-lock.json initial ready to test 2026-03-11 23:53:29 +01:00
package.json works locally 2026-03-11 18:49:34 +01:00
README.md added quickstart to docs 2026-03-12 07:03:16 +01:00
setup.sh change nomenclature 2026-03-12 00:57:57 +01:00
tsconfig.json change nomenclature 2026-03-12 00:57:57 +01:00

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

  1. Clone and navigate to the repository:

    git clone https://github.com/anomalyco/opencode-anchor.git
    cd opencode-anchor
    
  2. Run the setup script:

    ./setup.sh
    

    The 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/
  3. Configure Opencode instructions:

    Edit ~/.config/opencode/opencode.json and add:

    {
      "instructions": ["MEMORY_INSTRUCTIONS.md"]
    }
    

    See: https://opencode.ai/docs/rules/

  4. 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 all for 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

  1. Install dependencies:
npm install
  1. 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 (quick for key files only, deep for 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 language
  • limit: 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 rationale
    • pattern: Reusable patterns, best practices, conventions
    • documentation: API docs, README updates, verified references
    • troubleshooting: Bug fixes, root cause analysis, workarounds
    • reference: 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:

  1. Scans repository structure using repo-scanner
  2. Reads and analyzes documentation and code
  3. Remembers content with appropriate tags (Anchor Memory handles deduplication)

Tags applied:

  • repo-analysis - All analyzed content
  • analysis-quick or analysis-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 endpoint
  • searchRepoScoped: Limit searches to current repository
  • showConnectionWarnings: Warn when Anchor Memory is unavailable
  • tagCacheDuration: 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-auth not api 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: tag api might mean "authentication API endpoints"
  • In repo:payment-service: tag api might 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 quick or /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:

  1. Save your changes
  2. Restart Opencode to reload the tools

License

MIT