segment-users
Read your database schema, generate queries for every behavioral segment, and give you the exact action to take with each group. No analytics platform required.
Phase 1: Read the Schema
Check the codebase for the user model. The signals you need:
- Usage metric — What counts as activity? Credits consumed, API calls, generations, logins, content created. Find the field.
- Timestamps —
created_at,last_active_at,last_login_at. Any date fields on the user. - Plan / billing — Free vs paid, plan name, subscription status.
- ORM — Prisma, Drizzle, Mongoose, raw SQL? Match your output to what's already in the codebase.
If any of the three signals are missing (usage, timestamps, plan), tell the user before generating queries. Don't fabricate fields that don't exist in the schema.
Phase 2: Define the Segments
Use whatever signals are available. Don't force a segment if the data isn't there.
Usage-Based (requires usage metric)
Power Users — top 10% by usage. These people love the product. Treat them differently than everyone else.
Active — used in the last 7 days, above median usage.
Casual — used in the last 30 days, below median usage.
Dormant — no usage in 7–30 days. The clock is ticking.
Churned — no usage in 30+ days. Harder to recover, not impossible.
Lifecycle (requires created_at)
New — signed up < 7 days ago. Haven't formed a habit yet.
Onboarding — 7–14 days, hasn't hit the "aha moment" (define this as hitting a specific usage threshold based on the product).
Established — 14–60 days, regular usage pattern.
Veteran — 60+ days, consistent activity. The most valuable free-tier users.
Revenue (requires plan data)
Free Tier — never paid.
Paying — active subscription or purchased credits.
At Risk — paying but usage declining in the last 14 days. The most urgent segment.
Churned Paid — was paying, subscription ended. Revenue already lost.
Phase 3: Generate the Queries
For each applicable segment, generate both SQL and ORM. Adapt to the actual schema — no placeholder column names.
-- Power Users: top 10% by credits consumed
SELECT *, (initial_credits - credits) AS credits_used
FROM users
ORDER BY credits_used DESC
LIMIT (SELECT COUNT(*) / 10 FROM users);
-- Dormant: was active, silent for 7-30 days
SELECT * FROM users
WHERE last_active_at < NOW() - INTERVAL '7 days'
AND last_active_at > NOW() - INTERVAL '30 days';
-- At Risk: paying user, usage dropped below half their average
SELECT * FROM users
WHERE plan != 'free'
AND (initial_credits - credits) < (
SELECT AVG(initial_credits - credits) * 0.5
FROM users WHERE plan != 'free'
);
// Prisma: dormant users
const dormant = await prisma.user.findMany({
where: {
lastActiveAt: {
lt: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
gt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
},
},
});
Always include a count query so the user can see the full distribution immediately:
SELECT 'power_users' AS segment, COUNT(*) AS count FROM users WHERE ...
UNION ALL
SELECT 'active' AS segment, COUNT(*) AS count FROM users WHERE ...
UNION ALL
SELECT 'dormant' AS segment, COUNT(*) AS count FROM users WHERE ...
UNION ALL
SELECT 'churned' AS segment, COUNT(*) AS count FROM users WHERE ...
Phase 4: Recommend Actions
One action per segment. Concrete, not vague.
Power Users — upgrade offer or exclusive early access. They're already bought in. A personal email from the founder converts here better than any automated campaign.
Active — surface features they haven't used. In-app tooltip or email with one specific feature. Don't pitch; educate.
Casual — re-engage with the one thing they got value from. Remind them what worked.
Dormant — win-back email. One specific hook: what's changed, what's new. Not "we miss you."
Churned — short survey, then an incentive. Find out why before trying to recover them.
New — onboarding sequence. Define the "aha moment" threshold and build the first 3 days around reaching it.
At Risk — personal outreach before cancellation. A direct message from a human beats automation here.
Phase 5: Output Format
Print distribution, then queries, then actions.
USER SEGMENTS — [project name]
════════════════════════════════════
CURRENT DISTRIBUTION
────────────────────────────────────
Power Users: [N] users ([X]%)
Active: [N] users ([X]%)
Casual: [N] users ([X]%)
Dormant: [N] users ([X]%)
Churned: [N] users ([X]%)
────────────────────────────────────
Total: [N] users
════════════════════════════════════
If /ship-email is installed, offer to generate email templates for each segment after the queries.
Verify
[ ] User model read from codebase — no invented fields
[ ] Usage metric identified and defined
[ ] Only segments with available signals generated
[ ] SQL + ORM queries output for each segment
[ ] Count queries included so distribution is visible
[ ] At Risk segment flagged if any paying users exist
[ ] Action recommendation per segment — specific, not generic
[ ] All column names in queries match the actual schema
See references/guide.md for RFM scoring, cohort retention analysis, and churn prediction patterns.
More from tushaarmehtaa/tushar-skills
ship-credits
Scaffold a complete credits/token metering system for any app — database schema, backend middleware, payment webhooks, frontend state, and UI components. Goes from zero to "users can buy and spend credits" in one session.
17deploy-check
Pre-flight check before pushing to production. Catches TypeScript errors, accidentally staged secrets, pending migrations, and hygiene gaps before they hit live users.
6ship-email
Scaffold transactional and campaign email infrastructure end-to-end — provider setup, templates, user segmentation, and admin send UI. Use when the user wants to add email to their app — welcome emails, notifications, re-engagement, or bulk campaigns. Triggers on requests like "add email", "set up Resend", "email campaigns", "transactional email", "send emails to users", "welcome email", "notification emails", or any mention of email sending in an app context.
6make-skill
Turn any workflow into a properly structured Claude Code skill — YAML frontmatter, phase-based instructions, real code blocks, and a verify checklist. Use when the user wants to package a repeated workflow, create a new skill, turn a process into a slash command, or publish to the skills directory. Triggers on requests like "make a skill", "create a skill", "turn this into a skill", "new skill for...", "package this as a skill", "build a skill", "I want to publish a skill", "help me write a skill", or any request to create a reusable Claude Code skill.
6mvp-spec
Turn a rough product idea into a structured MVP spec — problem statement, personas, core loop, feature split, data model, API routes, page list, and tech stack recommendation. Write this before touching any code. Triggers on requests like "spec this out", "MVP spec", "plan this product", "what should I build first", "scope this idea", "PRD", "product spec", "write a spec for...", "help me plan this", "what do I build in v1", "product requirements", or any request to structure a product idea before writing code.
6og-image
Set up dynamic Open Graph image generation and all required meta tags so links look professional when shared on Twitter/X, LinkedIn, Slack, or anywhere that renders link previews. Triggers on requests like "OG image", "open graph", "social preview", "link preview", "Twitter card", "meta tags for sharing", "my links look broken when I share them", or any mention of how links appear when shared on social media.
6