This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build- Compiles TypeScript usingtsc --project tsconfig.build.jsonnpm run dev- Runs TypeScript compiler in watch modenpm run clean- Removes thedist/directory
npm test- Runs the full test suite (unit, integration, and e2e tests)npm run test:unit- Runs unit tests only withvitest run tests/unit/npm run test:integration- Runs integration tests withvitest run --retry=3 tests/integration/npm run test:e2e- Runs end-to-end tests withvitest run --config vitest.e2e.config.ts- Single test file:
npm exec vitest -- run tests/unit/lib/account.test.ts - Single test by name:
npm exec vitest -- run tests/unit/lib/account.test.ts -t 'test name' - Debug tests:
DEBUG_TESTS=true npm exec vitest -- run [test-file] -t 'test name' npm run test:init- Sets up test dependencies for various fixtures (Hugo, Next.js, monorepo)
npm run lint- Runs ESLint with cachenpm run lint:fix- Runs ESLint and automatically fixes issuesnpm run format- Formats code with Prettiernpm run format:check- Checks code formatting without modifying filesnpm run typecheck- Runs TypeScript type checkingnpm run typecheck:watch- Runs TypeScript type checking in watch mode
./bin/run.js [command]- Runs the CLI locallyDEBUG=true ./bin/run.js [command]- Runs with stack traces enabled for debuggingnpm run start -- [command]- Alternative way to run CLI locally
The Netlify CLI is built with Commander.js for CLI interface, @netlify/js-client for API interactions, and TypeScript with modular architecture. The system uses a registry pattern for managing Functions and Edge Functions, with sophisticated local development server capabilities.
- All commands extend
BaseCommandclass (src/commands/base-command.ts) which provides:- Consistent config loading and API client setup
- Site information management and linking
- Authentication and token handling
- Analytics and telemetry integration
- Commands follow a modular structure with separate
index.tsfiles for exports - Each command supports both interactive prompts and non-interactive flag-based operation
- FunctionsRegistry (
src/lib/functions/registry.ts): Manages Netlify Functions lifecycle- Supports multiple runtimes (JavaScript/TypeScript, Go, Rust)
- Handles hot reloading and file watching
- Manages function builds and serving
- EdgeFunctionsRegistry (
src/lib/edge-functions/registry.ts): Manages Edge Functions- Uses
@netlify/edge-bundlerfor Deno-based edge runtime - Handles Edge Function deployment and local serving
- Uses
The dev server (src/commands/dev/dev.ts) orchestrates multiple subsystems:
- Proxy Server: Routes requests between static files, functions, and edge functions
- Functions Server: Executes Netlify Functions locally with runtime-specific handlers
- Edge Functions Proxy: Serves Edge Functions via Deno runtime
- Framework Detection: Auto-detects and integrates with various web frameworks
- Live Tunneling: Provides public URLs for local development via Netlify's tunnel service
- Uses
@netlify/configfor configuration resolution and normalization - Supports
netlify.tomlfiles with environment-specific overrides - Integrates with Netlify's build plugins system
- Handles environment variable injection from multiple sources (process, .env files, Netlify site settings)
src/lib/api.ts- Netlify API client wrapper with authenticationsrc/lib/build.ts- Build system integration and config cachingsrc/lib/settings.ts- Project and global settings managementsrc/utils/command-helpers.ts- Shared utilities for CLI commands (logging, error handling, prompts)
src/lib/functions/runtimes/- Runtime-specific builders and executorsjs/- JavaScript/TypeScript function handling withzip-it-and-ship-itgo/- Go function compilation and executionrust/- Rust function compilation via Cargo
src/lib/functions/server.ts- Local function server with request/response handling
src/utils/dev.ts- Development server utilities and environment setupsrc/utils/proxy-server.ts- HTTP proxy for routing dev server requestssrc/utils/detect-server-settings.ts- Framework detection and port management
src/utils/deploy/- Site deployment orchestration- File hashing, diffing, and upload optimization
- Build artifact management and caching
- Progress tracking and status reporting
- Unit Tests (
tests/unit/): Test individual modules and utilities - Integration Tests (
tests/integration/): Test full command workflows using fixtures - E2E Tests: Test complete user scenarios with real Netlify API interactions
- Fixtures (
tests/integration/__fixtures__/): Sample projects for testing different frameworks and configurations
Environment variables are loaded from multiple sources with specific precedence:
- Process environment
.envfiles (multiple variants supported)- Netlify site settings (shared, project-specific)
- Addon-provided variables
- Build-time configuration
Functions are accessible via standardized URL patterns:
/.netlify/functions/[function-name]- Standard functions/.netlify/builders/[function-name]- On-demand builders- Custom paths supported via function configuration
The CLI integrates with Netlify's build plugin system, allowing plugins to:
- Modify build configuration
- Add custom build steps
- Integrate with the development server
- Provide additional CLI commands
- Node.js 20.12.2+ required
- Git LFS must be installed for full test suite
- Some integration tests require Netlify Auth Token (
NETLIFY_AUTH_TOKEN) or login via./bin/run.js login
- Never write comments on what the code does, make the code clean and self explanatory instead