Localizing Variables

Declare variables in smallest possible scope, initialize close to first use, minimize span and live time

43 stars 26 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add obra/clank --skill Localizing Variables
Manual install
git 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-Variables

Personal 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.
Read the full skill on GitHub

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

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.