Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0xranx OpenContext Agent Integration

From Leeroopedia
Knowledge Sources
Domains Developer_Tools, AI_Agents
Last Updated 2026-10-24 12:00 GMT

Overview

A pattern for integrating knowledge base tools into AI coding agents by syncing instruction files, slash commands, skills, and MCP server configuration to the agent's configuration directories.

Description

Agent integration addresses the challenge that AI coding agents (Cursor, Claude Code, Codex) need to discover and use external tools. Each agent has its own configuration format and directory structure, making manual integration tedious and error-prone.

The integration pattern synchronizes four types of artifacts:

  • Global Agent Instructions (AGENTS.md): Written to `~/.opencontext/agents/AGENTS.md`, this file teaches agents how to use OpenContext commands (folder listing, search, manifest, doc creation).
  • Project Agent Instructions: Written to `<projectRoot>/AGENTS.md` using marker-based block replacement (`...`), preserving any existing content outside the block.
  • Slash Commands: Five command definitions (help, context, search, create, iterate) are written to each agent's commands directory (e.g., `~/.cursor/commands/`, `~/.claude/commands/`).
  • Skills: The same command definitions are formatted as skill files in each agent's skills directory.
  • MCP Configuration: The MCP server configuration (`{ command: 'oc', args: ['mcp'] }`) is inserted into each agent's `mcp.json` file.

The idempotent sync pattern ensures that running the integration multiple times produces the same result: files are only written if their content has changed, and MCP configs are upserted (updated if existing, inserted if new).

Usage

Use this principle when setting up an AI coding agent to work with a knowledge base. The integration should be run once per agent (via `oc init`) and can be safely re-run to update configurations. Tool selection allows enabling only specific agents (e.g., `--no-cursor` to skip Cursor).

Theoretical Basis

The integration follows a declarative sync model:

Pseudo-code Logic:

# Abstract algorithm (NOT real implementation)
def sync_agent_artifacts(project_root, tools_selection):
    outputs = []

    # 1. Write global AGENTS.md (idempotent)
    if write_if_changed(GLOBAL_AGENTS_PATH, agents_template()):
        outputs.append(GLOBAL_AGENTS_PATH)

    # 2. Write slash commands for each selected tool
    for tool in ["cursor", "claude", "codex"]:
        if tools_selection[tool]:
            for cmd in COMMAND_DEFS:
                path = f"~/.{tool}/commands/{cmd.name}.md"
                if write_if_changed(path, format_command(cmd, tool)):
                    outputs.append(path)

    # 3. Write skills for each selected tool
    for tool in ["cursor", "claude", "codex"]:
        if tools_selection[tool]:
            for cmd in COMMAND_DEFS:
                path = f"~/.{tool}/skills/{cmd.name}/SKILL.md"
                if write_if_changed(path, format_skill(cmd)):
                    outputs.append(path)

    # 4. Upsert MCP config for each selected tool
    for tool in ["cursor", "claude", "codex"]:
        if tools_selection[tool]:
            mcp_path = f"~/.{tool}/mcp.json"
            if upsert_mcp_config(mcp_path, "opencontext", {"command": "oc", "args": ["mcp"]}):
                outputs.append(mcp_path)

    # 5. Inject project AGENTS.md (marker-based block replacement)
    if upsert_block_in_file(f"{project_root}/AGENTS.md", project_agents_template()):
        outputs.append(f"{project_root}/AGENTS.md")

    return outputs

Marker-Based Block Replacement

The project AGENTS.md uses markers to avoid destroying existing content:

<!-- OPENCONTEXT:START -->
... OpenContext instructions ...
<!-- OPENCONTEXT:END -->

When the file already exists with markers, only the block between markers is replaced. If markers are missing, the block is appended. This makes the operation safe to re-run.

Practical Guide

  • Run `oc init`: The CLI command handles the full integration flow with interactive tool selection.
  • Tool selection: Use `--tools cursor,claude` or `--no-codex` to control which agents get configured.
  • Re-running is safe: All operations are idempotent — files are only written if content changed.
  • Project vs global: Global instructions go to `~/.opencontext/agents/AGENTS.md`; project instructions go to `<projectRoot>/AGENTS.md`.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment