Skip to content

Programmatic API

Rulesync can be used as a library in your Node.js/TypeScript projects. The generate, importFromTool, and convertFromTool functions are available as named exports.

typescript
import { convertFromTool, generate, importFromTool } from "rulesync";

// Generate configurations
const result = await generate({
  targets: ["claudecode", "cursor"],
  features: ["rules", "mcp"],
});
console.log(`Generated ${result.rulesCount} rules, ${result.mcpCount} MCP configs`);

// Import existing tool configurations into .rulesync/
const importResult = await importFromTool({
  target: "claudecode",
  features: ["rules", "commands"],
});
console.log(`Imported ${importResult.rulesCount} rules`);

// Convert configurations between AI tools without writing intermediate .rulesync/ files
try {
  const convertResult = await convertFromTool({
    from: "claudecode",
    to: ["cursor", "copilot"],
    features: ["rules"],
  });
  console.log(`Converted ${convertResult.rulesCount} rule file(s)`);
} catch (error) {
  // Thrown when `from` is empty, `to` is empty, `to` includes `from`,
  // a source file cannot be parsed, or write fails.
  console.error("convert failed:", error);
}

generate(options?)

Generates configuration files for the specified targets and features.

OptionTypeDefaultDescription
targetsToolTarget[]from config fileTools to generate configurations for
featuresFeature[]from config fileFeatures to generate
outputRootsstring[][process.cwd()]Output root directories to generate files into
baseDirsstring[]Deprecated alias of outputRoots. Still accepted for backward compatibility; emits a one-shot deprecation warning. Will be removed in a future major release.
inputRootstringprocess.cwd()Directory containing the .rulesync/ source files. Output still goes to each outputRoots entry; only the input source root is redirected. Mirrors the CLI's --input-root.
configPathstringauto-detectedPath to rulesync.jsonc
verbosebooleanfalseEnable verbose logging
silentbooleantrueSuppress all output
deletebooleanfrom config fileDelete existing files before generating
globalbooleanfalseGenerate global (user scope) configurations
simulateCommandsbooleanfalseGenerate simulated commands
simulateSubagentsbooleanfalseGenerate simulated subagents
simulateSkillsbooleanfalseGenerate simulated skills
dryRunbooleanfalseShow changes without writing files
checkbooleanfalseExit with code 1 if files are not up to date

importFromTool(options)

Imports existing tool configurations into .rulesync/ directory.

OptionTypeDefaultDescription
targetToolTarget(required)Tool to import configurations from
featuresFeature[]from config fileFeatures to import
configPathstringauto-detectedPath to rulesync.jsonc
verbosebooleanfalseEnable verbose logging
silentbooleantrueSuppress all output
globalbooleanfalseImport global (user scope) configurations

convertFromTool(options)

Converts configuration files between AI tools without writing intermediate .rulesync/ files to disk.

OptionTypeDefaultDescription
fromToolTarget(required)Source tool to convert configurations from
toToolTarget[](required)Destination tools to convert to
featuresFeature[]["*"]Features to convert. Matches CLI behavior and overrides any features in rulesync.jsonc.
configPathstringauto-detectedPath to rulesync.jsonc
verbosebooleanfalseEnable verbose logging
silentbooleantrueSuppress all output
globalbooleanfalseConvert global (user scope) configurations
dryRunbooleanfalseShow changes without writing files

Released under the MIT License.