Single Purpose Variables
Use each variable for exactly one purpose - no hybrid coupling or hidden meanings
Install
npx skills add obra/clank --skill Single Purpose Variablesgit clone --depth 1 https://github.com/obra/clank.git /tmp/clank
mkdir -p ~/.claude/skills
cp -r /tmp/clank/skills/coding/single-purpose-variables ~/.claude/skills/Single-Purpose-VariablesPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Single Purpose Variables
## Overview
Each variable should represent exactly ONE thing. No reusing for different purposes. No hidden meanings.
**Core principle:** If variable represents count sometimes and error other times, use two variables.
## Baseline Violation: Hybrid Coupling
**From baseline, agents use special values to indicate errors:**
❌ **Hybrid coupling (baseline):**
```python
def process_file_pages(filename):
try:
pages_processed = 0 # Count (integer purpose)
# ... processing ...
return pages_processed
except:
return -1 # Error flag (boolean purpose as -1)
```
**Problem:** `pages_processed` represents TWO things:
- Non-negative integer = page count
- -1 = error occurred
**This is hybrid coupling:** Variable moonlights as different type.
✅ **Separate concerns:**
```python
def process_file_pages(filename):
try:
pages_processed = 0
# ... processing ...
return (True, pages_processed) # Success, count
except Exception as e:
return (False, str(e)) # Failure, error message
```
**Or raise exception:**
```python
def process_file_pages(filename):
# Let exceptions propagate - no hybrid variable needed
pages_processed = 0
# ... processing (raises on error) ...
return pages_processed # Always a count, never an error
```
## Common Hidden Meanings
❌ **What agents naturally do:**Details
- Skill name
Single Purpose Variables- Repository
- obra/clank
- Path
skills/coding/single-purpose-variables/SKILL.md- Repo updated
- 9 October 2025
FAQ
What does the Single Purpose Variables skill do?
Use each variable for exactly one purpose - no hybrid coupling or hidden meanings
How do I install the Single Purpose Variables skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add obra/clank --skill Single Purpose Variables. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Single Purpose Variables popular?
It lives in obra/clank, which has 43 GitHub stars and 26 forks.
Related skills
Gardening Skills Wiki
43obra/clank
Maintain skills wiki health - check links, naming, cross-references, and coverage
Remembering Conversations
43obra/clank
Search previous Claude Code conversations for facts, patterns, decisions, and context using semantic or text search
Brainstorming Ideas Into Designs
43obra/clank
Interactive idea refinement using Socratic method to develop fully-formed designs
Stay in Lane
62ElliotJLT/Claude-Skill-Potions
Before making changes, verifies they match what was actually requested. Activates when about to modify files, add features, or refactor code. Catches scope creep before it happens - no "while I'm here" improvements.
Simplifying Control Flow
43obra/clank
Flatten nested conditionals with early returns or table-driven methods - keep nesting depth under 3 levels
Trace It
62ElliotJLT/Claude-Skill-Potions
Before modifying shared code (utilities, types, configs, base classes), traces all callers and dependents first. Activates when editing files in shared/, utils/, lib/, or anything imported by 3+ files. Prevents "fixed one thing, broke three others.
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.