tonyandrewmeyer/charming-with-claude/config-classes
Claude Code and agent skill by tonyandrewmeyer/charming-with-claude
- community
Checking that the SKILL.md file is still in the repository.
Install
npx vskill@latest install tonyandrewmeyer/charming-with-claude/config-classesSKILL.md
The same SKILL.md was published earlier as tonyandrewmeyer/charming-with-claude/config-classes.
Skill: Adopt Config Classes
Replace raw self.config dictionary access with typed Python classes using CharmBase.load_config().
When to Use
Use this when a charm accesses config via self.config["key"] or self.config.get("key") and would benefit from type safety, validation, and IDE support.
Prerequisites
- ops >= 2.23.0
- The charm has config options defined in
charmcraft.yaml(orconfig.yaml)
Step 1: Audit Current Config Usage
- Read the charm's config definition in
charmcraft.yamlto understand all config options and their types. - Search the charm code for all config access patterns:
self.config["..."]self.config.get("...")self.config[...]with variable keys
- Note any manual validation (type checks, range checks, enum validation).
Step 2: Define the Config Class
Create a config class in src/config.py (or inline if the charm is small).
Option A: Dataclass (no extra dependencies)
Option B: Pydantic BaseModel (richer validation, requires pydantic dependency)
Field Naming Rules
- Juju config names use dashes:
log-level - Python field names use underscores:
log_level - The conversion is automatic — just use underscores in the class.
- For names that don't follow this pattern, use aliases:
``python # Dataclass: workload_class: str = dataclasses.field(metadata={"alias": "class"}) # Pydantic: workload_class: str = pydantic.Field(alias="class") ``
Step 3: Update the Charm
Loading config
The standard pattern is to load config in __init__ with errors="blocked":
With errors="blocked", if the config is invalid:
- The unit status is set to
BlockedStatus("Invalid config: ..."). - The hook exits cleanly (Juju won't retry).
- The charm should handle this in
collect_unit_statusor check the status before proceeding.
Replacing config access
Removing manual validation
Any validation that's now handled by the config class can be removed from the charm code.
Step 4: Update Tests
If tests set config values via testing.State(config={...}), those continue to work — no test changes needed for the state setup. But assertions that check for manual validation behaviour (e.g. checking that the charm sets BlockedStatus on bad config) should verify the new error path.
Step 5: Verify
- Run
tox -e lint— ensure the new module is properly imported. - Run
tox -e unit— all tests should pass. - Review the diff — it should be focused on config access patterns. No unrelated changes.
Exemplar Charms
- [cve-scanner-operator](https://github.com/canonical/cve-scanner-operator) — Pydantic with rich Field constraints,
errors="blocked", separatesrc/config.py. - [conserver-charm](https://github.com/canonical/conserver-charm) — Clean minimal Pydantic example.
- [forgejo-k8s-operator](https://github.com/canonical/forgejo-k8s-operator) — Dataclass approach with
__post_init__validation.
Common Mistakes
- Don't partially convert — if adopting
load_config, convert allself.configaccess. - Don't forget to add
pydanticto dependencies if using Pydantic. - Don't add validation that changes behaviour — the goal is to replace raw access with typed access, not to add new restrictions.
- Don't put the config class in the charm module if it's complex — use a separate
src/config.py.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingexperiments/2026-01-25-ops-upgrade/skills/config-classes/SKILL.md
Popularity
- Repository stars
- 3
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/tonyandrewmeyer/charming-with-claude/config-classes)