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. 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.
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.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

