Complete command-line interface reference for CodeMachine.
CodeMachine provides a command-line interface for managing workflows, executing agents, and configuring your development environment.
Basic Usage:
codemachine [command] [options]Global Options:
| Option | Description | Default |
|---|---|---|
-d, --dir <path> |
Target workspace directory | process.cwd() |
--spec <path> |
Path to planning specification file | .codemachine/inputs/specifications.md |
-h, --help |
Display help for command | - |
Package Binary:
- Entry point:
./dist/index.js - Command name:
codemachine
When no command is provided, CodeMachine starts in interactive session mode.
Usage:
codemachine
codemachine -d /path/to/workspaceFeatures:
- Interactive shell session with keyboard controls
- Real-time workflow execution
- Template selection menu
- Authentication management
- Onboarding for new users
Session Flow:
- CLI checks working directory (
-doption or current directory) - Syncs configuration for all registered engines
- Bootstraps
.codemachine/folder if it doesn't exist - Enters interactive shell with main menu
Workspace Structure:
.codemachine/
├── inputs/
│ └── specifications.md # Default spec file
├── template.json # Selected template
└── [engine-specific-configs]
Commands for managing and executing workflows.
Run the workflow queue until completion in non-interactive mode.
Syntax:
codemachine start [options]Options:
| Option | Description | Default |
|---|---|---|
--spec <path> |
Path to the planning specification file | .codemachine/inputs/specifications.md |
Behavior:
- Executes workflow queue sequentially
- Runs in non-interactive mode (no user prompts)
- Exits with status code on completion
Exit Codes:
0- Workflow completed successfully1- Workflow failed
Output Messages:
- Success:
✓ Workflow completed successfully - Error:
✗ Workflow failed: [error message]
Examples:
# Run workflow with default spec
codemachine start
# Run workflow with custom spec
codemachine start --spec ./custom/planning.md
# Run in specific directory
codemachine -d /path/to/project start
# Custom directory and spec
codemachine -d /path/to/project start --spec ./specs/feature.mdUse Cases:
- CI/CD pipeline automation
- Batch workflow execution
- Automated code generation scripts
- Testing workflows
Technical Details:
- Source:
src/cli/commands/start.command.ts - Non-blocking execution
- Error handling with detailed messages
List and select workflow templates interactively.
Syntax:
codemachine templatesArguments: None
Options: None
Behavior:
- Lists all available workflow templates from
templates/workflows/ - Displays interactive selection menu
- Auto-regenerates agents folder when template changes
- Saves selection to
.codemachine/template.json
Template Format:
- Files ending with
.workflow.js - Located in
templates/workflows/directory - Export workflow configuration and agent definitions
Examples:
# List and select template interactively
codemachine templates
# Use in specific workspace
codemachine -d /path/to/project templatesTemplate Storage:
- Selection saved to:
.codemachine/template.json - Default template:
templates/workflows/codemachine.workflow.js - Example template:
templates/workflows/_example.workflow.js
Use Cases:
- Switch between different workflow types
- Initialize new projects with specific templates
- Customize agent configurations per project
Technical Details:
- Source:
src/cli/commands/templates.command.ts - Supports both interactive and programmatic selection
- Triggers agent folder regeneration on template change
Commands for executing agents and workflow steps during development.
Execute single agents or orchestrate multiple agents with the unified run command.
Syntax:
codemachine run <script>
codemachine <engine-name> run <script>Arguments:
| Argument | Required | Description |
|---|---|---|
<script> |
Yes | Agent execution script with optional orchestration syntax |
Options:
| Option | Description | Default |
|---|---|---|
--model <model> |
Model to use (overrides agent config) | Agent's configured model |
-d, --dir <directory> |
Working directory | process.cwd() |
Script Syntax:
The <script> parameter supports several formats:
-
Simple agent execution:
"agent-id 'prompt'" -
Enhanced syntax with parameters:
"agent-id[input:file1.md;file2.md,tail:100] 'prompt'"Available parameters:
input:<file>orinput:<file1>;<file2>- Include file content(s) in agent contexttail:<number>- Limit file content to last N lines
-
Parallel execution (using
&):"agent1 'prompt1' & agent2 'prompt2' & agent3 'prompt3'" -
Sequential execution (using
&&):"agent1 'prompt1' && agent2 'prompt2' && agent3 'prompt3'" -
Mixed execution:
"agent1 'prompt1' && agent2 'prompt2' & agent3 'prompt3'"
Engine-Specific Commands: Each registered engine can be invoked directly:
codemachine claude run "agent 'prompt'"
codemachine codex run "agent 'prompt'"
codemachine cursor run "agent 'prompt'"Examples:
# Simple single agent execution
codemachine run "code-generator 'Build login feature'"
# Agent with input files
codemachine run "system-analyst[input:.codemachine/agents/system-analyst.md,tail:100] 'analyze architecture'"
# Multiple input files without prompt
codemachine run "arch-writer[input:file1.md;file2.md;file3.md]"
# Parallel orchestration
codemachine run "frontend[tail:50] 'UI' & backend[tail:50] 'API' & db[tail:30] 'schema'"
# Sequential orchestration
codemachine run "db 'Setup schema' && backend 'Create models' && api 'Build endpoints'"
# Mixed orchestration
codemachine run "db[tail:50] 'setup' && frontend[input:design.md,tail:100] & backend[input:api-spec.md,tail:100]"
# With specific engine
codemachine claude run "code-generator 'Create a login component'"
# Override model
codemachine run "code-generator 'Create component'" --model gpt-4
# In specific workspace
codemachine -d /my/project run "my-agent 'Generate tests'"Agent Resolution:
- Searches
config/main.agents.js - Searches
config/sub.agents.js - Throws error if agent ID not found
Execution Behavior:
&operator: Agents execute in parallel&&operator: Agents execute sequentially (waits for previous completion)- Mixed: Evaluates left-to-right with operator precedence
- Enhanced syntax allows including file contents and limiting output
Use Cases:
- Single agent execution for quick tasks
- Multi-agent orchestration for complex workflows
- Including specification files in agent context
- Parallel feature development across multiple agents
- Sequential pipeline execution (design → implement → test)
Technical Details:
- Source:
src/cli/commands/run.command.ts - Uses
CoordinatorServicefor execution - Parses scripts via
CoordinatorParser - Replaces both old
agentandorchestratecommands - Supports enhanced syntax not available in legacy commands
Migration from Legacy Commands:
If you were using the old agent command:
# Old
codemachine agent code-generator "Create login"
# New
codemachine run "code-generator 'Create login'"If you were using the old orchestrate command:
# Old
codemachine orchestrate "frontend 'UI' & backend 'API'"
# New (same syntax, different command)
codemachine run "frontend 'UI' & backend 'API'"Execute a single workflow step using an agent from the main agents configuration.
Syntax:
codemachine step [options] <id> [prompt...]Arguments:
| Argument | Required | Description |
|---|---|---|
<id> |
Yes | Agent ID from config/main.agents.js |
[prompt...] |
No | Optional additional prompt to append to agent's main prompt |
Options:
| Option | Description | Default |
|---|---|---|
--model <model> |
Model to use | Resolved from priority chain |
--engine <engine> |
Engine to use | Resolved from priority chain |
--reasoning <level> |
Reasoning effort: low, medium, or high |
Agent's config or engine default |
Option Resolution Priority:
Engine Resolution:
- CLI
--engineoverride - Agent config
engineproperty - First authenticated engine
- Default engine (first registered)
Model Resolution:
- CLI
--modeloverride - Agent config
modelproperty - Engine's default model
Reasoning Resolution:
- CLI
--reasoningoverride - Agent config
modelReasoningEffort - Engine default reasoning level
Behavior:
- Executes main workflow agent in isolated step
- Requires engine authentication
- Displays formatted output with spinning indicators
- Stores last 2000 characters in memory
Examples:
# Execute step with agent's default config
codemachine step planner
# Execute with additional prompt
codemachine step planner "Focus on microservices architecture"
# Override engine
codemachine step planner --engine claude
# Override model
codemachine step planner --model gpt-4-turbo
# Override reasoning level
codemachine step planner --reasoning high
# Combine multiple overrides
codemachine step planner "Design API" --engine codex --model gpt-4 --reasoning high
# Execute in specific workspace
codemachine -d /project step implementation "Add error handling"Authentication:
- Requires authenticated engine
- Error message if engine not authenticated:
Engine '[engine-name]' requires authentication. Run: codemachine auth login
Agent Source:
- Only searches
config/main.agents.js - Does not search
config/sub.agents.js - Throws error if agent not found in main agents
Use Cases:
- Test individual workflow steps
- Debug main agents in isolation
- Experiment with different models/engines
- Run specific workflow phases manually
Technical Details:
- Source:
src/cli/commands/step.command.ts - Output formatting with typewriter effect
- Memory preservation for session context
- Authentication validation before execution
Commands for managing authentication and system configuration.
Authentication management for AI engine providers.
Subcommands:
auth login- Authenticate with a providerauth logout- Logout from a providerauth status- Inspect authentication status/details
Authenticate with CodeMachine AI engine services.
Syntax:
codemachine auth loginArguments: None
Options: None
Behavior:
- Displays interactive provider selection menu
- Lists all registered engine providers
- Calls provider's authentication system
- Stores credentials securely per engine
Provider Selection: Interactive menu shows:
- Provider name
- Authentication status (authenticated/not authenticated)
Already Authenticated: If already authenticated, displays:
Already authenticated with [Provider].
Use `codemachine auth logout` to sign out.
Examples:
# Interactive provider login
codemachine auth login
# Returns to menu after authentication
# Can authenticate multiple providersAuthentication Flow:
- Display registered providers
- User selects provider
- Provider-specific auth process (API key, OAuth, etc.)
- Credentials stored in engine config
- Confirmation message
Use Cases:
- Initial setup of AI engines
Inspect authentication status for a selected provider.
Syntax:
codemachine auth statusBehavior:
- Shows the same provider selection menu as
auth login/logout. - For Kimi CLI, prints detailed diagnostics: platform, CLI availability, inline env presence, resolved project root, override path, and every auth source (environment variables, override file, project file, legacy tmp) with existence/permissions info.
- For other providers, displays a concise ready/not ready message based on
isAuthenticated().
Use Cases:
- Debugging “already authenticated” vs missing key scenarios.
- Verifying which auth file (
CODEMACHINE_KIMI_AUTH_FILE, project.codemachine/kimi/auth.env, or tmp) contains the stored key. - Re-authenticate expired sessions
- Switch between different provider accounts
- Enable new engines in workspace
Technical Details:
- Source:
src/cli/commands/auth.command.ts - Providers loaded from engine registry
- Engine-specific authentication handlers
- Secure credential storage
Logout from CodeMachine AI engine services.
Syntax:
codemachine auth logoutArguments: None
Options: None
Behavior:
- Displays interactive provider selection menu
- Shows only authenticated providers
- Clears authentication for selected provider
- Updates engine configuration
Logout Confirmation:
Signed out from [Provider].
Next action will be `login`.
Examples:
# Interactive provider logout
codemachine auth logout
# Select provider from menu
# Credentials clearedUse Cases:
- Switch provider accounts
- Remove expired credentials
- Security: clear credentials when sharing machine
- Testing unauthenticated flows
Technical Details:
- Source:
src/cli/commands/auth.command.ts - Clears provider-specific credentials
- Updates configuration files
- Preserves other provider authentications
Utility and informational commands.
Display the CodeMachine CLI version.
Syntax:
codemachine version
codemachine --version
codemachine -VArguments: None
Options: None
Output:
CodeMachine v[version]
Examples:
codemachine version
# Output: CodeMachine v1.0.0Use Cases:
- Verify installation
- Check for updates
- Bug reporting
- Compatibility checks
CodeMachine dynamically registers engine-specific command variants for each registered AI engine.
Pattern:
codemachine <engine-name> run <script>Examples:
# Claude-specific agent execution
codemachine claude run "my-agent 'Generate code'"
# Codex-specific agent execution
codemachine codex run "my-agent 'Generate code'"
# Cursor engine variant
codemachine cursor run "my-agent 'Generate code'"
# Kimi engine variant
codemachine kimi run "my-agent 'Generate code'"
# OpenCode engine variant
codemachine opencode run "build hello world"Behavior:
- Same options and arguments as main
runcommand - Forces execution with specific engine
- Useful for engine comparison and testing
Dynamic Registration:
- Commands registered automatically at startup
- Based on engines in engine registry
- Each engine gets its own subcommand namespace
The OpenCode provider needs explicit permission defaults to stay non-interactive. When you run codemachine opencode ... or --engine opencode, the CLI injects (unless already set):
OPENCODE_PERMISSION={"*":"allow","bash":{"*":"allow"}}OPENCODE_DISABLE_LSP_DOWNLOAD=1andOPENCODE_DISABLE_DEFAULT_PLUGINS=1OPENCODE_CONFIG_DIR=$HOME/.codemachine/opencode(can be overridden)
You can also set CODEMACHINE_SKIP_OPENCODE=1 to dry-run pipelines without launching the CLI, or CODEMACHINE_PLAIN_LOGS=1 to strip ANSI markers in log exports.
When OpenCode introduces a permission that is not covered by your current policy, CodeMachine now pauses execution, surfaces the request via the standard selection menu (Allow once / Always allow / Reject), rewrites OPENCODE_PERMISSION accordingly, and retries the run. Choosing Always allow remembers the approval for the current CLI session so subsequent steps inherit the updated policy automatically.
Important: Disable OpenCode sub‑agents. CodeMachine coordinates sub‑agents at the workflow level and does not yet handle OpenCode’s engine‑native sub‑agents. Keeping them enabled can disconnect the OpenCode process and provides no benefit because CodeMachine already scopes tasks to a single agent.
- Install with
uv tool install --python 3.13 kimi-cliand exportKIMI_API_KEY(plus optionalKIMI_BASE_URL/KIMI_MODEL_NAME). codemachine auth loginprompts for the API key (masked) and stores it at<project>/.codemachine/kimi/auth.env(0600). Override withCODEMACHINE_KIMI_AUTH_FILE, inspect viacodemachine auth status, and remove withcodemachine auth logout.- If
KIMI_BASE_URL/KIMI_MODEL_NAMEare unset we default tohttps://api.kimi.com/coding/v1andkimi-for-codingso print/wire mode works even when the upstream config file is empty. - Pin the project root used for
.codemachine/kimi/auth.envwithCODEMACHINE_PROJECT_ROOT=/absolute/workspace/pathwhen running from nested directories or CI sandboxes. - Override the exact CLI path via
CODEMACHINE_KIMI_BINARY=/full/path/to/kimiif you keep multiple installations around; otherwise we resolvekimionPATH. - Default print mode (
kimi --print) streams JSONL for resilient CI runs. SetCODEMACHINE_KIMI_MODE=wirewhen you need the JSON-RPC wire UI (step/tool/status fidelity). Wire mode auto-approves CLI prompts. - Provide additional MCP definitions through
KIMI_MCP_CONFIG_FILES=/path/a.json,/path/b.json. CODEMACHINE_SKIP_KIMI=1performs dry-runs;CODEMACHINE_PLAIN_LOGS=1strips ANSI sequences from streamed output.- Windows is not currently supported by the upstream CLI—use macOS, Linux, or WSL.
CLI Startup Flow:
-
Parse Global Options
- Check for
-d/--dirto set working directory - Check for
--specto override default specification path
- Check for
-
Pre-Action Hook
- Sync configuration for all registered engines
- Validate workspace structure
-
Bootstrap Workspace
- If
.codemachine/doesn't exist:- Create directory structure
- Initialize with default template
- Create default spec file
- If
-
Register Commands
- Register all standard commands
- Dynamically register engine-specific commands
-
Execute Command or Enter Interactive Mode
- If command provided: execute and exit
- If no command: enter interactive session shell
Default Workspace Bootstrap:
.codemachine/
├── inputs/
│ └── specifications.md # Created with template
├── template.json # Set to default template
└── [engine configs] # Created on first auth
Most Common Commands:
# Start interactive session
codemachine
# Run workflow
codemachine start
# Select template
codemachine templates
# Authenticate
codemachine auth login
# Execute agent or orchestrate
codemachine run "<agent-id> 'prompt'"
# Execute workflow step
codemachine step <id>
# Check version
codemachine versionWith Options:
# Set workspace
codemachine -d /path/to/project
# Custom spec
codemachine start --spec ./specs/custom.md
# Override model
codemachine step planner --model gpt-4
# Override engine and reasoning
codemachine step planner --engine claude --reasoning high