Portable Tools
by @tunaissacoding
Build cross-device tools without hardcoding paths or account names
clawhub install portable-toolsπ About This Skill
name: portable-tools description: Build cross-device tools without hardcoding paths or account names
Portable Tools - Cross-Device Development Methodology
Methodology for building tools that work across different devices, naming schemes, and configurations. Based on lessons from OAuth refresher debugging session (2026-01-23).
Core Principle
Never assume your device is the only device.
Your local setup is just one of many possible configurations. Build for the general case, not the specific instance.
The Three Questions (Before Writing Code)
1. "What varies between devices?"
Before writing any code that reads configuration, data, or credentials:
Ask:
Example from OAuth refresher:
Action: List variables, make them configurable or auto-discoverable
2. "How do I prove this works?"
Before claiming success:
Require:
Example from OAuth refresher:
BEFORE:
Access Token: POp5z1fi...eSN9VAAA
Expires: 1769189639000 AFTER:
Access Token: 01v0RrFG...eOE9QAA β
Different
Expires: 1769190268000 β
Extended
Action: Always show data transformation with real values
3. "What happens when it breaks?"
Before pushing to production:
Test:
Example from OAuth refresher:
keychain_account: "wrong-name" β Fallback should workAction: Test failure modes, not just happy path
Mandatory Patterns
Pattern 1: Explicit Over Implicit
β Wrong:
# Ambiguous - returns first match
security find-generic-password -s "Service" -w
β Correct:
# Explicit - returns specific entry
security find-generic-password -s "Service" -a "account" -w
Rule: If a command can be ambiguous, make it explicit.
Pattern 2: Validate Before Use
β Wrong:
DATA=$(read_config)
USE_VALUE="$DATA" # Hope it's valid
β Correct:
DATA=$(read_config)
if ! validate_structure "$DATA"; then
error "Invalid data structure"
fi
USE_VALUE="$DATA"
Rule: Never assume data has expected structure.
Pattern 3: Fallback Chains
β Wrong:
ACCOUNT="claude" # Hardcoded
β Correct:
# Try configured β Try common β Error with help
ACCOUNT="${CONFIG_ACCOUNT}"
if ! has_data "$ACCOUNT"; then
for fallback in "claude" "default" "oauth"; do
if has_data "$fallback"; then
ACCOUNT="$fallback"
break
fi
done
fi
[[ -z "$ACCOUNT" ]] && error "No account found. Tried: ..."
Rule: Provide automatic fallbacks for common variations.
Pattern 4: Helpful Errors
β Wrong:
[[ -z "$TOKEN" ]] && error "No token"
β Correct:
[[ -z "$TOKEN" ]] && error "No token foundChecked:
Config: $CONFIG_FILE
Field: $FIELD_NAME
Expected: { \"tokens\": { \"refresh\": \"...\" } } Verify with:
cat $CONFIG_FILE | jq '.tokens'
"
Rule: Error messages should help user diagnose and fix.
Debugging Methodology (Patrick's Approach)
Step 1: Get Exact Data
Don't ask: "Is it broken?" Ask: "What exact values do you see? How many entries exist? Which one has the data?"
Example:
# Vague
"Check keychain"Specific
"Run: security find-generic-password -l 'Service' | grep 'acct'"
"Tell me: 1. How many entries 2. Which has tokens 3. Last modified"
Step 2: Prove With Concrete Examples
Don't say: "It should work now" Show: "Here's the BEFORE token (POp5z...), here's AFTER (01v0R...), they're different"
Template:
BEFORE:
Field1:
Field2: AFTER:
Field1: β
Changed
Field2: β
Changed PROOF: Values are different
Step 3: Think Cross-Device Immediately
Don't think: "Works on my machine" Think: "What if their setup differs in [X]?"
Checklist:
Pre-Flight Checklist (Before Publishing)
Discovery Phase
Implementation Phase
--dry-run or --test modeTesting Phase
Documentation Phase
Real-World Example: OAuth Refresher
Original (Broken)
# Assumes single entry, no validation, no fallback
KEYCHAIN_DATA=$(security find-generic-password -s "Service" -w)
REFRESH_TOKEN=$(echo "$KEYCHAIN_DATA" | jq -r '.refreshToken')
Use token (hope it's valid)
Problems:
Fixed (Portable)
# Explicit account with validation and fallback
validate_data() {
echo "$1" | jq -e '.claudeAiOauth.refreshToken' > /dev/null 2>&1
}Try configured account
DATA=$(security find-generic-password -s "$SERVICE" -a "$ACCOUNT" -w 2>&1)
if validate_data "$DATA"; then
log "β Using account: $ACCOUNT"
else
log "β Trying fallback accounts..."
for fallback in "claude" "Claude Code" "default"; do
DATA=$(security find-generic-password -s "$SERVICE" -a "$fallback" -w 2>&1)
if validate_data "$DATA"; then
ACCOUNT="$fallback"
log "β Found data in: $fallback"
break
fi
done
fi[[ -z "$DATA" ]] || ! validate_data "$DATA" && error "No valid data found
Tried accounts: $ACCOUNT, claude, Claude Code, default
Verify with: security find-generic-password -l '$SERVICE'"
REFRESH_TOKEN=$(echo "$DATA" | jq -r '.claudeAiOauth.refreshToken')
Improvements:
Common Anti-Patterns
Anti-Pattern 1: "Works On My Machine"
FILE="/Users/patrick/.config/app.json" # Hardcoded path
Fix: Use $HOME, detect OS, or make configurable
Anti-Pattern 2: "Hope It's There"
TOKEN=$(cat config.json | jq -r '.token')
What if .token doesn't exist? Script continues with empty value
Fix: Validate before using
TOKEN=$(cat config.json | jq -r '.token // empty')
[[ -z "$TOKEN" ]] && error "No token in config"
Anti-Pattern 3: "First Match Is Right"
# If multiple entries exist, which one?
ENTRY=$(find_entry "service")
Fix: Be explicit or enumerate all
ENTRY=$(find_entry "service" "account") # Specific
OR
ALL=$(find_all_entries "service")
for entry in $ALL; do
validate_and_use "$entry"
done
Anti-Pattern 4: "Silent Failures"
process_data || true # Ignore errors
Fix: Fail loudly with context
process_data || error "Failed to process
Data: $DATA
Expected: { ... }
Check: command_to_verify"
Integration With Existing Workflows
With sprint-plan.md
Add to testing section:## Cross-Device Testing
[ ] Test with different account names
[ ] Test with wrong config values
[ ] Test with missing data
[ ] Document fallback behavior
With PRIVACY-CHECKLIST.md
Add before publishing:## Portability Check
[ ] No hardcoded paths (use $HOME, detect OS)
[ ] No hardcoded names (use config or fallback)
[ ] Validation on all inputs
[ ] Helpful errors for common issues
With skill-creator
When building new skills: 1. List what varies between devices 2. Make it configurable or auto-discoverable 3. Test with wrong config 4. Document troubleshootingQuick Reference Card
Before writing code: 1. What varies between devices? 2. How do I prove this works? 3. What happens when it breaks?
Mandatory patterns:
Testing:
Documentation:
Success Criteria
A tool is portable when:
1. β Works on different devices without modification 2. β Auto-discovers common variations in setup 3. β Fails gracefully with actionable error messages 4. β Can be debugged by reading the error output 5. β Documentation covers "what if my setup differs"
Test: Give it to someone with a different setup. If they need to ask you questions, the tool isn't portable yet.
Origin Story
This methodology emerged from debugging the OAuth refresher (2026-01-23):
Patrick's approach: 1. Asked for exact data (how many entries, which has tokens) 2. Demanded proof (show BEFORE/AFTER tokens) 3. Thought cross-device (what if naming differs?)
Result: Tool went from single-device/broken to universal/production-ready.
Key insight: The bugs weren't in the logic - they were in the assumptions.
When To Use This Skill
Use when:
Apply: 1. Before implementing: Answer the three questions 2. During implementation: Use mandatory patterns 3. Before testing: Run pre-flight checklist 4. After testing: Document variations and troubleshooting
Remember: Your device is just one case. Build for the general case.