Package Exports
- @tocodex/cli
- @tocodex/cli/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@tocodex/cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@tocodex/cli
Command Line Interface for ToCodex - Run the ToCodex AI coding agent from the terminal without VSCode.
Overview
This CLI uses the @tocodex/vscode-shim package to provide a VSCode API compatibility layer, allowing the main ToCodex extension to run in a Node.js environment.
Installation
npm install -g @tocodex/cliRequirements:
- Node.js 20 or higher
Updating
tocodex upgradeUninstalling
npm uninstall -g @tocodex/cliDevelopment Installation
For contributing or development:
# From the monorepo root.
pnpm install
# Build the main extension first.
pnpm --filter tocodex bundle
# Build the CLI.
pnpm --filter @tocodex/cli buildQuick Start
1. Get API Key
Get your API key at: https://user.tocodex.com/console/token
2. Configure API Key (One-time Setup)
After installation, a cli-settings.json example file is included in the package directory. You can either:
Option A: Edit the pre-created config file (simplest)
# Find the config file location
tocodex config path
# Edit the cli-settings.json file in your install directory
# Replace "sk-your-api-key-here" with your actual API keyOption B: Use the config command
# Set your ToCodex API key
tocodex config set apiKey sk-your-actual-api-key
# Set provider to tocodex
tocodex config set provider tocodex
# Set default model
tocodex config set model claude-opus-4-7
# Verify your settings
tocodex config listSettings are saved to ~/.tocodex/cli-settings.json and persist across sessions.
3. Run
# Simple question about a project
tocodex "What is this project?" -w ~/Documents/my-project
# Ask a question (no code changes)
tocodex --mode ask "Explain the authentication flow" -w .
# Code generation / refactoring
tocodex "Add input validation to the login form" -w ~/Documents/my-app
# Architecture review
tocodex --mode architect "Design a caching layer for the API" -w .
# Debug a specific issue
tocodex --mode debug "The API returns 500 on /users endpoint" -w .
# Non-interactive print mode (for scripting / CI)
tocodex --print "Summarize this repo" -w .
# Use a different model for one run
tocodex -m claude-sonnet-4-20250514 "Write unit tests for utils.ts" -w .
# Switch mode for one run
# Common modes: code, ask, architect, debug, browser-worker, ssh-server, image-gen
tocodex --mode ask "Explain this repository" -w .
tocodex --mode code "Refactor the login flow" -w .
tocodex --mode architect "Design a scalable cache layer" -w .
# Persist the default mode for future runs
tocodex config set mode ask
tocodex config set mode code
# Persist the default model for future runs
tocodex config set model gpt-5.5
tocodex config set model claude-sonnet-4-20250514
# Check current persisted settings
tocodex config list
# Run interactively without a prompt (enter prompt in TUI)
tocodex -w ~/Documents/my-project
# One-shot mode (exit after task completion)
tocodex --oneshot "Fix the TypeScript errors" -w .Switching Mode, Model, and Reasoning
In interactive TUI mode, the quickest way to change runtime settings is to type one of the shortcut trigger characters at the start of the input line. A picker opens immediately; use ↑/↓ to navigate and Enter to select.
| Shortcut | Picker | What it changes | Notes |
|---|---|---|---|
! |
Mode picker | Agent mode (code, ask, architect, debug, etc.) |
Example: type !ask then Enter. |
= |
Model picker | Current provider model | Example: type =gpt to fuzzy-search GPT models. Selecting a model clears the current task so the next task uses it. |
~ |
Reasoning picker | Reasoning effort (disabled, low, medium, high, xhigh) |
Example: type ~high then Enter. Selecting an effort clears the current task so the next task sends the updated reasoning fields. |
? |
Help picker | Shortcut reference | Shows available trigger characters and keyboard shortcuts. |
Keyboard cycling shortcuts are also available:
| Shortcut | Action |
|---|---|
Ctrl+M |
Cycle to the next mode. |
Ctrl+L |
Cycle to the next model for the current provider. |
Ctrl+R |
Cycle reasoning effort. |
Ctrl+T |
Show or hide the TODO list viewer. |
Tab |
Toggle focus between input and scroll area when available. |
Ctrl+C |
Press twice to quit. |
For one-off non-interactive commands, use flags:
# Switch mode for one run
tocodex --mode ask "Explain the authentication flow" -w .
tocodex --mode code "Add validation to the login form" -w .
# Switch model for one run
tocodex -m gpt-5.5 "Review this code" -w .
tocodex --model claude-sonnet-4-20250514 "Write tests for utils.ts" -w .Persist defaults with tocodex config set:
# Set default mode
tocodex config set mode code
tocodex config set mode ask
# Set default model
tocodex config set model gpt-5.5
tocodex config set model claude-sonnet-4-20250514
# Set default reasoning effort
tocodex config set reasoningEffort high
# Inspect current defaults
tocodex config listScheduled Tasks
ToCodex CLI can create independent scheduled tasks. Tasks are stored locally and can be inspected or run from the command line.
Create a scheduled task
Create an interval task that runs every minute:
tocodex schedule create "Daily news" "Search for and summarize today's major news in Chinese" --trigger '{"kind":"interval","intervalMs":60000}' --mode codeCreate a cron task:
tocodex schedule create "Morning summary" "Summarize today's top news" --trigger '{"kind":"cron","expression":"0 9 * * *","timezone":"Asia/Shanghai"}' --mode codeCreate a one-time task. runAt is a Unix timestamp in milliseconds:
tocodex schedule create "One-time check" "Check this repository status" --trigger '{"kind":"once","runAt":1760000000000}' --mode codeView scheduled tasks
List all tasks:
tocodex schedule listList only enabled tasks:
tocodex schedule list --enabled-onlyFilter by scope:
tocodex schedule list --scope global
tocodex schedule list --scope workspaceThe output is JSON and includes the local task store path, task IDs, enabled status, trigger, nextRunAt, and lastRun.
Run and inspect tasks
Run a task immediately:
tocodex schedule run <task-id>Show recent run history:
tocodex schedule runs <task-id>
tocodex schedule runs <task-id> --limit 5Run all currently due tasks once:
tocodex schedule run-dueUpdate or delete tasks
Update a task with a JSON patch:
tocodex schedule update <task-id> '{"enabled":false}'
tocodex schedule update <task-id> '{"trigger":{"kind":"interval","intervalMs":300000}}'Delete a task:
tocodex schedule cancel <task-id>Automatic execution
CLI-created scheduled tasks are executed automatically only while the scheduler daemon is running:
tocodex schedule daemonThe daemon runs in the foreground and checks for due tasks every 30 seconds by default. Keep this terminal/process running if you want CLI-created tasks to execute on schedule.
Use a custom polling interval:
tocodex schedule daemon --poll-ms 10000Note: The CLI scheduler is not installed as a Windows service, systemd service, or OS-level cron job. If the daemon process is stopped or the terminal is closed, CLI-created scheduled tasks will not run automatically until you start
tocodex schedule daemonagain. Tasks created by ToCodex's native scheduled-task tools are also checked by a lightweight VS Code extension-side scheduler while the extension host is active.
First Run Without API Key
If you run tocodex without configuring an API key, the CLI will show an interactive onboarding prompt:
- Connect to ToCodex Cloud — Opens your browser for OAuth authentication
- Use your own API key — Prompts you to configure your own API key
Note: If a
cli-settings.jsonwith aprovidervalue already exists, onboarding is skipped and the CLI uses the configured API key directly.
Configuration
Config Commands
| Command | Description |
|---|---|
tocodex config set <key> <val> |
Set a configuration value |
tocodex config get <key> |
Get a configuration value |
tocodex config list |
List all configuration values |
tocodex config path |
Show config file location |
Supported config keys:
| Key | Description | Example |
|---|---|---|
apiKey |
API key for the LLM provider | sk-xxx... |
provider |
API provider | tocodex, openrouter |
model |
Default model | claude-opus-4-7 |
mode |
Default mode | code, ask, architect |
reasoningEffort |
Reasoning effort level | medium, high |
Priority Chain
Settings are resolved in this order (first wins):
- CLI flags (
--provider,-m,--api-key, etc.) - Config file (
~/.tocodex/cli-settings.json) - Environment variables (
TOCODEX_API_KEY, etc.) - Defaults (provider:
openrouter, model:claude-opus-4-7)
Config File Example
~/.tocodex/cli-settings.json:
{
"apiKey": "sk-your-api-key",
"provider": "tocodex",
"model": "claude-opus-4-7",
"mode": "code"
}API Endpoint
When using the tocodex provider, API requests are sent to:
https://api.tocodex.comThis can be overridden via the TOCODEX_API_URL environment variable.
Usage
Interactive Mode (Default)
By default, the CLI auto-approves actions and runs in interactive TUI mode:
# With config file already set up:
tocodex "What is this project?" -w ~/Documents/my-project
# Or with environment variable:
export TOCODEX_API_KEY=sk-your-key
tocodex "What is this project?" -w ~/Documents/my-projectYou can also run without a prompt and enter it interactively in TUI mode:
tocodex -w ~/Documents/my-projectIn interactive mode:
- Tool executions are auto-approved
- Commands are auto-approved
- Followup questions show suggestions with a 60-second timeout, then auto-select the first suggestion
- Browser and MCP actions are auto-approved
Approval-Required Mode (--require-approval)
If you want manual approval prompts, enable approval-required mode:
tocodex "Refactor the utils.ts file" --require-approval -w ~/Documents/my-projectIn approval-required mode:
- Tool, command, browser, and MCP actions prompt for yes/no approval
- Followup questions wait for manual input (no auto-timeout)
Print Mode (--print)
Use --print for non-interactive execution and machine-readable output:
# Prompt is required
tocodex --print "Summarize this repository"
# Create a new task with a specific session ID (UUID)
tocodex --print --create-with-session-id 018f7fc8-7c96-7f7c-98aa-2ec4ff7f6d87 "Summarize this repository"Stdin Stream Mode (--stdin-prompt-stream)
For programmatic control (one process, multiple prompts), use --stdin-prompt-stream with --print.
Send NDJSON commands via stdin:
printf '{"command":"start","requestId":"1","prompt":"1+1=?"}\n' | tocodex --print --stdin-prompt-stream --output-format stream-json
# Optional: provide taskId per start command
printf '{"command":"start","requestId":"1","taskId":"018f7fc8-7c96-7f7c-98aa-2ec4ff7f6d87","prompt":"1+1=?"}\n' | tocodex --print --stdin-prompt-stream --output-format stream-jsonToCodex Cloud Authentication
To use ToCodex Cloud features (like the provider proxy), you need to authenticate:
# Log in to ToCodex Cloud (opens browser)
tocodex auth login
# Check authentication status
tocodex auth status
# Log out
tocodex auth logoutThe auth login command:
- Opens your browser to authenticate with ToCodex Cloud
- Receives a secure token via localhost callback
- Stores the token locally
Tokens are valid for 90 days. The CLI will prompt you to re-authenticate when your token expires.
Authentication Flow:
+----------+ +-----------+ +-----------------+
| CLI | | Browser | | ToCodex Cloud |
+----+-----+ +-----+-----+ +--------+--------+
| | |
| Open auth URL | |
|------------------->| |
| | |
| | Authenticate |
| |--------------------->|
| | |
| |<---------------------|
| Token via callback| |
|<-------------------| |
| | |
| Store token | |
| | |
+----+-----+ +-----+-----+ +--------+--------+
| CLI | | Browser | | ToCodex Cloud |
+----------+ +-----------+ +-----------------+Options
| Option | Description | Default |
|---|---|---|
[prompt] |
Your prompt (positional argument, optional) | None |
--prompt-file <path> |
Read prompt from a file instead of command line argument | None |
--create-with-session-id <session-id> |
Create a new task using the provided session ID (UUID) | None |
-w, --workspace <path> |
Workspace path to operate in | Current directory |
-p, --print |
Print response and exit (non-interactive mode) | false |
--stdin-prompt-stream |
Read NDJSON control commands from stdin (requires --print) |
false |
-e, --extension <path> |
Path to the extension bundle directory | Auto-detected |
-d, --debug |
Enable debug output (includes detailed debug information, prompts, paths, etc) | false |
-a, --require-approval |
Require manual approval before actions execute | false |
-k, --api-key <key> |
API key for the LLM provider | From env var |
--provider <provider> |
API provider (tocodex, anthropic, openai, openrouter, etc.) | openrouter (or tocodex if authenticated) |
-m, --model <model> |
Model to use | claude-opus-4-7 |
--mode <mode> |
Mode to start in (code, architect, ask, debug, etc.) | code |
--terminal-shell <path> |
Absolute shell path for inline terminal command execution | Auto-detected shell |
-r, --reasoning-effort <effort> |
Reasoning effort level (unspecified, disabled, none, minimal, low, medium, high, xhigh) | medium |
--consecutive-mistake-limit <n> |
Consecutive error/repetition limit before guidance prompt (0 disables the limit) |
10 |
--ephemeral |
Run without persisting state (uses temporary storage) | false |
--oneshot |
Exit upon task completion | false |
--output-format <format> |
Output format with --print: text, json, or stream-json |
text |
Auth Commands
| Command | Description |
|---|---|
tocodex auth login |
Authenticate with ToCodex Cloud |
tocodex auth logout |
Clear stored authentication token |
tocodex auth status |
Show current authentication status |
Environment Variables
The CLI will look for API keys in environment variables if not provided via --api-key:
| Provider | Environment Variable |
|---|---|
| tocodex | TOCODEX_API_KEY |
| anthropic | ANTHROPIC_API_KEY |
| openai-native | OPENAI_API_KEY |
| openrouter | OPENROUTER_API_KEY |
| gemini | GOOGLE_API_KEY |
| vercel-ai-gateway | VERCEL_AI_GATEWAY_API_KEY |
Authentication Environment Variables:
| Variable | Description |
|---|---|
TOCODEX_AUTH_BASE_URL |
Override the ToCodex Cloud URL (default: https://user.tocodex.com) |
TOCODEX_SDK_BASE_URL |
Override the SDK base URL (default: https://cloud-api.tocodex.com) |
TOCODEX_EXTENSION_PATH |
Override the extension bundle path |
Architecture
+-------------------+
| CLI Entry |
| (index.ts) |
+---------+---------+
|
v
+-------------------+
| ExtensionHost |
| (extension- |
| host.ts) |
+---------+---------+
|
+----+-----+
| |
v v
+---------+ +------------+
| vscode | | Extension |
| shim | | Bundle |
+---------+ +------------+How It Works
CLI Entry Point (
index.ts): Parses command line arguments and initializes the ExtensionHostExtensionHost (
extension-host.ts):- Creates a VSCode API mock using
@tocodex/vscode-shim - Intercepts
require('vscode')to return the mock - Loads and activates the extension bundle
- Manages bidirectional message flow
- Creates a VSCode API mock using
Message Flow:
- CLI -> Extension:
emit("webviewMessage", {...}) - Extension -> CLI:
emit("extensionWebviewMessage", {...})
- CLI -> Extension:
Development
# Run directly from source (no build required)
pnpm dev --provider tocodex --api-key $TOCODEX_API_KEY --print "Hello"
# Run tests
pnpm test
# Type checking
pnpm check-types
# Linting
pnpm lintReleasing
# Build + create tarball
node scripts/release.mjs --tarball
# Build + publish to npm
node scripts/release.mjs --npm
# Build + all (tarball + npm + docker)
node scripts/release.mjs --all --version 1.0.0License
Apache-2.0