Localizing Variables
Declare variables in smallest possible scope, initialize close to first use, minimize span and live time
Install
npx skills add obra/clank --skill Localizing Variablesgit clone --depth 1 https://github.com/obra/clank.git /tmp/clank
mkdir -p ~/.claude/skills
cp -r /tmp/clank/skills/coding/localizing-variables ~/.claude/skills/Localizing-VariablesPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Localizing Variables
## Overview
The Principle of Proximity: Keep related actions together. Declare variables in the smallest scope possible, initialize them close to where they're first used, and keep all references to a variable close together.
**Core principle:** Minimize the window of vulnerability. The smaller the scope and the closer the references, the less can go wrong and the easier code is to understand.
**Goal:** Reduce what you must keep in mind at any one time.
## When to Use
**Apply to every variable you declare:**
- When declaring variables
- When initializing variables
- When reviewing code with scattered variable usage
- When refactoring to improve clarity
**Warning signs:**
- Variables declared at top of function, used at bottom
- All variables initialized together, far from first use
- Large gap between variable declaration and use
- Must scroll to see variable declaration and usage together
- Variables have function/class scope when could be more local
- Can't see all uses of variable on one screen
## Key Concepts
### Scope
How widely visible a variable is:
- **Block scope** - visible only within `{}` or indented block (smallest)
- **Loop scope** - visible only within loop
- **Function scope** - visible throughout function
- **Class scope** - visible to all methods in class
- **Module scope** - visible throughout file
- **Global scope** - visible everywhere (largest, avoid)
**Rule:** Start with smallest scope. Expand only if necessary.Details
- Skill name
Localizing Variables- Repository
- obra/clank
- Path
skills/coding/localizing-variables/SKILL.md- Repo updated
- 9 October 2025
FAQ
What does the Localizing Variables skill do?
Declare variables in smallest possible scope, initialize close to first use, minimize span and live time
How do I install the Localizing Variables skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add obra/clank --skill Localizing Variables. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Localizing 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
Maintaining Consistent Abstractions
43obra/clank
Class interfaces present one cohesive abstraction - don't mix domain logic with serialization, persistence, or unrelated concerns
Keeping Routines Focused
43obra/clank
Each routine does one thing and does it well - extract when routines have multiple responsibilities
Naming Variables
43obra/clank
Choose names that fully and accurately describe what the variable represents
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.