
Localizing Variables
Claude Code agent workflow helper from OBRA clank repository.
Install
npx skills add https://github.com/obra/clank --skill localizing-variablesWhat is this skill?
- OBRA clank agent workflow.
- Install via skills.sh registry.
- Pairs with Superpowers ecosystem.
Adoption & trust: 2 installs on skills.sh; 40 GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Microsoft Foundrymicrosoft/azure-skills
Azure Aimicrosoft/azure-skills
Azure Hosted Copilot Sdkmicrosoft/azure-skills
Lark Eventlarksuite/cli
Running Claude Code Via Litellm Copilotxixu-me/skills
Setup Matt Pocock Skillsmattpocock/skills
Journey fit
Common Questions / FAQ
Is Localizing Variables safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Localizing Variables
# 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. ### Span Distance between successive references to a variable: ```python a = 0 # First reference b = 0 # 1 line between references to a c = 0 # 2 lines between references to a a = b + c # Second reference # Span of a: 2 lines ``` **Goal:** Minimize span. Keep references close together. ### Live Time Total statements between first and last reference: ```python recordIndex = 0 # Line 2 - first reference # ... 24 lines of other code ... recordIndex += 1 # Line 28 - last reference # Live time: 28 - 2 + 1 = 27 statements ``` **Goal:** Minimize live time. Reduce window of vulnerability. ## The Principle of Proximity **Keep related actions together:** ❌ **Bad (declarations far from use):** ```python def process_data(): # All declarations at top index = 0 total = 0 done = False result = [] # 20 lines later... while index < count: index += 1 # 30 lines later... while not done: if total > threshold: done = True # 40 lines later... result.append(final_value) return result ``` **Live times:** index=25, total=35, done=35, result=40. Average: 34 lines. ✅ **Good (declare close to use):** ```python def process_data(): # Declare index right before loop that uses it index = 0 while index < count: index += 1 # Declare total and done right before loop that uses them total = 0 done = False while not done: if total > threshold: done = True # Declare result right before use result = [] result.append(final_value) return result ``` **Live times:** index=3, tota