Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
Last active May 1, 2025 09:30
Show Gist options
  • Save keithrbennett/e01fa87018214acbdabefb5b1ccc483d to your computer and use it in GitHub Desktop.
Save keithrbennett/e01fa87018214acbdabefb5b1ccc483d to your computer and use it in GitHub Desktop.
Converts plain text Cursor AI rules separated by "\n====\n" to Cursor's settings.json expected format.
#!/usr/bin/env python
# Transforms Cursor rules written in text and plain text delimited by '\n====\n'
# into the JSON expected in the project root's .cursor/settings.json.
#
# This is a filter script that reads its input from stdin and writes it to stdout.
#
# For example, it could be run like this, from the project root:
#
# ai-rules-to-json < my-rules.txt > .cursor/settings.json
#
# where my-rules.txt contains (minus the comment characters):
#
# rule 1
# ====
# rule 2
#
# ai-rules-to-json < my-rules.txt # will output:
# {
# "ai.rules": [
# "rule 1",
# "rule 2"
# ]
# }
#
# The output is written to stdout, which you can redirect to a file or pipe to another command.
#
# Note that it is possible for your settings.json file to contain other settings, and that
# redirecting this script's output to .cursor/settings.json will replace all previous settings.
import sys
import json
# Read all input from stdin
content = sys.stdin.read()
# Split rules by delimiter and strip whitespace from each rule
rules = [rule.strip() for rule in content.split('\n====\n')]
# Prepare output dictionary
data = {"ai.rules": rules}
# Write JSON to stdout
json.dump(data, sys.stdout, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment