code command starts a code assistant session optimized for programming tasks.
As of PR #3818,
praisonai code runs its resident TUI directly from pip install praisonai-code — no wrapper required. Installing the full praisonai wrapper enables the richer legacy dispatch (PraisonAI._start_interactive_mode), which takes over when present.praisonai code is safe by default: file writes and shell commands prompt for approval on first call. Pass --no-safe or --dangerously-skip-approval to restore the legacy ungated behaviour. Use --plan to make the session strictly read-only — every mutating tool is denied outright rather than gated by an approval prompt. See Tool Approval.Usage
Arguments
Options
Safe mode (
--safe) is on by default as of PR #2369. Dangerous built-in tools ask for approval in interactive sessions and are denied in non-interactive (CI) sessions. Use --no-safe to opt out, or --dangerously-skip-approval for a complete bypass — both register AutoApproveBackend on the approval registry so the core @require_approval gate is also bypassed. A safe-mode run clears a bypass a prior --no-safe call left in the same process (REPL/worker/test), removing only the backend it installed itself. See Approval for full details.Append to the system prompt
--append-system-prompt adds a one-off suffix to the assembled system prompt for a single invocation. It is never persisted and disappears when the process exits.
Piped Input
praisonai code reads piped stdin when the prompt is provided in the shell pipeline.
\n). See Piped Input.
Step budget for coding sessions
praisonai code runs with a coding-sized step budget by default: 200 steps, applied to both tool-execution loops.
The core Agent defaults (max_steps=20, max_tool_calls_per_turn=10) are tuned for a general-purpose Q&A agent with two or three tools, and are left untouched — no library user’s behaviour changes. But 10 tool calls is “list files, read two files, one grep”: it cannot reach a test run. The coding CLI raises the ceiling for its own sessions only.
Override
1
Explicit flag
2
Environment fallback (CI / sandbox)
--max-steps flag > PRAISONAI_CODE_MAX_STEPS env > DEFAULT_CODE_MAX_STEPS (200). An unparseable or non-positive value falls through to the next source.
The flag raises both budget knobs to the same value, because:
Raising only one leaves the other as the real (and invisible) ceiling.
Why 200?
Why 200?
A coding agent’s unit of work is read → edit → run tests → read the failure (≈4 calls per fix attempt), before any orientation. 200 steps is ~50 edit/verify cycles, chosen to cover the tail rather than the median: trajectories cluster at 20–40 steps, but hard tasks — the ones benchmarks measure — run past 100, and a budget at the median silently truncates those. Runaway loops stay bounded by the orthogonal guards (per-tool loop guard,
ExecutionConfig.max_execution_time, max_budget, model context window).What about max_tool_calls_per_turn?
What about max_tool_calls_per_turn?
The LiteLLM tool loop counts every tool call in a turn against
max_tool_calls_per_turn, while the OpenAI-native loop is bounded by max_steps. --max-steps sets both to the same value so a Gemini/Anthropic-routed session isn’t capped at 10 calls while an OpenAI-routed one runs to your budget.Does this change the SDK defaults?
Does this change the SDK defaults?
No. The coding budget applies only to
praisonai code. The Python Agent defaults (max_steps=20, max_tool_calls_per_turn=10) are unchanged.ExecutionConfig.max_steps contract and how to detect truncation with agent.last_stop_reason.
Headless truncation contract (code -p)
A budget-exhausted headless run exits 2 with status: "truncated" — distinct from a hard failure (1) and a clean completion (0).
This matches praisonai run → truncation and closes a hazard where a wrap-up summary (a perfectly non-empty string) was classified as status: "ok", exit 0, silently reporting truncation as success to CI and benchmark adapters.
--output text, a stderr warning follows the printed result:
status: "truncated" field is the machine signal.
The shared truncation check (run._run_was_truncated) resolves through agent.last_stop_reason == "max_steps", so code -p and praisonai run agree on the 0 / 1 / 2 exit-code contract.
First-run credential gate
praisonai code routes first-run onboarding through the shared credential gate, so a keyless newcomer is offered the setup wizard (interactive) or exits with a hint (headless) instead of dead-ending on a raw provider error.
--agent <profile> passes the profile’s llm value through the gate, so onboarding validates the profile’s model — not a silently-adopted local one.Headless / scripting mode
-p/--print runs one task and prints a clean, machine-readable result — no Chat mode: banners, no profiling block — then exits with a code that reflects success or failure. This is the scripting parity code shares with run --output json and chat --json.
JSON envelope
--output json (the default under -p) prints a single-line JSON object on stdout:
Text mode
--output text prints just the result on stdout — nothing else — so it pipes cleanly:
Exit-code contract
The exit code lets CI, benchmarks, and shell scripts branch on success without parsing stdout.
See Headless truncation contract (
code -p) for the truncated case.
Scripted multi-turn with --resume
--resume <id> composes with -p so a script can carry a session across calls. The id flows back out in the envelope’s session_id:
Fail-closed options
Headless mode runs a minimal code agent, so options that need the full interactive wiring are rejected up front (exit 1) rather than silently dropped:
Two more guards keep the contract explicit:
--output without -p errors, and -p without a prompt errors.
On a keyless install,
code -p fails fast at the first-run credential gate with Error: No API key configured. Run: praisonai setup (exit 1) — before the Agent path is touched.-p: --model, --thinking, --verbose, --workspace, --resume / --session / --continue, --tools, --agent, and --plan (as of PraisonAI PR #4026). --tools and the profile’s named tools are merged onto the default headless coding toolset (de-duped by identity), so custom tools add to the defaults rather than replacing them. --plan and a profile’s declarative permissions are enforced via a non-interactive approval backend, so honouring the scope is a tightening (deny/ask fails closed) — never an interactive prompt that would stall a scripted run.
The envelope reuses the same token collector and cost tracker as
run --output json, so usage.in/out/cost reflect real figures without any extra flags.Sessions
praisonai code shares the canonical session store at ~/.praisonai/sessions/ (Windows: %USERPROFILE%\.praisonai\sessions\). Every conversation you start here is the same session object the rest of the CLI reads and writes.
Sessions created inside praisonai code are visible to:
praisonai session list(andlist --all)praisonai session show <id>/delete <id>/export <id>/share <id>/unshare <id>praisonai run --continue/--session <id>— same id, same conversation- the
praisonai dashboard
Prior to
praisonai-code ≥ 1.x (post-fix #3645), code sessions were written to ~/.praison/sessions/ and were not visible to session list or the dashboard. Upgrading unifies the store; pre-fix sessions stay in the legacy path. To bring them across, move them manually:Examples
Start code assistant
Ask a coding question
Specify language context
Disable safe mode (opt out of approval prompts)
Full bypass (no approval prompts, applies to subprocess tree)
Headless one-shot for scripts
Headless one-shot with a custom tool
--tools is now first-class under -p. The resolved tools are merged onto the default headless coding toolset (ACP + edit + search + LSP), so custom tools add to the defaults rather than replacing them.
--tools accepts either comma-separated names resolved through ToolResolver (identical to run --tools) or a ./tools.py file path. If a user tools.py fails at import time, the failure is reported through the same machine-readable JSON envelope (status: "error", non-zero exit) — never as a raw traceback.
Headless one-shot under a named agent profile
--agent <name> loads a profile from .praisonai/agents/ and applies its instructions, role, goal, llm, and named tools to the headless run. Its declarative permissions are enforced via a non-interactive approval backend, so a pinned least-privilege profile runs safely in CI.
--model still wins over the profile’s llm. See Custom Agents & Commands for profile definitions.
Headless read-only planning (--plan)
--plan under -p runs a read-only headless session: reads, searches, and LSP queries are allowed, but every mutating tool (write, edit, shell) is denied by a non-interactive PermissionMode.PLAN backend. Ideal for CI review jobs that must produce a plan without touching the tree.
--plan overrides any profile permission scope with the read-only planning mode. See Permission Modes and Approval.
Read-only planning session
--plan is the read-only planning permission mode (PermissionMode.PLAN). See Permission Modes and Permissions.
Reasoning effort (per invocation)
Custom agent profile
Append a one-off instruction (per invocation)
Project context
By default,praisonai code walks up from the current directory to your git root and prepends any AGENTS.md / CLAUDE.md / agents.md / .agents/AGENTS.md it finds to the agent’s system prompt, layered on top of ~/.praisonai/AGENTS.md. Pass --no-context (or set PRAISON_NO_CONTEXT=true) to disable. See Context Files for details.
Workspace directory
praisonai code runs its file, edit, search, and shell tools inside one workspace directory. Everything the agent reads and writes is contained there.
Pick a workspace explicitly
./src.
Pick a workspace with an environment variable
PRAISONAI_WORKSPACE is the canonical name. The older PRAISON_WORKSPACE still works for backwards compatibility, but PRAISONAI_WORKSPACE wins when both are set.
Resume back into the same directory
praisonai code --continue from any shell — the tools re-root into the directory the session was created in, so the conversation stays consistent.
If the recorded directory no longer exists you’ll see a warning and the tools fall back to the current directory:
--workspace always wins over the resumed directory.
Windows Automation
For Windows automation scenarios, use the--no-acp flag and set UTF-8 encoding. The -w flag is now honored end-to-end, so the agent’s tools operate inside the directory you pass:
Auto checkpointing & in-session undo
Workspace checkpointing is on by default for interactivepraisonai code sessions, so /undo and /revert work out of the box. Disable per-run with --no-checkpoints, or project-wide with checkpoints.auto: false (or PRAISONAI_CHECKPOINTS=off).
How /undo differs by mode
Interactive slash commands
Type these inside apraisonai code REPL (checkpointing is on by default; disable with --no-checkpoints):
Both commands show a diff preview before restoring and refuse to run while a turn is still in progress.
One-shot revert from CLI
Project config
Enable checkpointing for allpraisonai code sessions in a project:
default → checkpoints.auto (config) → PRAISONAI_CHECKPOINTS (env). Interactive praisonai code passes default=True, so checkpointing is on unless you disable it.
See Checkpoints for the full checkpoint feature reference.
See Also
- Chat - General chat mode (
--jsonheadless output) - Piped Input - Compose
code -pin Unix pipelines and CI - LSP Code Intelligence - Language server integration
- Approval - Tool approval and safety defaults
- Checkpoints - Workspace checkpointing and undo
- Step Budget - The
max_stepscontract and the coding-sized default

