Skip to main content

Overview

The anchor 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

string
required
Workspace name. Must be a valid Rust identifier (no reserved words, cannot start with a digit).

Options

flag
default:"false"
Use JavaScript instead of TypeScript for test files
flag
default:"false"
Don’t install JavaScript dependencies after initialization
enum
default:"yarn"
Package manager to use for installing dependenciesOptions: yarn, npm, pnpm, bun
flag
default:"false"
Don’t initialize a git repository
enum
default:"multiple"
Rust program template to useOptions:
  • single: Program with a single lib.rs file (not recommended for production)
  • multiple: Program with multiple files for instructions, state, etc. (recommended)
enum
default:"mocha"
Test template to useOptions: mocha, jest, rust, mollusk
flag
default:"false"
Initialize even if there are files in the directory

Examples

Basic Initialization

Create a new workspace with default settings:
Output:

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.
The command will fail if a workspace already exists in the current directory, unless --force is specified.
Use the multiple template (default) for better code organization and maintainability in production applications.