Overview
Theanchor init command creates a new Anchor workspace with all necessary files and directories, including program templates, test configurations, and package management setup.
Command Syntax
Arguments
Workspace name. Must be a valid Rust identifier (no reserved words, cannot start with a digit).
Options
Use JavaScript instead of TypeScript for test files
Don’t install JavaScript dependencies after initialization
Package manager to use for installing dependenciesOptions:
yarn, npm, pnpm, bunDon’t initialize a git repository
Rust program template to useOptions:
single: Program with a singlelib.rsfile (not recommended for production)multiple: Program with multiple files for instructions, state, etc. (recommended)
Test template to useOptions:
mocha, jest, rust, molluskInitialize even if there are files in the directory
Examples
Basic Initialization
Create a new workspace with default settings:Using JavaScript with npm
Custom Template Configuration
Use a single-file program template with Jest tests:Skip Dependency Installation
Generated Structure
The command creates the following directory structure:Configuration Files
Anchor.toml
The workspace configuration file is created with:- Default cluster set to
localnet - Program deployment configuration
- Test script configuration
- Toolchain settings (package manager)
Cargo.toml
Root workspace manifest with:- Workspace members pointing to
programs/* - Release profile optimizations
- Overflow checks enabled
Notes
The workspace name is converted to snake_case for Rust identifiers and kebab-case for directory names.