Archon/docs/cli-user-guide.md
Rasmus Widing 845c816226
feat: default worktree isolation for CLI + auto-detect base branch (#692)
* feat: default worktree isolation for CLI + auto-detect base branch

- CLI now creates a worktree by default (matching all other adapters)
- Branch names auto-generated as {workflowName}-{timestamp}
- --no-worktree opts out of isolation (standalone flag, no longer requires --branch)
- All generated branch names prefixed with archon/ for clear namespace
- Base branch auto-detected from git (symbolic-ref → origin/main → origin/master)
- Config worktree.baseBranch still overrides auto-detection
- $BASE_BRANCH in workflow prompts auto-resolves without config
- Ignore .claude/skills/ from ESLint

* fix: address PR review findings — error handling, tests, docs

- Add warn log for silent getDefaultBranch catch in executor.ts
- Fix branchToSync bug: don't pass fromBranch as sync target
  (fromBranch is the worktree start-point, not the base to sync)
- Add user-facing warning when isolation is silently skipped
- Add errorType to codebase_auto_registration_failed log
- Consolidate all validation guards in workflowRunCommand
  (cli.ts keeps them for UX fast-path, workflowRunCommand is
  the authoritative boundary for programmatic callers)
- Add tests: validation guards, default isolation, --no-worktree
  skip, isolation-skipped warning, auto-detect $BASE_BRANCH success
- Add loadRepoConfig to @archon/core mock in workflow tests
- Update docs: CLAUDE.md, cli-user-guide, configuration,
  authoring-workflows, worktree-orchestration, README, cli.md rule
  — all updated for default isolation, archon/ prefix, optional
  baseBranch with auto-detection

* refactor: simplify isolation branch logic and fix log naming

- Split shouldIsolate into wantsIsolation + codebase check to
  eliminate redundant double-check of codebase
- Simplify else-if chain: use wantsIsolation instead of re-testing
  already-false conditions
- Deduplicate isolation-skipped warning messages
- Fix log event: base_branch.auto_detect_failed →
  workflow.base_branch_auto_detect_failed (project naming convention)

* fix: fail fast when isolation cannot be created instead of silent fallback

When the user hasn't opted out with --no-worktree, failing to create
a worktree (DB error or not in a git repo) now throws instead of
silently running in the live checkout. This prevents AI from making
unprotected changes to the working tree.

* chore: Auto-commit workflow artifacts (archon-assist)
2026-03-17 13:39:41 +02:00

6.2 KiB

Archon CLI User Guide

Run AI-powered workflows from your terminal.

For developers: See CLI Developer Guide for architecture and internals.

Prerequisites

  1. Clone the repository and install dependencies:

    git clone https://github.com/dynamous-community/remote-coding-agent
    cd remote-coding-agent
    bun install
    
  2. Make CLI globally available (recommended):

    cd packages/cli
    bun link
    

    This creates an archon command available from anywhere.

  3. Authenticate with Claude:

    claude /login
    

Note: Examples below use archon (after bun link). If you skip step 2, use bun run cli from the repo directory instead.

Quick Start

# List available workflows (requires git repository)
archon workflow list --cwd /path/to/repo

# Run a workflow (auto-creates isolated worktree by default)
archon workflow run assist --cwd /path/to/repo "Explain the authentication flow"

# Explicit branch name for the worktree
archon workflow run plan --cwd /path/to/repo --branch feature-auth "Add OAuth support"

# Opt out of isolation (run in live checkout)
archon workflow run assist --cwd /path/to/repo --no-worktree "Quick question"

Note: Workflow and isolation commands require running from within a git repository. Running from subdirectories automatically resolves to the repo root. The version and help commands work anywhere.

Commands

workflow list

List workflows available in target directory.

archon workflow list --cwd /path/to/repo

# Machine-readable output for scripting
archon workflow list --cwd /path/to/repo --json

Discovers workflows from .archon/workflows/ (recursive) plus bundled defaults.

Flags:

Flag Effect
--cwd <path> Target directory (required for most use cases)
--json Output machine-readable JSON instead of formatted text

With --json, outputs { "workflows": [...], "errors": [...] }. Optional fields (provider, model, modelReasoningEffort, webSearchMode) are omitted when not set on a workflow.

workflow run <name> [message]

Run a workflow with an optional user message.

# Basic usage
archon workflow run assist --cwd /path/to/repo "What does this function do?"

# With isolation
archon workflow run plan --cwd /path/to/repo --branch feature-x "Add caching"

Flags:

Flag Effect
--cwd <path> Target directory (required for most use cases)
--branch <name> Explicit branch name for the worktree
--from <branch>, --from-branch <branch> Override base branch (start-point for worktree)
--no-worktree Opt out of isolation — run directly in live checkout
--resume Resume from last failed run

Default (no flags):

  • Creates worktree with auto-generated branch (archon/task-<workflow>-<timestamp>)
  • Auto-registers codebase if in a git repo

With --branch:

  • Creates/reuses worktree at ~/.archon/worktrees/<repo>/<branch>/
  • Reuses existing worktree if healthy

With --no-worktree:

  • Runs in target directory directly (no isolation)
  • Mutually exclusive with --branch and --from

isolation list

Show all active worktree environments.

archon isolation list

Groups by codebase, shows branch, workflow type, platform, and days since activity.

isolation cleanup [days]

Remove stale environments.

# Default: 7 days
archon isolation cleanup

# Custom threshold
archon isolation cleanup 14

# Remove environments with branches merged into main (also deletes remote branches)
archon isolation cleanup --merged

complete <branch> [branch2 ...]

Remove a branch's worktree, local branch, and remote branch, and mark its isolation environment as destroyed.

archon complete feature-auth
archon complete feature-auth --force  # bypass uncommitted-changes check

Flags:

Flag Effect
--force Skip uncommitted-changes guard

Use this after a PR is merged and you no longer need the worktree or branches. Accepts multiple branch names in one call.

version

Show version, build type, and database info.

archon version

Working Directory

The CLI determines where to run based on:

  1. --cwd flag (if provided)
  2. Current directory (default)

Running from a subdirectory (e.g., /repo/packages/cli) automatically resolves to the git repository root (e.g., /repo).

When using --branch, workflows run inside the worktree directory.

Commands and workflows are loaded from the working directory at runtime. The CLI reads directly from disk, so it picks up uncommitted changes immediately. This is different from the server (Telegram/Slack/GitHub), which reads from the workspace clone at ~/.archon/workspaces/ — that clone only syncs from the remote before worktree creation, so changes must be pushed to take effect there.

Environment

The CLI loads environment from:

  1. .env in current directory
  2. ~/.archon/.env (fallback)

Auto-enables global Claude auth if no explicit tokens are set.

Database

  • Without DATABASE_URL (default): Uses SQLite at ~/.archon/archon.db — zero setup, auto-initialized on first run
  • With DATABASE_URL: Uses PostgreSQL (optional, for cloud/advanced deployments)

Both work transparently. Most users never need to configure a database.

Examples

# Quick question (auto-isolated in archon/task-assist-<timestamp>)
archon workflow run assist --cwd ~/projects/my-app "How does error handling work here?"

# Quick question without isolation
archon workflow run assist --cwd ~/projects/my-app --no-worktree "How does error handling work here?"

# Plan a feature (auto-isolated)
archon workflow run plan --cwd ~/projects/my-app "Add rate limiting to the API"

# Implement with explicit branch name
archon workflow run implement --cwd ~/projects/my-app --branch feature-rate-limit "Add rate limiting"

# Branch from a specific source branch instead of auto-detected default
archon workflow run implement --cwd ~/projects/my-app --branch test-adapters --from feature/extract-adapters "Test adapter changes"

# Check worktrees after work session
archon isolation list

# Clean up old worktrees
archon isolation cleanup