Arkenv

From yamcodes/arkenv · View interactive version

Arkenv is an AI agent skill from the GitHub repository yamcodes/arkenv. Answer questions about ArkEnv and help implement environment variable validation. Use when developers: (1) Ask about environment variable validation or typesafety, (2) Want to setup ArkEnv in a project, (3) Need to define or update schemas using ArkType or Standard Schema, (4) Are integrating with N

How to use this skill

Skill file

ArkEnv

ArkEnv is a typesafe environment variable validation library for modern JavaScript and TypeScript frameworks. It provides a single canonical surface across all frameworks: import { env } from "./env".

In v1, ArkEnv offers two first-class validation engines:


Capabilities

Core usage

Framework integration

CLI (setup & DevOps)

Hosting presets

ArkEnv is code-first. You can select a hosting provider preset during initial project setup (--preset vercel, netlify, cloudflare, railway, render, fly) or copy-paste provider fields directly into ./env.ts from the documentation (/docs/core-concepts/hosting-presets). There are no machine-managed comment blocks or CLI mutation commands.

Agent setup (machine-readable)

AI agents SHOULD always use the CLI for project initialization to ensure consistency and reliability. Use the --agent flag for a fully automated, machine-readable experience.

Handling refusals (`ok: false`)

--agent never implies --force. When a safety check trips, the CLI refuses and emits an errored settlement envelope to stdout:

{
  "ok": false,
  "commandId": "init",
  "error": {
    "code": "CLI.GIT_TREE_DIRTY",
    "severity": "error",
    "summary": "Git working tree is not clean.",
    "why": "Commit or stash your changes before running arkenv init.",
    "nextActions": [
      {
        "kind": "run-command",
        "label": "Re-run with --force to bypass git working tree check",
        "command": "arkenv init --force"
      }
    ]
  },
  "diagnostics": [],
  "nextActions": [
    {
      "kind": "run-command",
      "label": "Re-run with --force to bypass git working tree check",
      "command": "arkenv init --force"
    }
  ]
}

Escalation pattern: always run init --agent without --force first. If you get ok: false, inspect error.code and nextActions. Only re-run with --force (or the command from a run-command action) once you have deliberately decided the refusal is safe to bypass — do not add --force pre-emptively.


CLI commands

`init`

Set up ArkEnv in your project. It detects your framework and configures the appropriate plugin and schema.

pnpm dlx arkenv init [options]
Options:

`check`

Validate the environment against your schema file.

pnpm arkenv check [options]
Options:

Defining Schemas & Importing `env`

`@arkenv/core` (ArkType DSL)

import arkenv from "@arkenv/core";

export const env = arkenv({
  PORT: "number.port = 3000",
  DATABASE_URL: "string",
  VITE_API_URL: "string",
  NODE_ENV: "'development' | 'production' | 'test' = 'development'",
});

`@arkenv/standard` (Standard Schema: Zod, Valibot)

import arkenv from "@arkenv/standard";
import * as z from "zod";

export const env = arkenv({
  PORT: z.number().default(3000),
  DATABASE_URL: z.string(),
  VITE_API_URL: z.url(),
  NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
});

Valibot uses the /valibot subpath (install @valibot/to-json-schema as well):

import { arkenv } from "@arkenv/standard/valibot";
import * as v from "valibot";

export const env = arkenv({
  PORT: v.optional(v.number(), 3000),
  DATABASE_URL: v.pipe(v.string(), v.url()),
});

Consuming `env` in Application Code

Always import and read properties directly from the canonical env object:

import { env } from "./env";

export default function App() {
  const apiUrl = env.VITE_API_URL; // string
  return <div>API URL: {apiUrl}</div>;
}

Framework Setup Patterns

1. Vite (`@arkenv/vite-plugin`)

Register the plugin in vite.config.ts without schema arguments:

import { defineConfig } from "vite";
import arkenvPlugin from "@arkenv/vite-plugin";

export default defineConfig({
  plugins: [arkenvPlugin()],
});

If you need environment variables inside vite.config.ts itself (e.g. server.port), validate them with loadEnv:

import { defineConfig, loadEnv } from "vite";
import arkenvPlugin from "@arkenv/vite-plugin";
import arkenv, { type } from "@arkenv/core";

export const Env = type({
  PORT: "number.port = 5173",
  VITE_API_URL: "string",
});

export default defineConfig(({ mode }) => {
  const env = arkenv(Env, { env: loadEnv(mode, process.cwd(), "") });
  return {
    plugins: [arkenvPlugin()],
    server: { port: env.PORT },
  };
});

2. Bun (`@arkenv/bun-plugin`)

In bunfig.toml:

[serve.static]
plugins = ["@arkenv/bun-plugin"]

In Bun.build:

import arkenvPlugin from "@arkenv/bun-plugin";

await Bun.build({
  entrypoints: ["./src/index.tsx"],
  outdir: "./dist",
  plugins: [arkenvPlugin],
});

Security Boundaries & Layouts


Best Practices & Rules

  1. Always use import { env } from "./env": Never use import.meta.env or process.env directly for application environment variables in v1.
  2. Never create ambient .d.ts augmentations: ImportMetaEnvAugmented and ProcessEnvAugmented are legacy v0 patterns dropped in v1.
  3. Keep secrets on the server: Never prefix server secrets (DATABASE_URL, API_SECRET_KEY) with client prefixes (VITE_, NEXT_PUBLIC_, BUN_PUBLIC_, NUXT_PUBLIC_).
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.