Official agent skill

Using Redis Token Buckets

by PostHog in PostHog/posthog-foss

A skill your agent uses when adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill, a refund path for requests that did no work, or a limit…

OfficialMITAuto-check passedDatabases

Install Using Redis Token Buckets

skills CLI
$ npx skills add PostHog/posthog-foss --skill using-redis-token-buckets -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install PostHog/posthog-foss using-redis-token-buckets --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/PostHog/posthog-foss.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/using-redis-token-buckets .claude/skills/using-redis-token-buckets && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
using-redis-token-buckets
GitHub stars
721
Token cost
~1.6k tokens
SKILL.md length
669 words
Files
1
Skills in repo
213
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill, a refund path for requests that did no work, or a limit…

  • Adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill
  • SKILL.md covers Use this skill when, When NOT to use it, limits (vendored library) vs… and The API, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • A refund path for requests that did no work

What it does

Using Redis Token Buckets is an agent skill from PostHog/posthog-foss, published by the product's own GitHub organization. Use when adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill, a refund path for requests that did no work, or a limit whose Retry-After must be a real wait rather than a window edge. posthog/tokenbucket.py provides an atomic Lua token bucket (consume, refund, peek) over posthog.redis.getclient(). Choose it over DRF SimpleRateThrottle/fixed-window cache counters when boundary bursts, top-of-window lockouts, or charge-then-refund semantics matter. Trigger…

Its SKILL.md is about 1.6k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering Rate limiting. It works with Redis, PostHog and Lua. The repository describes itself as: PostHog FOSS is a read-only mirror of PostHog, with all proprietary code removed. NOTE: This repo is synced automatically from the main PostHog repo. Please raise any issues and… The licence is MIT.

When your agent uses it

  • Adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill
  • A refund path for requests that did no work
  • A limit whose Retry-After must be a real wait rather than a window edge
  • Terms: token bucket

Example prompts

  • “/using-redis-token-buckets”

Requirements

  • Python 3

What it can do on your machine

Read from SKILL.md and the folder at commit 2c48221. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are python).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • limits.readthedocs.io

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Using Redis Token Buckets loads about 1.6k tokens when it runs. Until then it costs about 162 tokens; SKILL.md has 669 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~162
When it runs · the whole SKILL.md, loaded when a task matches
~1.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from PostHog/posthog-foss at commit 2c48221, republished under its MIT licence (© PostHog). 669 words, ~1,628 tokens.

