Skip to content

chore: Add CLAUDE.md to register code standards with Claude agent#183

Open
morgan-wowk wants to merge 1 commit intomasterfrom
claude-rules
Open

chore: Add CLAUDE.md to register code standards with Claude agent#183
morgan-wowk wants to merge 1 commit intomasterfrom
claude-rules

Conversation

@morgan-wowk
Copy link
Collaborator

@morgan-wowk morgan-wowk commented Mar 20, 2026

TL;DR

Added coding conventions documentation for Python, SQLAlchemy, and data safety practices.

What changed?

Created CLAUDE.md file containing development guidelines including:

  • Python style requirements for f-string logging, keyword-only arguments, unused parameter naming, and StrEnum usage
  • SQLAlchemy best practices for schema metadata derivation, transaction management, and migration logging
  • Data safety rules prohibiting deletion of data files without confirmation

How to test?

No testing required - this is documentation only. Developers should reference these conventions when writing new code or reviewing pull requests.

Why make this change?

Establishes consistent coding standards across the repository to improve code quality, maintainability, and prevent data loss incidents during development.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@morgan-wowk morgan-wowk marked this pull request as ready for review March 20, 2026 19:14
@morgan-wowk morgan-wowk requested a review from Ark-kun as a code owner March 20, 2026 19:14
@morgan-wowk morgan-wowk requested a review from yuechao-qin March 20, 2026 19:14
CLAUDE.md Outdated

- **Derive schema metadata from models.** Never hardcode table names, column names, or column types as strings. Reference them from the SQLAlchemy model (e.g. `Model.__table__.c.column_name`) and compile types with `col.type.compile(dialect=engine.dialect)`.
- **Single transaction per logical operation.** Wrap all related DDL or DML mutations in one `with engine.connect() as conn` / `conn.commit()` block.
- **Log migrations.** Every migration step (ALTER TABLE, backfill, index creation) should log before it runs and handle `OperationalError` for concurrent deployments gracefully.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch errors and log them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion — updated the "Log migrations" rule to explicitly include catching and logging exceptions. Thanks!

- **f-strings for all logging.** Use `_logger.info(f"...")` — never `%s` interpolation.
- **Keyword-only arguments.** Add `*` to function definitions to make all parameters keyword-only, even when there is only one parameter.
- **Unused parameters.** Prefix unused function parameters with `_` (e.g. `_old_value`, `_initiator`) and add type hints to every parameter, used or not.
- **StrEnum for known string sets.** When a parameter or constant is drawn from a fixed set of strings, define a `StrEnum` for it rather than using bare string literals.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Type hinting function parameters
  • Import modules only except for exception of from typing import ...
  • python filenames should:
Style: Modules should be names as plural or uncountable nouns.
Example: database_migrations.py instead of database_migrate.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three added — type hints on every function parameter/return type, module-only imports (with the from typing import exception), and plural/uncountable noun file naming. Thanks for the detailed suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants