Skip to main content
The 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.
Pass --pure (alias --no-plugins) to skip external-plugin discovery for a single run without touching your saved enable/disable state — see Pure Mode.

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.
Omit the flag and set the environment variable instead — handy for CI:
See Append System Prompt for the full behaviour.

Piped Input

praisonai code reads piped stdin when the prompt is provided in the shell pipeline.
Prompt argument is merged first, piped body second (joined with \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.
See First-run Onboarding for the full flow and Setup for the wizard.

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:
Errors go to stderr; status is carried by the exit code.

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.
Honored under -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 (and list --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:
See Session Management for the full command set and Storage Paths for where files live.

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

See Headless / scripting mode for the envelope shape and exit-code contract.

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

See Custom Agents & Commands for profile definitions and Thinking for budget levels.

Append a one-off instruction (per invocation)

The text is appended to the end of the system prompt for this run only — never written to any agent file. See Append System Prompt.

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

Everything the agent reads or writes stays inside ./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

Launch 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:
An explicit --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:
See the Windows Automation section in Real-world Examples for complete setup instructions.

Auto checkpointing & in-session undo

Workspace checkpointing is on by default for interactive praisonai 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 a praisonai 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

Shows the diff preview and restores the workspace, then exits.

Project config

Enable checkpointing for all praisonai code sessions in a project:
Precedence (highest last): defaultcheckpoints.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