Skip to content

CLI Commands

Authenticate with the Hapnd API.

Terminal window
npx @hapnd/cli login <api-key>

Validates the key against /auth/whoami, then stores it in ~/.hapnd/config.json. Exits with an error if the key is invalid or the API is unreachable.

Clear stored credentials.

Terminal window
npx @hapnd/cli logout

Show current authentication status.

Terminal window
npx @hapnd/cli whoami

Displays tenant name, masked API key, and whether the key came from the config file or HAPND_API_KEY environment variable. Exits with a warning if not authenticated.

Create a hapnd.json configuration file in the current directory.

Terminal window
npx @hapnd/cli init
npx @hapnd/cli init --reducer
npx @hapnd/cli init --projection

The config file tells the CLI what kind of project this is. If you don’t use hapnd.json, the CLI auto-detects from your source code (looks for IReducer<T> or IProjection<T> implementations).

Upload and compile a reducer or projection.

Terminal window
npx @hapnd/cli deploy [path] [--dry-run] [--wait]
OptionDescription
pathDirectory to deploy from. Defaults to current directory.
--dry-runValidate the project without uploading. Shows what would be deployed.
--waitWait for compilation to complete before returning.

The CLI:

  1. Scans the directory for .cs files
  2. Detects the project type from the .csproj or hapnd.json
  3. Determines whether it’s a reducer or projection (from interface implementations)
  4. Zips the source files
  5. Uploads to Hapnd
  6. Returns the deployment ID

Example output:

Scanning /Users/you/src/MyReducers...
Detected:
Language: C#
Kind: reducer
Files: 3
Files to deploy:
OrderReducer.cs
OrderState.cs
EventData.cs
✓ Deployed successfully
ID: red_abc123def456
Status: compiling

For multi-reducer DLLs, all IReducer<T> implementations are discovered and auto-bound to their aggregate types on successful compilation.

Bind a reducer to an aggregate type. This tells Hapnd to run the reducer on every event appended to aggregates of that type.

Terminal window
npx @hapnd/cli bind <aggregate-type> <reducer-id>

Example:

Terminal window
npx @hapnd/cli bind order red_abc123def456

Output:

✓ Reducer bound successfully
Aggregate Type: order
Reducer: red_abc123def456
Bound At: 2026-03-15T18:30:00.000Z

Binding is typically automatic when deploying multi-reducer DLLs. Use this command to manually bind or rebind a reducer to a different aggregate type.

Check the compilation status of a deployment.

Terminal window
npx @hapnd/cli status <id>

Example:

Terminal window
npx @hapnd/cli status red_abc123def456

Output for a successful compilation:

Deployment Status
ID: red_abc123def456
Status: compiled
Kind: reducer
Created: 2026-03-15T18:30:00.000Z
Class: MyReducers.OrderReducer
State: MyReducers.OrderState
Compiled: 2026-03-15T18:30:05.000Z

Output for a failed compilation:

Deployment Status
ID: red_abc123def456
Status: failed
Kind: reducer
Created: 2026-03-15T18:30:00.000Z
Compilation Error:
error CS0246: The type or namespace name 'HttpClient' could not be found

Possible statuses:

StatusMeaning
pending_compilationUploaded, waiting in the compilation queue
compilingCurrently being compiled
compiledSuccessfully compiled and ready to use
failedCompilation failed — check the error output