Skip to main content

byor: Build Your Own Rules

CI PyPI Python versions License

Custom code rules for the conventions your linter won't enforce.

byor lets you write the checks a general linter leaves out: rules specific to your team, your codebase, and your taste. It runs them in your editor, in CI, and inside your AI agent's loop as it writes.

The recommended practice for getting AI Agents to follow a styleguide is putting your standards in a markdown file (e.g. AGENTS.md or a skill). But, in practice, this is unreliable. byor exists because agents don't follow prose. If you set up byor as an agentic hook, it will send diagnostic messages whenever your agent breaks a rule, so the required correction is always in context.

byor is the sheepdog for your flock of coding agents: you set the rules, and it reins in any that stray, while the work is still happening.

A Simple Example

When I was recently reviewing code from codex, it was completely littered with pass-through wrappers: functions that existed to route arguments to other functions.

def get_user(user_id: int) -> User:
    return fetch_user(user_id)

Whether a pass-through wrapper is worth banning is a matter of taste, and personally I think they just make code harder to read. So I built a rule that bans writing code like this, and now my agents never commit the mistake again.

# .byor/rules/project/no-routing-functions.yml
# NOTE: this is a simplification of the full rule for the README
#       you can view the full rule here: examples/rules/no-routing-functions.yml
id: no-routing-functions
language: Python
severity: warning
message: A function whose only job is forwarding a call.
rule:
  kind: function_definition
  has:
    field: body
    has:
      kind: return_statement
      pattern: return $CALLEE($$$ARGS)
      all:
        - nthChild: 1
        - nthChild: { position: 1, reverse: true }
metadata:
  byor:
    agent_prompt: >
      Call the implementation directly, or give the function real behavior.
      Don't keep a pure pass-through.

You rarely write these by hand. Tell your agent the rule in plain language and it writes the check and will stress test and iterate with you to refine it.

Install

uv tool install byor --with-executables-from ast-grep-cli   # byor, plus ast-grep on PATH
byor install                                               # editor + agent integrations, once per machine

byor bundles ast-grep and finds it either way. --with-executables-from ast-grep-cli also puts it on your PATH, for the ast-grep scan and ast-grep lsp uses below.

The above commands will set up byor globally. After doing so, open up your coding agent and ask it to help set you up. It will likely read your markdown files for rules it can codify, as well as offer to run byor init if you would like to separate the rules of your repository from your global config.

Where rules run

A rule you write once runs in four places:

  • Editor: a diagnostic while you type (ast-grep lsp).
  • Terminal: ast-grep scan.
  • CI: committed rules run with plain ast-grep. byor init --gate creates the .github workflow.
  • AI agents: a post-edit hook corrects each edit as it lands, and a pre-command gate corrects shell commands before they run, scoped to what changed.

What a rule can be

Kind Catches Example
ast-grep rule a call, import, or code structure like the wrapper above no-requests · no-routing-functions
Check whatever a linter, type checker, or script decides dependency-gate
Command a shell command, before it runs no-pip-install

Every example runs in CI. More in examples/ and docs/rules.md.

Scopes

A rule can be yours alone or committed for the whole team. Committing it turns a preference into a standard: the rule is version-controlled, reviewed like any other change, and applied the same way for everyone, human or agent.

Scope Lives in Shared with
project .byor/rules/project/ Your team (committed)
local .byor/rules/personal/local/ You, this repo
global ~/.config/byor/rules/ You, every repo

A project or local rule overrides a global rule with the same ID. Command rules follow the same scopes under .byor/commands/. Packages and profiles tune which rules apply where; see docs/rules.md.

AI agents

Another Quick Example

Agents are good at making an error disappear instead of fixing them. I ran into this a lot with pre-commit hooks. There would be a large number of errors it would have to resolve, and it would resolve many, but often would choose to silence some.

Moving from pre-commit to byor hooks improved this because the agent wouldn't get lazy as a function of having so many diagnostics at once. However, it didn't solve the problem. Luckily, we can create rules that tell the agent not to silence!

# .byor/rules/project/no-type-suppression.yml
# NOTE: you may need to adapt the comment regex depending on the type checker
id: no-type-suppression
language: Python
severity: error
message: Don't silence the type checker. Fix the type.
rule:
  any:
    - pattern: cast($TYPE, $VALUE)
    - kind: comment
      regex: '#\s*type:\s*ignore'
metadata:
  byor:
    agent_prompt: >
      Silencing a type checker is a last resort, and only acceptable when 
      the type system genuinely cannot express a shape. Prioritize fixing 
      the issue at the signature if you can do so without `Any` or `object`.
      Be open to resolving the issue by modifying other methods or redesigning
      the interface in a way that is still consistent with the implementation.
      If this is a rare case where you need a cast, ask for approval to do so.
      Upon approval, silence both the type checker and ast-grep, leaving a comment
      to explain why this particular case requires the exception.

The post-edit hook feeds that back the moment the agent writes the suppression, so it fixes the type instead of hiding it.

Install Agentic Hooks

byor install --agents claude-code,codex
byor hook install --agent copilot     # add one later
Harness Post-edit hook Pre-command gate
Claude Code PostToolUse PreToolUse
Codex PostToolUse PreToolUse
Copilot CLI postToolUse preToolUse
OpenCode plugin not yet
Pi extension not yet

Cursor and Antigravity expose no reliable post-edit hook, so byor omits them. Details in docs/ai-agents.md.

Commands

Setup

byor install   register byor's editor + agent integrations (machine-wide)
byor init      set up byor in a repository (docs/sync-model.md)
byor hook      add or remove one agent integration
byor doctor    check that everything is wired up
byor profile   list or apply exclusion profiles
byor package   list, install or remove opt-in rule bundles

Rule Management

These are mostly run by your agent as it captures feedback (docs/rules.md):

byor add       create a rule (--command for a command rule)
byor list      show rules and where they resolve from
byor edit      open a rule in $EDITOR
byor remove    delete a rule
byor promote   move a personal or package rule into shared config
byor exclude   turn off a global rule in this repo
byor include   turn a previously excluded rule back on

byor runs the rest itself: byor agent-check (the post-edit hook), byor command-check (the pre-command gate), and byor sync (mirror global rules into a repo). Every command takes --help; repo commands take --repo PATH.

Documentation

Metadata

Release files for byor 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for byor 0.5.1
File Size Uploaded Provenance Actions
byor-0.5.1.tar.gz 139.4 kB With provenance Details for byor-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for byor 0.5.1
File Interpreter ABI Platform Actions
byor-0.5.1-py3-none-any.whl Python 3 none any Details for byor-0.5.1-py3-none-any.whl

Total release size: 302.5 kB

Release files / byor-0.5.1.tar.gz

Download URL byor-0.5.1.tar.gz
Size 139.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f76a9ed7f7f0effb1c0cd5a0197ee630a345ea9db1dd99e7dd10dfbf3696372c
BLAKE2b-256 checksum
How to use checksums
1107a9f2ac5d6d595aaad2a8ce8088f1dbe303263c77c55cbf6b8b5c454051e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / byor-0.5.1-py3-none-any.whl

Download URL byor-0.5.1-py3-none-any.whl
Size 163.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9984e5e9ffb358e90d7a82362ebf925618b70377039a2b9129dfec1925c56b6
BLAKE2b-256 checksum
How to use checksums
f6bfc041f4af5c565fe378e6d034c3eddafc461f2bf2071d8e424db47ea6e221
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for byor 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for byor-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page