Kanel and Claude Code

Kanel and Claude Code. Kicking ass. I love Kanel and you should to if you ever work with Typescript, but now I can inform Claude Code (In CLAUDE.md) about my every schema change so that info is always in context with any requests I make!

I didn't include the script because it does get into my app's details a fair bit, however, this would be easy to customise with a similar prompt with Claude Code.

Re Kanel output, can we make that information something you don't have to scan over and over when I ask questions that might be related?

● Absolutely! There are a few ways we could make the database schema information more readily available without having to scan it repeatedly:

Option 1: Add Schema Overview to CLAUDE.md

I could read through the key schema files once and create a comprehensive database schema section in your CLAUDE.md file with:

  • Table relationships
  • Key entity descriptions
  • Important fields and types
  • Multi-tenant schema structure

Option 2: Create a Schema Summary Tool

I could create a utility script that:

  • Scans all the Kanel-generated types
  • Extracts key information about tables, relationships, and types
  • Generates a markdown summary file
  • Could be run periodically when schema changes

Option 3: Schema Context File

Create a dedicated database-schema.md file that I reference when needed, containing:

  • Entity relationship overview
  • Key business objects and their purposes
  • Important fields for common operations
  • Multi-tenant customer schema structure

Which approach would you prefer? I think Option 1 (adding to CLAUDE.md) might be most practical since it would always be available in context, but Option 3 gives more dedicated space for detailed schema documentation.

The goal would be to have this information readily available so when you ask schema-related questions, I already have the context loaded rather than scanning files each time.

How would you know to reference the database-schema.md?

● Good point! That's the challenge with Option 3. Here are the ways I could reference it:

How I'd Know to Reference It:

  1. When you explicitly mention it - "Check the database schema" or "look at the schema file"
  2. Context clues in your questions - When you ask about:
    - Database operations, queries, or types
    - Relationships between entities
    - Table structures or fields
    - Multi-tenant schema questions
  3. When working with generated types - If I see imports like #postgres-types/customer/ in code

The Problem:

Unlike CLAUDE.md (which is always in context), I'd have to actively decide to read the schema file, and I might not always think to do it.

Better Approach:

Option 1 (CLAUDE.md) is probably best because:

  • It's always available in my context automatically
  • No decision-making required about when to reference it
  • Keeps all project knowledge in one place
  • Gets loaded every time we work together

Would you like me to create a comprehensive database schema section in CLAUDE.md? I could:

  1. Read through the key Kanel-generated types
  2. Document the main entities, relationships, and multi-tenant structure
  3. Add it as a new section to your existing CLAUDE.md

This way the schema knowledge would always be available without me having to scan files or decide when to reference external documentation.

The script idea is best if it updates CLAUDE.md when Kanel is run. There is an existing cmd in the package.json

● Perfect! That's a much better approach - automatically updating CLAUDE.md when Kanel runs. Let me check the existing package.json command:

● Read(package.json)
⎿  Read 50 lines (ctrl+r to expand)

● Perfect! I can see the command is "get-postgres-types": "npx kanel" on line 8.

I'll create a script that:

  1. Reads all the Kanel-generated types from typescript/postgres/generated-types/
  2. Extracts key schema information (tables, relationships, important fields)
  3. Updates the CLAUDE.md file with a database schema section
  4. Modifies the package.json command to run this script after Kanel

● Write(util/update-schema-docs.mjs)
⎿  Wrote 181 lines to util/update-schema-docs.mjs
#!/usr/bin/env node
// update-schema-docs.mjs - Updates CLAUDE.md with database schema information
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const projectRoot = path.resolve(__dirname, '..');
… +171 lines (ctrl+r to expand)

● Now let me update the package.json to run this script after Kanel:

● Update(package.json)
⎿  Updated package.json with 1 addition and 1 removal
5      "main": "core.js",
6      "type": "module",
7      "scripts": {
8 -      "get-postgres-types": "npx kanel",
8 +      "get-postgres-types": "npx kanel && node util/update-schema-docs.mjs",
9        "tailwind:ejs": "postcss ./planner/public/styles/tailwind.css -o ./planner/public/styles/style.css",
10        "tw:app": "npx tailwindcss -c typescript/tailwind.config.all-ts.js -i tailwind-base.css -o ./planner/public/tailwind.css",
11        "watch:tw:app": "npx tailwindcss -c typescript/tailwind.config.all-ts.js -i tailwind-base.css -o ./planner/public/tailwind.css --watch",

● Perfect! Now let me test the script by running it to see how it works:

● Bash(node util/update-schema-docs.mjs)
⎿  🔍 Scanning database schema types...
📊 Found 66 tables across 6 schemas
✅ Updated CLAUDE.md with database schema documentation
… +1 line (ctrl+r to expand)

● Excellent! The script worked perfectly. Here's what I've created:

✅ Schema Documentation Automation

What it does:

  1. Scans all Kanel-generated types (found 66 tables across 6 schemas!)
  2. Extracts key information about tables and their purposes
  3. Automatically updates CLAUDE.md with comprehensive schema documentation
  4. Runs after every Kanel update via the modified get-postgres-types command

Features:

  • Auto-generated: Updates every time you run npm run get-postgres-types
  • Comprehensive: Covers all schemas (customer, events, public, pwaconfig, sales, support)
  • Organized: Groups tables by schema with descriptions
  • Key relationships: Documents important table relationships
  • Multi-tenant aware: Explains the customer schema structure
  • Timestamped: Shows when it was last generated

Now when you ask schema-related questions, I'll have:

  • Complete table listings for all 6 schemas
  • Understanding of multi-tenant structure
  • Key relationships between entities
  • Schema purposes and organization

The information is now permanently part of your CLAUDE.md context and will stay up-to-date automatically whenever you regenerate your database types!