context-mod-devvit
A rule-engine moderation bot for Reddit subreddits, running natively on Devvit.
Write your moderation rules once in JSON5. The rule engine (8 rule kinds incl. Phase 4.7 perceptual-blockhash image-repost), 8 action handlers (remove · approve · lock · comment · report · ban · userFlair · distinguish), atomic config publish, dry-run rule tester, AI rule explainer, AI event summary w/ 24h response cache, mod activity feed, config-diff viewer, mute/unmute, full mod-auth gating + per-sub + per-user rate-limiting + circuit-breaker on AI calls, per-event run isolation + wall-clock timeouts, light-mode toggle, and Observatory dashboard all ship live in v0.6.7. Mods install ContextMod once, define what counts as spam / what to remove / what to comment / what users to ban, and the bot handles the rest.
Devvit Web port of ContextMod: FoxxMD's flagship moderation bot, originally built on PRAW and now ported to Reddit's first-party developer platform.
Built for the Reddit Mod Tools and Migrated Apps Hackathon (Apr 29 – May 27, 2026). Ported with explicit written permission from FoxxMD via github.com/FoxxMD/context-mod#152.
Why a port? The original ContextMod requires you to host a server, manage API tokens, and trust a centralized instance. Devvit's per-subreddit install model removes all three. Every mod team installs their own instance with one click: no infrastructure, no shared rate limits, no central bottleneck.
What it does
ContextMod evaluates new posts and comments against a flexible, mod-defined rule engine and takes moderation actions when checks trigger. Each rule + action set is defined in a JSON5 config (loaded from your sub's wiki), composable with named rules, filters, and Mustache-templated action messages.
The Devvit port preserves the rule/check/action concept model that 15+ existing CM operator communities already know (deployments range from 10K to 1M+ subscribers across general-interest and NSFW subs), while solving the central-server bottleneck that capped CM's adoption on the original PRAW infrastructure. With Devvit's per-subreddit install model, every mod team can install their own instance.
Note on community attribution: per FoxxMD's Discord guidance 2026-05-20, mod-tool documentation deliberately avoids naming specific subreddits or moderators using ContextMod. The asymmetric nature of spam-fighting means revealing the toolset to adversaries shifts the balance away from defenders. Operator counts are kept aggregate.
Quick start (for moderators)

- Install: Visit developers.reddit.com/apps/cm-devvit and click Add to community, then pick your subreddit (you must be a mod with
posts + wiki permissions).
- Pin the dashboard: In your sub's mod overflow menu, click ContextMod: View recent actions. A custom post appears that shows mod-action telemetry, live data from the
events:recent50 ZSET (Phase 3 shipped). Stickying it is optional but recommended.
- Write your rules: Create
r/<your-sub>/wiki/botconfig/contextmod with JSON5 config. A starter config is seeded on install; the examples/ directory carries 12 working configs (starter + spam-fresh + approve-trusted + comment-mod-banned + repost-watch + low-karma-banned + named-rules-flair + nsfw-strict + Phase 4 history/attribution/recentActivity + Phase 4.7 image-repost) you can paste and edit. See Config schema for the full surface.
- Reload: In the subreddit mod overflow, click ContextMod: Reload config from wiki (or wait 5 minutes, the app polls automatically). Toast shows the rule count; the Observatory dashboard refreshes with the next rule firing.
- Test a rule: Right-click any post or comment, choose ContextMod: Test rules on this item. A dry-run shows which rules would fire without taking action.
No hosting. No tokens. No central bottleneck. Everything lives inside your subreddit's Devvit installation.
Moderator permissions and data access
ContextMod is a moderator-only tool. Every surface that shows moderation data or performs a moderation action is gated on the caller being a moderator of the subreddit, verified server-side against Reddit's live moderator list (reddit.getModerators()) on every request, not just by the menu's forUserType. This section is the "who can see and do what" contract for any subreddit installing the app.
Menu items. All six mod-menu entries (Reload config, View recent actions, Test rules, Simulate rule, Explain rule with AI, Set OpenAI API key) declare "forUserType": "moderator" in devvit.json, so non-moderators never see them in the menu.
Server-side verification (defense in depth). The Observatory custom post is a webview, and its server endpoints are HTTP-reachable by anyone who can open the post, not only by the mod who clicked a menu item. So forUserType alone is not a security boundary. Every endpoint that returns mod data or performs an action calls requireModerator() before doing any work. The dashboard data and action API replies 403; the menu and form handlers reply with a "Mod-only action" toast (the Devvit response shape they require). In both cases the work never runs for a non-moderator.
| Surface |
Endpoint(s) |
Gate |
| Recent actions feed |
GET /api/recent |
requireModerator |
| Stats counters |
GET /api/stats |
requireModerator |
| Mod-activity feed |
GET /api/mod-activity |
requireModerator |
| Config revision history |
GET /api/config-history |
requireModerator |
| Muted rules (read + mutate) |
GET /api/muted-rules, POST /api/mute-rule, POST /api/unmute-rule |
requireModerator |
| AI event explainer |
POST /api/explain-event |
requireModerator |
| Config editor |
GET /api/config/raw, POST /api/config/{validate,simulate-live,explain,save} |
requireModerator |
| Mod menu actions + forms |
POST /internal/menu/*, POST /internal/form/* |
requireModerator |
A non-moderator who opens the Observatory post sees a "Moderators only" notice, never moderation data.
Permission granularity (documented exception). The gate is "is a moderator of this subreddit." ContextMod does not distinguish granular Reddit moderator permissions (wiki, config, posts, flair, and so on): any moderator can view the telemetry and edit the rule config through the app. This is intentional. ContextMod's wiki config is the bot's control surface, managed by the moderator team as a whole, the same way AutoModerator's config is. The in-app editor writes the config wiki page on behalf of any moderator using the app's moderator scope. If your team needs to restrict who changes the bot's behavior, use Reddit's native moderator permissions plus your team's own process.
Exceptions to the mod gate (and why they are safe).
GET /api/health is an unauthenticated liveness probe. It returns only {ok, app name, version, timestamp}: no moderation data, no Redis access. The dashboard's reload button and external uptime checks use it. GET /api/health/deep (which does touch Redis and Reddit context) IS mod-gated.
?demo=1 on the read endpoints returns clearly-synthetic fixtures (demo_mod_alice, and so on) so the dashboard can be demoed without a live install. Real subreddit data is never served on the demo path.
/internal/triggers/* and /internal/cron/* are invoked by the Devvit platform (event triggers and schedulers), not by users, so they are not part of the moderator-facing surface.
Data isolation. Each install runs in its own Devvit Redis namespace, so one subreddit's moderation data is never visible to another.
Try locally in 3 commands (for judges + devs)
See the Observatory dashboard render without installing the app, no Devvit credentials needed:
git clone https://github.com/StephenSook/context-mod-devvit.git
cd context-mod-devvit
npm ci && npm run dev:web
Then open http://localhost:5173/?demo=1. The ?demo=1 query parameter seeds the dashboard with synthetic events (per the production-safety pattern: fabricated data never auto-shows). Remove the flag to see the empty-state with a copy-to-clipboard starter config.
The dev:web script chains vite build → node scripts/dev/mock-server.cjs. The mock server is pure Node stdlib (no Express, no extra deps) and binds 127.0.0.1 only: local loopback, no LAN exposure.
To stop: Ctrl-C in the terminal running npm run dev:web.
Status
Phase 0–4 + 4.7 all shipped. Rule engine, 8 action handlers (remove / approve / lock / comment / report / ban / userFlair / distinguish), atomic wiki-config publish, dry-run rule tester, AI explainer + event summary, hard-mute, config-diff viewer, mod activity feed, mobile-responsive Observatory dashboard, Phase 4 history-aware rules (history / attribution / recentActivity), Phase 4.7 perceptual-blockhash image-repost.
Production health (verified 2026-05-19): 828 tests passing · tsc --build clean · npm run lint clean · production npm audit 0 vulnerabilities · CI green across 8 jobs (validate Node 20/22/24 + ai-tone + Playwright chromium/firefox/webkit + CodeQL + Semgrep + axe-core + dependency-cruiser + release-drafter). Lighthouse CLI v13.3.0: Performance 84 · Accessibility 100 · Best Practices 100 · CLS 0.04 (good) · TBT 0 ms.
Cut + deferred: MHS (ModerateHateSpeech HTTP fetch) cut per Reddit PR #96 (2026-05-08). The HTTP fetch policy AI-provider allowlist excludes ModerateHateSpeech. Subs using upstream CM for hate-speech filtering keep running the original PRAW build.
For phase-by-phase ship state, per-component readiness, hardening-wave detail, and the full
cut + deferred list, see docs/STATUS.md. For the team-coordination plan
Observatory dashboard preview

Captured 2026-05-14 via Playwright against the mock-server-backed ?demo=1 build. Production now renders the same chrome over real events:recent50 ZSET data (Phase 1+2+3 shipped 2026-05-16). ?demo=1 remains for screenshots + demo capture without depending on a live test sub.
Architecture