Complete end-to-end guide for new contributors to Socket CLI.
Before starting, ensure you have:
| Requirement | Minimum Version | Check Command |
|---|---|---|
| Node.js | 18.0.0+ | node --version |
| pnpm | 10.16.0+ | pnpm --version |
| Git | 2.0+ | git --version |
| Disk Space | ~5 GB | df -h . |
Node.js 18+:
# macOS (using Homebrew)
brew install node@20
# Linux (using nvm)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 20
# Windows (using Chocolatey)
choco install nodejs-ltspnpm 10.16+:
# Using npm (comes with Node.js)
npm install -g pnpm
# Or using Homebrew (macOS)
brew install pnpm
# Or use corepack (built into Node.js 16+)
corepack enable
corepack prepare pnpm@latest --activate
# Verify installation
pnpm --version # Should be 10.16.0 or higherGet Socket CLI running locally in 5 steps:
# 1. Clone the repository
git clone https://github.com/SocketDev/socket-cli.git
cd socket-cli
# 2. Install dependencies
pnpm install
# 3. Build the CLI
pnpm run build
# 4. Test the CLI
pnpm exec socket --version
# 5. Run tests
pnpm run test:unitExpected output:
$ pnpm exec socket --version
CLI: v1.2.0
If you see the version number, congratulations! Your setup is working.
Note: You may see a banner with token/org info - this is normal and comes from your local config. Most commands work without an API token during development.
# Clone from GitHub
git clone https://github.com/SocketDev/socket-cli.git
cd socket-cli
# Or if you have SSH keys configured
git clone git@github.com:SocketDev/socket-cli.git
cd socket-cliVerification:
ls -la
# Should see: package.json, packages/, docs/, etc.pnpm installWhat this does:
- Installs all npm dependencies
- Sets up pnpm workspace for the monorepo
- Links internal packages together
- Downloads Socket registry overrides
Expected output:
Packages: +500
++++++++++++++++++++++++++++++++
Progress: resolved 500, reused 500, downloaded 0, added 500, done
Verification:
ls -la node_modules
# Should see many packages installedpnpm run buildWhat this does:
- Compiles TypeScript source files to JavaScript
- Generates type definitions
- Creates the
dist/directory with built files - Takes ~30 seconds
Expected output:
> socket-cli@1.0.80 build
> pnpm run build:cli
✓ TypeScript compilation complete
✓ Type definitions generated
✓ Build artifacts created in dist/
Verification:
ls -la packages/cli/dist
# Should see: cli.js and other compiled files# Run using pnpm exec (recommended)
pnpm exec socket --versionTry some commands:
# Show help
pnpm exec socket --help
# These work without API token
pnpm exec socket --version
pnpm exec socket --help-full
# Commands that require API token
pnpm exec socket package lodash --view
pnpm exec socket scan create# Run all tests (lint, type-check, unit tests)
pnpm run test
# Or run just unit tests (from CLI package)
pnpm --filter @socketsecurity/cli run test:unit
# Or run specific test file
pnpm --filter @socketsecurity/cli run test:unit src/commands/scan/cmd-scan.test.mtsExpected output:
✓ packages/cli/src/commands/scan/cmd-scan.test.mts (10 tests) 234ms
✓ packages/cli/src/utils/config.test.mts (15 tests) 156ms
Test Files 2 passed (2)
Tests 25 passed (25)
Verification:
echo $?
# Should output: 0 (success)-
Create a feature branch:
git checkout -b feature/my-awesome-feature
-
Make your changes:
- Edit files in
packages/cli/src/ - Follow the code style in
CLAUDE.md - Use
.mtsextension for TypeScript files
- Edit files in
-
Build and test:
pnpm run build pnpm run test:unit
-
Test your changes:
# Run the CLI with your changes pnpm exec socket <your-command> # Or use the quick build + run script pnpm run bs <your-command>
Build the CLI:
pnpm run buildRun the CLI:
# After building
pnpm exec socket --help
pnpm exec socket --version
# Test basic commands (no API token required)
pnpm exec socket --version
pnpm exec socket --helpRun tests:
# All tests (includes build step)
pnpm run test
# Just unit tests
pnpm --filter @socketsecurity/cli run test:unit
# Specific test file
pnpm --filter @socketsecurity/cli run test:unit src/commands/scan/cmd-scan.test.mtsFix linting issues:
pnpm run fixType checking:
pnpm run typeUpdate test snapshots:
# Update all snapshots
pnpm run testu
# Update specific test file
pnpm run testu packages/cli/src/commands/scan/cmd-scan.test.mtsTest a single file (fast):
pnpm --filter @socketsecurity/cli run test:unit src/utils/config.test.mtsTest with pattern matching:
pnpm --filter @socketsecurity/cli run test:unit src/commands/scan/cmd-scan.test.mts -t "should handle errors"Test with coverage:
pnpm --filter @socketsecurity/cli run test:unit:coverageWatch mode (auto-rerun on changes):
pnpm --filter @socketsecurity/cli run test:unit -- --watchUnderstanding the codebase organization:
socket-cli/
├── packages/cli/ # Main CLI package
│ ├── src/
│ │ ├── cli.mts # Entry point
│ │ ├── commands/ # Command implementations
│ │ │ ├── scan/ # Scan command
│ │ │ │ ├── cmd-scan.mts # Command definition
│ │ │ │ ├── handle-scan.mts # Business logic
│ │ │ │ └── output-scan.mts # Output formatting
│ │ │ ├── optimize/ # Optimize command
│ │ │ └── ... # Other commands
│ │ ├── utils/ # Shared utilities
│ │ ├── types.mts # Type definitions
│ │ └── constants.mts # Constants
│ ├── dist/ # Build output (gitignored)
│ └── test/ # Test files
├── packages/yoga-layout/ # WASM builder for Yoga
├── packages/onnx-runtime-builder/ # ONNX Runtime WASM
├── packages/minilm-builder/ # ML model builder
├── packages/node-smol-builder/ # Custom Node.js builder
├── packages/node-sea-builder/ # SEA binary builder
├── docs/ # Documentation
│ ├── architecture/ # System design
│ ├── build/ # Build guides
│ ├── development/ # Developer guides
│ └── testing/ # Testing strategies
└── scripts/ # Build and utility scripts
Each command follows this pattern:
cmd-*.mts- Command definition and CLI interface (meow flags, help text)handle-*.mts- Business logic and processingoutput-*.mts- Output formatting (JSON, markdown, etc.)fetch-*.mts- API calls (when applicable)
Example: Scan command
commands/scan/
├── cmd-scan.mts # CLI interface, flags
├── handle-scan.mts # Processing logic
├── output-scan.mts # Format results
└── fetch-scan.mts # API interactions
Socket CLI includes several advanced build components. You typically don't need to build these for CLI development, but here's how:
# Build all WASM components
node scripts/build-all-binaries.mjs --wasm-only
# Or build individually
cd packages/yoga-layout
pnpm run buildRequirements:
- Emscripten SDK (for yoga-layout)
- Rust + wasm-pack (for ONNX, models)
# Build custom Node.js for current platform
node scripts/build-all-binaries.mjs --smol-onlyRequirements:
- Python 3.8+
- C++ compiler (GCC, Clang, or MSVC)
- ~10 GB disk space
- ~30 minutes build time
See: Build Quick Start
For developing with local versions of Socket dependencies:
# Link to local socket-registry and socket-sdk-js
node scripts/setup-links.mjs
# This enables hot-reloading from sibling repositoriesSee: Development Linking
This is normal - Socket CLI reads your local config file (.socketrc.json or environment variables). Most commands work without an API token during development:
# These work without API token
pnpm exec socket --version
pnpm exec socket --help
# These require API token
pnpm exec socket package lodash --view
pnpm exec socket scan createTo suppress config, use --config '{}':
pnpm exec socket --config '{}' --version# Install pnpm globally
npm install -g pnpm
# Or use corepack (built into Node.js 16+)
corepack enable
corepack prepare pnpm@latest --activate# Clean and reinstall dependencies
rm -rf node_modules packages/*/node_modules
pnpm install
pnpm run build# Ensure you built first
pnpm run build
# Run specific failing test for debugging
pnpm test:unit <path-to-test> -t "test name"
# Check if snapshots need updating
pnpm run testu# Increase Node.js memory limit
export NODE_OPTIONS="--max-old-space-size=4096"
pnpm run build# Rebuild the project
pnpm run build
# Run type checker
pnpm run type# Clean and rebuild
pnpm run clean
pnpm run build
# Or build just what you need
pnpm --filter @socketsecurity/cli run build# Check that build succeeded
ls -la packages/cli/dist/cli.js
# Try running directly
node packages/cli/dist/cli.js --version
# Check Node version
node --version # Should be 20+# Fix linting issues first
pnpm run fix
# Or bypass hooks temporarily (not recommended)
git commit --no-verifyNow that you have Socket CLI running locally:
-
Read the architecture docs:
-
Learn the coding standards:
- Read
CLAUDE.mdin the repository root - Review existing commands for patterns
- Read
-
Pick an issue to work on:
- Browse GitHub Issues
- Look for "good first issue" labels
-
Make your first contribution:
- Create a feature branch
- Make your changes
- Write tests
- Submit a pull request
If you encounter issues not covered here:
-
Check existing documentation:
-
Search GitHub Issues
-
Ask in Socket Community Discord
-
File a Bug Report
| Task | Command |
|---|---|
| Install dependencies | pnpm install |
| Build CLI | pnpm run build |
| Run CLI | pnpm exec socket <command> |
| Run all tests | pnpm run test |
| Run unit tests | pnpm --filter @socketsecurity/cli run test:unit |
| Fix linting | pnpm run fix |
| Type check | pnpm run type |
| Clean build artifacts | pnpm run clean |
Before submitting your first PR, verify:
-
pnpm installcompletes successfully -
pnpm run buildcompletes without errors -
pnpm exec socket --versionshows version number -
pnpm run test:unitpasses all tests -
pnpm run typepasses without errors -
pnpm run fixfixes any linting issues - Your code follows patterns in
CLAUDE.md - You've tested your changes locally
Welcome to Socket CLI development!