Download SKILL.mdSave it as .claude/skills/using-redis-token-buckets/SKILL.md (or your agent's skills folder).
name
using-redis-token-buckets
description
Use when adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill, a refund path for requests that did no work, or a limit whose Retry-After must be a real wait rather than a window edge. `posthog/token_bucket.py` provides an atomic Lua token bucket (`consume`, `refund`, `peek`) over `posthog.redis.get_client()`. Choose it over DRF `SimpleRateThrottle`/fixed-window cache counters when boundary bursts, top-of-window lockouts, or charge-then-refund semantics matter. Trigger terms: token bucket, rate limit, burst, refill, quota, Retry-After, fixed window, throttle.

Using Redis token buckets

posthog/token_bucket.py is the repo's primitive for bucket-like limits in Redis. A bucket holds up to burst tokens and refills continuously at per_hour / 3600 tokens per second. Every operation is atomic (a server-side Lua script), so concurrent web workers cannot double-spend a token.

Use this skill when

  • Adding a rate limit where callers legitimately burst but must be capped on sustained rate
  • A limit needs a refund path: charge on entry, give the token back when the request provably did no work
  • Retry-After must be the real per-caller wait for the next token, not "seconds until the top of the hour"
  • Replacing a fixed-window cache counter that suffers 2x boundary bursts or full-window lockouts
  • Exposing RateLimit-Limit/Remaining/Reset headers or a quota introspection endpoint (use peek)

When NOT to use it

  • Per-IP or per-user request throttling on ordinary DRF endpoints: subclass the existing throttles in posthog/rate_limit.py (IPThrottle, UserRateThrottle, PersonalApiKeyRateThrottle). They integrate with DRF's lifecycle and the RATE_LIMIT_ENABLED instance setting.
  • Outbound third-party API calls: use posthog/egress/ and its limits-library sliding-window limiter (posthog/egress/limiter/), which carries priorities and degraded fallbacks. /routing-outbound-api-calls covers the route.
  • Hard quotas that must survive a Redis flush: a bucket is best-effort (eviction or failover hands the caller a fresh budget). Pair it with a durable Postgres count for the few operations where that matters, and treat the bucket as the fast path.
  • Concurrency caps (how many at once, not how often): see the sorted-set gate in posthog/clickhouse/client/limit.py.

limits (vendored library) vs this module

The repo also vendors the limits library (used by posthog/egress/limiter/backends.py). Pick by the semantics you need, not by familiarity:

  • Use limits when a plain window answers the question "no more than N per window" and nothing ever needs to be un-counted. Its MovingWindowRateLimiter/SlidingWindowCounterRateLimiter strategies avoid fixed-window boundary bursts, its RedisStorage runs its own Lua so hits are atomic, and test()/get_window_stats() cover peeking and remaining/reset. For outbound third-party calls specifically, don't use it directly; go through posthog/egress/, which wraps it with priorities and a degraded in-memory fallback.
  • Use this module when you need what limits cannot express: a token bucket (independent burst capacity and refill rate), a refund path (its API is hit/test/get_window_stats/clear; there is no way to give a hit back), a Retry-After that is the wait for the next token rather than the window edge, or variable per-request cost.

A custom script is the de-facto token-bucket implementation on stock Redis (no native rate-limit command; the redis-cell module is not deployed), and limits runs its own Lua anyway, so neither choice avoids Lua.

Show full SKILL.md (250 more words)Show less

The API

python
from posthog.token_bucket import Budget, BucketDecision, BucketUnavailable, consume, peek, refund

BUDGET = Budget(burst=30, per_hour=120)  # capacity 30, refills one token every 30s

decision = consume(f"myfeature_rate:{team_id}", BUDGET)
match decision:
    case BucketUnavailable():
        ...  # Redis can't answer: usually fail open; fall through to a durable check if you have one
    case BucketDecision(allowed=False):
        raise Throttled(wait=decision.retry_after)  # whole seconds, safe for a Retry-After header
    case BucketDecision():
        ...  # proceed; decision.remaining / .limit / .reset back RateLimit-* headers

# The request turned out to do no work (validation error, capability refusal):
refund(f"myfeature_rate:{team_id}", BUDGET)

# Introspection without charging (headers on reads, a /limits endpoint):
peek(f"myfeature_rate:{team_id}", BUDGET)

Semantics worth knowing:

  • consume charges and answers in one atomic step. cost above burst is a programmer error (ValueError), not a denial.
  • refund is capped at capacity and treats a missing key as an already-full bucket. Refund only what you charged; refunding on outcomes the caller controls (e.g. their own 4xxs they can trigger for free) is fine, refunding on outcomes an attacker controls to spin the bucket is not.
  • peek is a plain read plus local refill math, so it can lose a sub-second race to a concurrent charge. Never gate anything on peek; gate on consume.
  • Keys are fully caller-constructed. Prefix them (<feature>_rate:), include every identity the budget is scoped to, and never include secrets. The bucket self-expires once it would be full again, so idle keys clean themselves up.
  • Nothing raises on Redis failure: every operation returns BucketUnavailable and the caller decides fail-open vs fall-through. Do not swallow it silently; log or count it so an outage is visible.

Reference consumer

The agentic provisioning rate limits (ee/api/agentic_provisioning/ratelimits.py) are the canonical consumer: per-partner budgets declared on handlers with @rate_limited, tier multipliers, refund-on-no-work in handle_exception, RateLimit-* headers from the decision, and Prometheus counters around every outcome. Read it before building a second rate-limit layer on top of the bucket.

Testing

Under settings.TEST, posthog.redis.get_client() returns fakeredis, which executes the Lua scripts (via lupa). Control time with time_machine.travel(..., tick=False) (the script's clock is passed in from Python), reset between tests with posthog.redis.TEST_clear_clients() + posthog.token_bucket.TEST_reset_scripts(), and see posthog/test/test_token_bucket.py for the pattern.

© PostHog, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/using-redis-token-buckets of PostHog/posthog-foss.

Open the folder on GitHubat commit 2c48221

Compare with similar skills

Using Redis Token Buckets next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Using Redis Token Buckets compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Using Redis Token Buckets this skillPostHog/posthog-foss721—~1.6kAutomated safety check: PassMIT
Redis SpecialistFerroxLabs/wayland608—~4.2kAutomated safety check: PassApache-2.0
Rate Limiter InterviewerPrepLabsAI/InterviewMentor112—~2.1kAutomated safety check: PassMIT
Resume Backend Project OptimizerLAIJiangFeng/resume-builder247—~868Automated safety check: PassNone
Redis ExpertRightNow-AI/openfang18k—~821Automated safety check: PassApache-2.0
Redis Patternsrohitg00/awesome-claude-code-toolkit2.7k—~1.2kAutomated safety check: PassApache-2.0

Similar skills

  • Redis Specialist

    FerroxLabs/wayland

    Comprehensive Redis expertise covering all data structures (strings, hashes, lists, sets, sorted sets, streams), pub/sub messaging, Lua scripting, Redis Cluster architecture, Sentinel high…

    608 GitHub stars~4.2k tokensUpdated yesterday
    DatabasesAuto-check passed
  • Rate Limiter Interviewer

    PrepLabsAI/InterviewMentor

    A Staff Infrastructure Engineer interviewer. An agent skill from PrepLabsAI/InterviewMentor.

    112 GitHub stars~2.1k tokensUpdated today
    Backend & APIsAuto-check passed
  • Resume Backend Project Optimizer

    LAIJiangFeng/resume-builder

    将中文后端项目经历改写为高质量、可面试追问、强数据化的简历要点。适用于用户提供“项目经历/主要工作/职责描述”后,要求按统一模板输出“负责xxx功能 + 关键技术细节组合 + 解决问题 + 数据化结果”的场景;适用于 Java 后端求职、简历优化、面试前项目复盘,且需要对齐面试高频考点(Java 集合与并发、MySQL、Redis、Spring、消息队列、系统设计等)时使用。

    247 GitHub stars~868 tokensUpdated 1 mo ago
    DatabasesAuto-check passed
  • Redis Expert

    RightNow-AI/openfang

    Redis expert for data structures, caching patterns, Lua scripting, and cluster operations

    18k GitHub stars~821 tokensUpdated 3 mo ago
    DatabasesAuto-check passed
  • Redis Patterns

    rohitg00/awesome-claude-code-toolkit

    Redis patterns including caching strategies, pub/sub, streams for event processing, Lua scripts, and data structures

    2.7k GitHub stars~1.2k tokensUpdated 4 mo ago
    DatabasesAuto-check passed
  • Redis

    ericrisco/rsc-harness

    A skill your agent uses when using Redis or any Redis-protocol store (Valkey, ElastiCache, Upstash, Dragonfly, Memorystore) as a cache, queue, rate limiter or distributed lock and it has to be…

    156 GitHub stars~4.3k tokensUpdated today
    DatabasesAuto-check passed

More from PostHog/posthog-foss

All 213 skills in this repo
  • Authoring Log Alerts

    PostHog/posthog-foss

    Official

    Author useful, low-noise log alerts on services in a PostHog project.

    721 GitHub stars~3k tokensUpdated today
    Auto-check passed
  • Autoresolving PR Conflicts

    PostHog/posthog-foss

    Official

    Operating procedure for the conflict-autoresolver agent: sweep open PostHog/posthog PRs that conflict with master, resolve the trivial conflicts (generated artifacts deterministically, source…

    721 GitHub stars~4.2k tokensUpdated today
    Auto-check passed
  • Official

    Help users debug PostHog Error Tracking stack-trace symbolication for any supported platform — JavaScript/TypeScript web, React Native (Hermes), Android (Proguard / R8), or iOS / macOS (dSYM).

    721 GitHub stars~2.2k tokensUpdated today
    Auto-check passed
  • Exploring Apm Traces

    PostHog/posthog-foss

    Official

    Investigates distributed application performance using PostHog APM (OpenTelemetry span) data via MCP.

    721 GitHub stars~3.5k tokensUpdated today
    Auto-check passed
  • Exploring LLM Traces

    PostHog/posthog-foss

    Official

    Debug and inspect LLM/AI agent traces using PostHog's MCP tools.

    721 GitHub stars~4.4k tokensUpdated today
    Auto-check passed
  • Investigate Metric

    PostHog/posthog-foss

    Official

    Diagnose why a product metric changed (dropped, spiked, or plateaued) by orchestrating breakdowns, actors, paths, lifecycle, retention, and annotations queries.

    721 GitHub stars~1.9k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about Using Redis Token Buckets

What does Using Redis Token Buckets do?

A skill your agent uses when adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill, a refund path for requests that did no work, or a limit…. Using Redis Token Buckets is an agent skill from PostHog/posthog-foss, published by the product's own GitHub organization. Use when adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill, a refund path for requests that did no work, or a limit whose Retry-After must be a real wait rather than a window edge.

When should I use Using Redis Token Buckets?

Using Redis Token Buckets fits situations like: adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill; A refund path for requests that did no work; A limit whose Retry-After must be a real wait rather than a window edge; terms: token bucket.

How do I install Using Redis Token Buckets in Claude Code?

Run `npx skills add PostHog/posthog-foss --skill using-redis-token-buckets -a claude-code`. Or copy the skill folder (.agents/skills/using-redis-token-buckets in PostHog/posthog-foss) into .claude/skills/using-redis-token-buckets in your project. Claude Code loads it when a task matches its description.

How do I install Using Redis Token Buckets in Codex?

Run `npx skills add PostHog/posthog-foss --skill using-redis-token-buckets -a codex`. Or copy the skill folder (.agents/skills/using-redis-token-buckets in PostHog/posthog-foss) into .agents/skills/using-redis-token-buckets in your project. Codex loads it when a task matches its description.

Can I use Using Redis Token Buckets in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add PostHog/posthog-foss --skill using-redis-token-buckets -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/using-redis-token-buckets, .gemini/skills/using-redis-token-buckets, .github/skills/using-redis-token-buckets and .opencode/skills/using-redis-token-buckets in your project.

What does Using Redis Token Buckets need to run?

SKILL.md names no scripts, command-line tools or credentials: Using Redis Token Buckets is instructions for the agent only. Our summary lists: Python 3.

Does Using Redis Token Buckets access the network?

SKILL.md names 1 domain. As links in the text: limits.readthedocs.io. This is read from the text; nothing was executed.

Is Using Redis Token Buckets safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Using Redis Token Buckets use?

Using Redis Token Buckets is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Using Redis Token Buckets use?

About 1.6k tokens (SKILL.md is roughly 6.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Using Redis Token Buckets?

Skills that share tags, products or a category with Using Redis Token Buckets: Redis Specialist (FerroxLabs/wayland, 608 stars), Rate Limiter Interviewer (PrepLabsAI/InterviewMentor, 112 stars), Resume Backend Project Optimizer (LAIJiangFeng/resume-builder, 247 stars) and Redis Expert (RightNow-AI/openfang, 18k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Using Redis Token Buckets?

PostHog (a GitHub organization, an official publisher) maintains it in PostHog/posthog-foss, which has 721 GitHub stars. The repository holds 213 skills in this directory. The repository was last updated on October 7, 2026.

Source: PostHog/posthog-foss on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.