CodeTrain / Docs / The CodeTrain CLI

The CodeTrain CLI

This page covers the CodeTrain CLI day to day: signing in, starting a lesson in each mode, the options worth knowing, the smaller commands, and where the CLI writes its files. If the CLI is not installed yet, the /developers/ page covers that.

Sign in

$ codetrain login

Run codetrain login and it prints a web address and a short code, opens the address in your browser, and waits. Confirm the code on the page where you are signed in to CodeTrain, and the CLI reports the account it connected and the plan. Approve a code only if you started the login yourself; Ctrl-C cancels. With no browser on the machine, --no-browser prints the address and leaves opening it to you. Once you are connected, it suggests codetrain start --mode sandbox.

For CI or a script, codetrain login --token TOKEN skips the browser step and saves a token instead. codetrain logout forgets the saved token.

Start a lesson

$ codetrain start

codetrain start begins a lesson and opens it in your browser, on a page the CLI serves on the machine itself at 127.0.0.1:7341. If that port is busy it moves to the next free one. Over SSH or on a headless machine, --no-browser leaves the browser closed, and --no-serve registers the lesson without the page. If a lesson is already in progress on the machine, codetrain start reconnects to it. Pass --new to start a fresh one instead.

The three kinds of lesson

codetrain start --mode sandbox
The default mode: a lesson in a fresh scratch folder on your machine. codetrain start with no --mode gives you this.
codetrain start --mode repo
A lesson on the repository you are in. The CLI works on a copy of it on your machine, and a change reaches your real repository only when you accept it.
codetrain start --mode onboarding
A team's onboarding journey for the repository you are in. When your team has more than one program, --program picks which one.

Free allows sandbox. Pro adds repo. Team and Enterprise allow the same modes as Pro plus codetrain defend, and onboarding comes with a team's onboarding program. A mode the plan does not include is refused when the lesson starts, and the CLI gives the reason.

Options

$ codetrain start --mode repo --model claude --file src/app.py

--model ID picks the tutor model: haiku, claude, or an id from codetrain models. With no --model, the CLI uses the best model the plan allows, which is haiku on Free. --file PATH attaches a file on your machine to the tutor's context, so it can review your work against your own code; you can give it more than once. --no-browser keeps the browser closed, and --no-serve registers the lesson without serving the page.

The other commands

codetrain status
Shows your plan and your usage.
codetrain models
Lists the models your account can name with --model.
codetrain end
Ends the lesson in progress.
codetrain sync
Keeps the learner profile in step with the account in the cloud. --push-only and --pull-only sync in one direction.
codetrain logout
Forgets the saved token on this machine.

Where things are kept

The CLI keeps its sign-in in ~/.config/codetrain/config.json, and the CODE_TRAINER_HOME variable moves that folder. A sandbox lesson works in a new temporary folder. A repo lesson works on a copy on your machine, and the source is not uploaded to keep. Two commands sit outside this page: codetrain metrics for the delivery numbers, and codetrain defend for the read-through before review, both on the /docs/ overview.