Implementation:0xranx OpenContext SyncAgentsArtifacts
| Knowledge Sources | |
|---|---|
| Domains | Developer_Tools, Agent_Integration |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for synchronizing OpenContext instructions, slash commands, skills, and MCP configuration to AI coding agents (Cursor, Claude Code, Codex).
Description
The syncAgentsArtifacts function is the top-level orchestrator for agent integration. It calls five sub-functions in sequence:
- ensureGlobalArtifacts: Writes the global `AGENTS.md` file to `~/.opencontext/agents/AGENTS.md` with OpenContext usage instructions.
- ensureUserCommands: Writes 5 slash command definitions to each selected agent's commands directory.
- ensureUserSkills: Writes the same 5 commands as skill files (with SKILL.md format) to each agent's skills directory.
- ensureUserMcpConfigs: Upserts the MCP server config (`{ command: 'oc', args: ['mcp'] }`) into each agent's `mcp.json`.
- ensureProjectArtifacts: Injects the project-level AGENTS.md block using marker-based replacement.
All operations are idempotent: files are only written if their content has changed (`writeFileIfChanged`), and MCP configs are upserted only if the server entry differs.
The five slash commands are: `opencontext-help`, `opencontext-context`, `opencontext-search`, `opencontext-create`, `opencontext-iterate`.
Usage
- Agent Integration Setup: Called by `oc init` to set up all agent integrations.
- Re-sync: Can be called multiple times to update configurations after changes.
- Tool selection: Pass `{ cursor: true, claude: true, codex: false }` to skip specific agents.
Code Reference
Source Location
- Repository: OpenContext
- File: src/core/agents.js
Signature
/**
* Sync all agent artifacts (global instructions, commands, skills, MCP, project AGENTS.md)
* @param {string} projectRoot - Project root directory
* @param {Object} options
* @param {{ cursor?: boolean, claude?: boolean, codex?: boolean }} options.tools - Tool selection
* @returns {string[]} Array of file paths written/updated
*/
function syncAgentsArtifacts(projectRoot, options = {}) {
const outputs = [];
outputs.push(...ensureGlobalArtifacts());
outputs.push(...ensureUserCommands(options.tools));
outputs.push(...ensureUserSkills(options.tools));
outputs.push(...ensureUserMcpConfigs(options.tools));
outputs.push(...ensureProjectArtifacts(projectRoot));
return outputs;
}
Import
const { syncAgentsArtifacts } = require('./core/agents');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| projectRoot | string | Yes | Project root directory path |
| options.tools | Object | No | Tool selection: { cursor, claude, codex } (all default true) |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | string[] | Array of file paths that were written or updated |
Output Paths
| Artifact | Cursor Path | Claude Path | Codex Path |
|---|---|---|---|
| Global AGENTS.md | ~/.opencontext/agents/AGENTS.md | (same) | (same) |
| Commands | ~/.cursor/commands/*.md | ~/.claude/commands/*.md | — |
| Skills | ~/.cursor/skills/*/SKILL.md | ~/.claude/skills/*/SKILL.md | ~/.codex/skills/*/SKILL.md |
| MCP config | ~/.cursor/mcp.json | ~/.claude/mcp.json | ~/.codex/mcp.json |
| Project AGENTS.md | <projectRoot>/AGENTS.md | (same) | (same) |
Usage Examples
Full Sync (JavaScript)
const { syncAgentsArtifacts } = require('./core/agents');
const outputs = syncAgentsArtifacts(process.cwd(), {
tools: { cursor: true, claude: true, codex: true }
});
outputs.forEach(path => console.log(`Updated: ${path}`));
Sync for Cursor Only
const outputs = syncAgentsArtifacts(process.cwd(), {
tools: { cursor: true, claude: false, codex: false }
});
CLI Usage
# Sync all agents
oc init
# Skip Cursor
oc init --no-cursor
# Only Claude
oc init --no-cursor --no-codex