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
inputRootsstring[][<cwd>/.rulesync]Ordered list of rulesync source-tree directories (e.g. .rulesync, .rulesync.local). Each entry is a source tree itself — no .rulesync/ join is applied. The first root is required; later roots are optional overlays and may be absent. Output still goes to each outputRoots entry; only the input source root is redirected. Later entries override earlier ones for the same relative source path. Cannot be combined with inputRoot. Mirrors the CLI's --input-roots.
inputRootstringprocess.cwd()Deprecated. PARENT directory of a .rulesync/ source tree; kept as a backward-compatibility alias that expands internally to inputRoots: [join(inputRoot, ".rulesync")]. Prefer inputRoots and point it directly at your source tree(s). Cannot be combined with inputRoots. 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

Unreadable sources do not throw here. Unlike the CLI, which exits non-zero, generate() resolves and reports the problem on the result: sourceLoadFailed is true and sourceLoadFailedFeatures names the features whose .rulesync/ source could not be read. Their counts are 0, exactly like a feature that had nothing to write, so check the flag rather than the counts before treating a run as successful. (Those features also keep their existing generated files: delete skips their orphan sweep.)

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.