Environment Management
Launchpad provides powerful environment management capabilities that automatically isolate project dependencies and provide tools for managing these environments. This guide covers all aspects of environment management, from automatic activation to manual cleanup.
Overview
Environment management in Launchpad consists of two main components:
- Automatic Environment Isolation - Project-specific environments that activate when you enter a directory
- Environment Management Tools - CLI commands for listing, inspecting, cleaning, and removing environments
- Shell Message Customization - Configurable activation and deactivation messages
Automatic Environment Isolation
How It Works
When you enter a directory containing dependency files (like dependencies.yaml
), Launchpad automatically:
- Generates a unique environment hash based on the project path
- Creates an isolated environment directory at
~/.local/share/launchpad/envs/{hash}/
- Installs project-specific packages to the isolated environment
- Modifies PATH to prioritize the project's binaries
- Sets up environment variables as specified in the dependency file
- Creates deactivation hooks to restore the original environment when leaving
- Displays customizable messages for activation and deactivation
Environment Hash Format
Launchpad uses a human-readable hash format for environment directories:
Format: {project-name}_{8-char-hex-hash}
Examples:
my-web-app_1a2b3c4d
- For a project in/home/user/projects/my-web-app
api-server_5e6f7g8h
- For a project in/work/api-server
final-project_7db6cf06
- For a deeply nested project
Benefits:
- Human-readable - Easy to identify which project an environment belongs to
- Unique - 8-character hex hash prevents collisions between projects
- Consistent - Same project path always generates the same hash
- Collision-resistant - Different paths with same project name get different hashes
Supported Dependency Files
Launchpad automatically detects these dependency files:
dependencies.yaml
/dependencies.yml
.launchpad.yaml
/launchpad.yaml
.launchpad.yml
/launchpad.yml
deps.yml
/deps.yaml
.deps.yml
/.deps.yaml
For pkgx compatibility, Launchpad also supports:
pkgx.yaml
/pkgx.yml
.pkgx.yaml
/.pkgx.yml
Example dependency file:
dependencies:
- node@22
- python@3.12
- gnu.org/wget@1.21
env:
NODE_ENV: development
API_URL: https://api.example.com
DATABASE_URL: postgresql://localhost/myapp
Shell Integration
To enable automatic environment activation, add shell integration:
# Add to your shell configuration
echo 'eval "$(launchpad dev:shellcode)"' >> ~/.zshrc
# Reload your shell
source ~/.zshrc
Once set up, environments automatically activate:
cd my-project/ # → ✅ Environment activated for /path/to/my-project
cd ../ # → dev environment deactivated
Customizing Shell Messages
You can customize or disable environment activation/deactivation messages:
Disabling Messages
# Disable all environment messages
export LAUNCHPAD_SHOW_ENV_MESSAGES=false
# Or in configuration file
echo 'export default { showShellMessages: false }' > launchpad.config.ts
Custom Activation Messages
# Environment variable (use {path} placeholder for project path)
export LAUNCHPAD_SHELL_ACTIVATION_MESSAGE="🚀 Project environment loaded: {path}"
# Or in configuration file
echo 'export default {
shellActivationMessage: "🔧 Development environment ready: {path}"
}' > launchpad.config.ts
Custom Deactivation Messages
# Environment variable
export LAUNCHPAD_SHELL_DEACTIVATION_MESSAGE="👋 Project environment closed"
# Or in configuration file
echo 'export default {
shellDeactivationMessage: "🔒 Environment closed"
}' > launchpad.config.ts
Message Examples
Different styles you can use:
# Minimal style
export LAUNCHPAD_SHELL_ACTIVATION_MESSAGE="[ENV] {path}"
export LAUNCHPAD_SHELL_DEACTIVATION_MESSAGE="[ENV] closed"
# Detailed style
export LAUNCHPAD_SHELL_ACTIVATION_MESSAGE="🔧 Development environment ready for {path}"
export LAUNCHPAD_SHELL_DEACTIVATION_MESSAGE="👋 Development environment deactivated"
# Emoji style
export LAUNCHPAD_SHELL_ACTIVATION_MESSAGE="📁 {path} 🚀"
export LAUNCHPAD_SHELL_DEACTIVATION_MESSAGE="🏠 Back to global environment"
Environment Management Commands
Listing Environments
The env:list
command shows all your development environments:
# Basic listing
launchpad env:list
# Detailed view with hashes
launchpad env:list --verbose
# JSON output for scripting
launchpad env:list --format json
# Simple format
launchpad env:ls --format simple
Output formats:
Table (default):
📦 Development Environments:
│ Project │ Packages │ Binaries │ Size │ Created │
├───────────────────────────────────────────────────────────────┤
│ final-project │ 2 │ 2 │ 5.0M │ 5/30/2025 │
│ working-test │ 3 │ 20 │ 324M │ 5/30/2025 │
│ dummy │ 1 │ 1 │ 1.1M │ 5/30/2025 │
└───────────────────────────────────────────────────────────────┘
Total: 3 environment(s)
JSON:
[
{
"hash": "final-project_7db6cf06",
"projectName": "final-project",
"packages": 2,
"binaries": 2,
"size": "5.0M",
"created": "2025-05-31T01:36:49.283Z"
}
]
Simple:
final-project (final-project_7db6cf06)
working-test (working-test_208a31ec)
dummy (dummy_6d7cf1d6)
Inspecting Environments
The env:inspect
command provides detailed information about a specific environment:
# Basic inspection
launchpad env:inspect working-test_208a31ec
# Detailed inspection with directory structure
launchpad env:inspect final-project_7db6cf06 --verbose
# Show binary stub contents
launchpad env:inspect dummy_6d7cf1d6 --show-stubs
Example output:
🔍 Inspecting environment: working-test_208a31ec
📋 Basic Information:
Project Name: working-test
Hash: working-test_208a31ec
Path: /Users/user/.local/share/launchpad/envs/working-test_208a31ec
Size: 324M
Created: 5/30/2025, 6:38:08 PM
Modified: 5/30/2025, 6:38:12 PM
📁 Directory Structure:
bin/: 20 item(s)
pkgs/: 3 item(s)
lib/: 6 item(s)
share/: 5 item(s)
📦 Installed Packages:
python.org@3.12.10
curl.se@8.5.0
cmake.org@3.28.0
🔧 BIN Binaries:
python (file, executable)
curl (file, executable)
cmake (file, executable)
pip (file, executable)
...
🏥 Health Check:
✅ Binaries present
✅ 3 package(s) installed
Overall Status: ✅ Healthy
Health Check Criteria:
- Binaries present - Environment has executable binaries
- Packages installed - Package directories exist and contain files
- Directory structure - Required directories (bin, pkgs) exist
Cleaning Up Environments
The env:clean
command automatically removes unused or problematic environments:
# Preview what would be cleaned
launchpad env:clean --dry-run
# Clean environments older than 30 days (default)
launchpad env:clean
# Clean environments older than 7 days
launchpad env:clean --older-than 7
# Force cleanup without confirmation
launchpad env:clean --force
# Verbose cleanup with details
launchpad env:clean --verbose
Cleanup Criteria:
- Environments with no binaries (failed installations)
- Environments older than specified days (default: 30)
- Empty or corrupted environment directories
Removing Specific Environments
Remove individual environments by their hash:
# Remove with confirmation
launchpad env:remove dummy_6d7cf1d6
# Force removal without confirmation
launchpad env:remove minimal_3a5dc15d --force
# Verbose removal showing details
launchpad env:remove working-test_208a31ec --verbose
Advanced Environment Features
Environment Variables and Context
Each environment can export specific variables:
# Check current environment context
echo $LAUNCHPAD_ENV_HASH
echo $LAUNCHPAD_PROJECT_NAME
# Use in scripts
if [ -n "$LAUNCHPAD_ENV_HASH" ]; then
echo "Running in Launchpad environment: $LAUNCHPAD_PROJECT_NAME"
fi
Environment Performance
- Fast activation - Subsequent entries to the same project use cached installations
- Isolated PATH - Each environment has its own binary resolution
- Memory efficient - Environments share common dependencies when possible
- Disk optimization - Human-readable hashes improve filesystem performance
Integration with Development Tools
Environments work seamlessly with development tools:
Node.js project example:
dependencies:
- node@22
- typescript@5.0
- yarn@1.22
env:
NODE_ENV: development
TYPESCRIPT_CONFIG: ./tsconfig.dev.json
Python project example:
dependencies:
- python@3.12
- pip
- poetry@1.5
env:
PYTHONPATH: ./src
VIRTUAL_ENV: ./.venv
Troubleshooting Environment Issues
Environment Not Activating
Check shell integration:
bashtype _pkgx_chpwd_hook
Verify dependency file:
bashlaunchpad dev:dump --dryrun
Check file detection:
bashls -la dependencies.yaml
Environment Messages Not Showing
Check message settings:
bashecho $LAUNCHPAD_SHOW_ENV_MESSAGES
Verify shell integration:
bashgrep "launchpad dev:shellcode" ~/.zshrc
Test manual activation:
eval "$(launchpad dev:shellcode)"
Performance Issues
Clean old environments:
bashlaunchpad env:clean --older-than 7
Check disk usage:
bashdu -sh ~/.local/share/launchpad/envs/*
Monitor activation time:
bashtime (cd my-project && cd ..)
## Best Practices
### Environment Naming
- Use descriptive project directory names
- Avoid special characters that might cause filesystem issues
- Keep project names reasonably short for readable hashes
### Dependency Management
- **Pin versions** in dependency files for reproducible environments
- **Use semantic versioning** ranges when appropriate (`^1.2.0`, `~3.1.0`)
- **Document environment variables** in your project README
### Cleanup Strategy
- **Regular cleanup** - Run `env:clean` periodically to remove old environments
- **Monitor disk usage** - Large environments can consume significant space
- **Remove unused projects** - Clean up environments for deleted projects
### Troubleshooting
**Environment not activating:**
1. Check shell integration: `echo 'eval "$(launchpad dev:shellcode)"' >> ~/.zshrc`
2. Verify dependency file exists and has correct syntax
3. Reload shell configuration: `source ~/.zshrc`
**Package installation failures:**
1. Check internet connectivity
2. Verify package names and versions exist in pkgx
3. Use `launchpad dev:dump --verbose` for detailed error information
**Hash collisions (rare):**
1. Different projects with same name get different hashes based on full path
2. If collision occurs, rename one of the project directories
3. Remove old environment: `launchpad env:remove {hash}`
## Advanced Usage
### Scripting with JSON Output
Use JSON output for automation:
```bash
#!/bin/bash
# Clean up environments larger than 100MB
envs=$(launchpad env:list --format json)
echo "$envs" | jq -r '.[] | select(.size | test("^[0-9]+[0-9][0-9]M|^[0-9]+G")) | .hash' | while read hash; do
echo "Removing large environment: $hash"
launchpad env:remove "$hash" --force
done
Integration with CI/CD
Clean up environments in CI pipelines:
# GitHub Actions example
- name: Clean old environments
run: |
launchpad env:clean --older-than 1 --force
Monitoring Environment Usage
Track environment disk usage:
# Show environments sorted by size
launchpad env:list --format json | jq -r 'sort_by(.size) | reverse | .[] | "\(.projectName): \(.size)"'