> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/solana-foundation/anchor/llms.txt
> Use this file to discover all available pages before exploring further.

# anchor init

> Initialize a new Anchor workspace with programs, tests, and configurations

## 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

```bash theme={null}
anchor init <name> [OPTIONS]
```

## Arguments

<ParamField path="name" type="string" required>
  Workspace name. Must be a valid Rust identifier (no reserved words, cannot start with a digit).
</ParamField>

## Options

<ParamField path="--javascript" type="flag" default="false">
  Use JavaScript instead of TypeScript for test files
</ParamField>

<ParamField path="--no-install" type="flag" default="false">
  Don't install JavaScript dependencies after initialization
</ParamField>

<ParamField path="--package-manager" type="enum" default="yarn">
  Package manager to use for installing dependencies

  **Options:** `yarn`, `npm`, `pnpm`, `bun`
</ParamField>

<ParamField path="--no-git" type="flag" default="false">
  Don't initialize a git repository
</ParamField>

<ParamField path="--template" type="enum" default="multiple">
  Rust program template to use

  **Options:**

  * `single`: Program with a single `lib.rs` file (not recommended for production)
  * `multiple`: Program with multiple files for instructions, state, etc. (recommended)
</ParamField>

<ParamField path="--test-template" type="enum" default="mocha">
  Test template to use

  **Options:** `mocha`, `jest`, `rust`, `mollusk`
</ParamField>

<ParamField path="--force" type="flag" default="false">
  Initialize even if there are files in the directory
</ParamField>

## Examples

### Basic Initialization

Create a new workspace with default settings:

```bash theme={null}
anchor init my_project
```

**Output:**

```
my_project initialized
```

### Using JavaScript with npm

```bash theme={null}
anchor init my_project --javascript --package-manager npm
```

### Custom Template Configuration

Use a single-file program template with Jest tests:

```bash theme={null}
anchor init my_project --template single --test-template jest
```

### Skip Dependency Installation

```bash theme={null}
anchor init my_project --no-install
```

## Generated Structure

The command creates the following directory structure:

```
my_project/
├── .anchor/
├── app/
├── programs/
│   └── my_project/
│       ├── src/
│       │   ├── lib.rs
│       │   ├── constants.rs (multiple template)
│       │   ├── error.rs (multiple template)
│       │   ├── instructions.rs (multiple template)
│       │   ├── instructions/
│       │   │   └── initialize.rs (multiple template)
│       │   └── state.rs (multiple template)
│       └── Cargo.toml
├── tests/
│   └── my_project.ts
├── migrations/
│   └── deploy.ts
├── target/
│   └── deploy/
│       └── my_project-keypair.json
├── Anchor.toml
├── Cargo.toml
├── package.json
├── tsconfig.json
├── .gitignore
└── .prettierignore
```

## 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

<Note>
  The workspace name is converted to snake\_case for Rust identifiers and kebab-case for directory names.
</Note>

<Warning>
  The command will fail if a workspace already exists in the current directory, unless `--force` is specified.
</Warning>

<Tip>
  Use the `multiple` template (default) for better code organization and maintainability in production applications.
</Tip>
