writing-dataclasses

writing-dataclasses is a skill for Claude Code, Codex from PostHog/posthog-foss. It costs 157 tokens per session (1,648 once invoked), scanned A, original, MIT.

A guide for using Python dataclasses to represent fixed groups of typed values. It covers when a named immutable object is safer than a tuple or a loosely shaped dictionary.

In plain words
What is it for?
Use it when designing Python function inputs or results that contain several related fields with a fixed structure.
Why use it?
It prevents values from being passed in the wrong order or accessed through misspelled dictionary keys.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: installed under .agents/ (shared by several agents).

Good fit Use it when designing Python function inputs or results that contain several related fields with a fixed structure.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/posthog/posthog-foss/writing-dataclasses
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add PostHog/posthog-foss --skill writing-dataclasses
Clone the repo
git clone --depth 1 https://github.com/PostHog/posthog-foss

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for writing-dataclasses

README.md
[![agentmods](https://agentmods.dev/badge/skills/posthog/posthog-foss/writing-dataclasses/github.svg)](https://agentmods.dev/skills/posthog/posthog-foss/writing-dataclasses)
Your own site
<a href="https://agentmods.dev/skills/posthog/posthog-foss/writing-dataclasses"><img src="https://agentmods.dev/badge/skills/posthog/posthog-foss/writing-dataclasses/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for writing-dataclasses

Your own site · 80×15
<a href="https://agentmods.dev/skills/posthog/posthog-foss/writing-dataclasses"><img src="https://agentmods.dev/badge/skills/posthog/posthog-foss/writing-dataclasses.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 157 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,648 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00157 $0.01648
Opus 5.5 $0.00063 $0.00659
Sonnet 5.5 $0.00031 $0.00330
Haiku 4.5 $0.00016 $0.00165

Measured 3mo ago against content hash bfbbbe1674c8, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

writing-dataclasses scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/writing-dataclasses/SKILL.md · 79 lines

How it starts

The opening of the file, as written. The whole thing — 79 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Writing dataclasses

The point of every rule here is the same: values that share a type get swapped silently, and a positional tuple or a dict[str, Any] lets that happen. A named, frozen dataclass makes the swap a typecheck failure instead of a runtime bug. Everything below follows from that; if a rule doesn't serve it in your case, say so in the PR and skip it.

When a dataclass, when not

  • Return or pass a dataclass instead of a tuple when two or more elements share a type ((start, end), (width, height), (rows, columns)), or when the tuple has roughly 3+ elements and positional access hurts readability. A small tuple of clearly different types ((user, count)) is fine as-is.
  • Prefer a dataclass over dict[str, Any] when a fixed set of values crosses a function boundary. A dict key typo fails at runtime; a dataclass field typo fails typecheck. Dicts stay for genuinely dynamic key sets.
  • NamedTuple is not the answer for the swap problem: it still unpacks positionally.

Which decorator

Use @frozen from posthog.dataclasses for internal value and result objects. It is @dataclass with frozen=True, kw_only=True, slots=True as defaults, and every flag is overridable:

from posthog.dataclasses import frozen

@frozen
class BillingPeriod:
    start: datetime
    end: datetime

@frozen(slots=False)          # class uses functools.cached_property
class ParsedQuery: ...

@frozen(frozen=False)         # genuinely mutated after construction (a builder, an accumulator)
class RunAccumulator: ...
  • kw_only=True is what actually prevents swaps at construction: BillingPeriod(start=a, end=b), never BillingPeriod(a, b). Don't override it without a reason.
  • slots=True blocks functools.cached_property and ad-hoc attributes; override with slots=False rather than dropping @frozen.
  • A bare @dataclass with no explicit frozen= fails the ratchet in posthog/test/repo_invariants/test_dataclass_defaults.py and is flagged by the advisory prefer-frozen-dataclasses semgrep rule. @dataclass(frozen=False) passes; the ratchet asks for a stated choice, not immutability. If you only moved an existing bare @dataclass, regenerate the baseline with python posthog/test/repo_invariants/test_dataclass_defaults.py instead of decorating it.
  • Don't add frozen=False to a bare @dataclass you didn't otherwise touch. The ratchet counts per file against a baseline; an unchanged count passes, and the edit is churn in someone else's file.
  • Facade contracts (products/<name>/backend/facade/contracts.py) are frozen dataclasses too, usually pydantic.dataclasses.dataclass(frozen=True) so they validate on construction. See products/architecture.md.

Read the full file on GitHub · 79 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 79 lines · 157 tokens per session scan A bfbbbe1674c8

Subscribe to this mod's changes

writing-dataclasses is a skill published in the GitHub repository PostHog/posthog-foss (736 stars, last pushed today), licensed MIT. It adds 157 tokens to every session and 1,648 once invoked, about $0.0006 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

writing-dataclasses compared with skills from other repositories

writing-dataclasses next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
writing-dataclassesPostHog/posthog-fossSkill736todayMITA157Claude Code, Codex
matlabK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA44Claude Code
pennylaneK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA74Claude Code
holoscan-install-wheelNVIDIA/skillsSkill4.3ktodayApache-2.0A34Claude Code, Codex
python-engineering-guidelinesanywhere-labs/Agents-AnywhereSkill3.9ktodayApache-2.0A75Codex
future-self-liteTHU-MAIC/OpenMAICSkill46ktodayMITA20Claude Code, Codex
rocm-kernelshuggingface/kernelsSkill803todayApache-2.0A93Claude Code