Claude Code CLI model provider
claude_code_cli supplies the local OS user's Claude login on personal
Community installs and operator-configured named accounts to the
claude-code-cli model backend. Codumentor owns conversation history, tool
execution and approvals; Claude is invoked as a text-only inference subprocess,
not as an autonomous workspace coding agent. This version has no login endpoints,
settings widget, browser connection flow, or personal derived connections.
It ships in the community edition. Enterprise builds leave it out; an enterprise
source checkout still runs it.
Community terminal login
Community enables use_os_login by default and offers **Claude Code (terminal
login)** when the server binds to loopback and uses exactly one local user. Use
claude auth login as the same OS user that runs Codumentor. The CLI uses that
user's normal HOME and, if set, CLAUDE_CONFIG_DIR; Codumentor does not read or
copy the login. An accountless profile uses this login; a profile with a named
account always uses that named account. Set use_os_login: false in the plugin's
args to turn this option off without disabling named accounts.
Operator-assisted connection
Install a trusted Claude CLI executable on the server. Perform authentication as
the same operating-system service account that runs Codumentor, in a dedicated
private directory outside all repositories and isolated workspace trees. Do not
reuse the operator's ordinary HOME or copy its credentials into a workspace.
For example, after the administrator provisions /srv/codumentor-auth for that
service account, run as that account:
umask 077
mkdir -p /srv/codumentor-auth/organization
chmod 700 /srv/codumentor-auth/organization
HOME=/srv/codumentor-auth/organization \
CLAUDE_CONFIG_DIR=/srv/codumentor-auth/organization \
/usr/local/bin/claude auth login
Follow the installed CLI's login instructions. Use that same executable and both
environment variables for later authentication maintenance. Neither login nor
executable installation is performed by the plugin. An invalid or missing named
account directory fails when its model is selected, not when the backend
registers. A named account never falls back to the OS login.
The directory must be owned by the service account with 0700 permissions. Its
ancestors must be real directories owned by that account or root, not writable
by other users (root-owned sticky temporary directories are permitted). Symlinks
in the directory or its ancestor chain and parent traversal are rejected. The
plugin also rejects overlap with configured repository roots and the configured
or default workspace-isolation root. Keep the entire account tree private,
including credential files created by the CLI; the plugin validates the directory
boundary, not every CLI-created descendant. Paths are rechecked when constructing
a model; administrators must not replace account trees while requests run.
Configuration
Only administrators should edit the plugin's executable and account-directory
mapping. A model profile selects an opaque account name, never a filesystem path
or executable. Add this entry to the deployment's existing plugins list:
plugins:
- module: codumentor.plugins.claude_code_cli
class: ClaudeCodeCLIPlugin
args:
enabled: true
executable: /usr/local/bin/claude # default: claude (service PATH)
accounts:
organization: /srv/codumentor-auth/organization
session_idle_timeout: 3300 # seconds an idle CLI process waits for its conversation
max_idle_sessions: 4 # idle CLI processes kept, all conversations together
Account names contain letters, digits, _ and -, start with a letter or digit,
and have at most 64 characters. Directories must be absolute; ~ and environment
variable interpolation are not performed. An executable may be an absolute path
or a bare executable name, not a relative path. Prefer an administrator-managed
absolute executable path and a trusted service PATH.
A profile can select the configured account:
models:
profiles:
claude-main:
provider: claude-code-cli
base_url: claude-code-cli://anthropic # identity only; not an HTTP endpoint
model: sonnet
backend_options:
account: organization # was claude_cli_account (deprecated, still read)
read_timeout: 600
# context_window: omit to use the window the CLI reports for the model
subagent_default: claude-main # default role profile; select claude-main in the model picker
Or declare a connection, whose models become ordinary profiles:
models:
connections:
organization-claude:
provider: claude-code-cli
base_url: claude-code-cli://anthropic # identity only; not an HTTP endpoint
backend_options:
account: organization
models:
- sonnet
These are alternative model declarations; merge the chosen example into existing
configuration rather than replacing other settings. Choose model identifiers and
context limits supported by the installed CLI and subscription. Making a profile
available does not grant account isolation between Codumentor users: anyone the
administrator permits to select it spends from the same organization account.
Use the deployment's model-selection/access policies to restrict that access
explicitly. This is not a personal subscription connection and does not bypass
those policies. Disable the plugin to refuse new model construction; stop active
requests before removing or replacing account state.
Generation protocol and limitations
The first request of a conversation sends the available tool definitions, then
Codumentor's text conversation (role, content and tool-call fields only), as JSON
through stdin to a CLI process in stream-json mode. Claude's JSON-schema output describes an answer and zero or more tool requests.
Codumentor validates the envelope; tool requests then go through the same
approval/execution loop as any other backend's, which answers an unknown tool or
malformed arguments with an error the model can correct. Tool requests made while
tools were withheld (tool_choice: none) are dropped. CLI-native tools are never
translated into Codumentor tool calls.
Process reuse and prompt caching
The process is kept after the call. The Claude CLI caches its own message
history: a whole conversation replayed into a fresh process as one message is
written to the prompt cache in full every time, and never read back. So a process
remembers what it has seen (the messages sent to it and the answer it produced),
and the next request whose history extends that record borrows it and sends
only the new messages: tool results (with the ids Codumentor gave the calls),
notes, the next user message, and the tool definitions again only if they
changed. Everything before is read from cache; measured, that is roughly 35x
cheaper per call than a fresh process.
No conversation identity is involved: matching on the history is itself the
append-only check. A regenerated or edited message, a compaction, a different
model, a cancelled or failed call, or two calls running at once, simply find no
idle process that fits, and a new one replays the history from scratch (one full
cache write, as before). Two rewrites Codumentor makes on purpose between turns
are tolerated because they only remove information: per-turn notes that are no
longer in the prompt, and tool results that aged out into a placeholder. The
process keeps the fuller version it already saw. Such a process is not reused
once a turn fills 90% of the CLI's context window, so the surplus cannot
overflow it. A process that never needed either tolerance holds exactly
Codumentor's prompt and is kept at any size: a fresh process would replay the
same tokens and only rewrite the cache. The CLI's own auto-compaction is off
(autoCompactEnabled: false and DISABLE_AUTO_COMPACT=1), so compaction is
always Codumentor's, at the trigger compaction computes.
The context window is the profile's context_window when set. Otherwise it is
the contextWindow the CLI reports in each result's modelUsage (1,000,000
for current Claude models), with 200000 assumed until the first result arrives.
Compaction still applies compaction's max_context_tokens ceiling
(or a model_context_limits entry for the model), whichever is lower.
Operator settings (plugin args):
session_idle_timeout(seconds, default 3300): an idle process is stopped after this. Past the provider's prompt-cache lifetime a kept process saves nothing, and the next call pays a cache write either way. The CLI writes 1-hour cache entries (ephemeral_1h, measured 2026-10-31) and each read renews them, so the default stays just under an hour of idleness.max_idle_sessions(default 4): idle processes kept, across all conversations and accounts; the least recently used goes first. Each is a Node.js process, so size this against memory.0stops every process after its call, which turns caching off.
Processes still generating are not limited by this; they are as many as the
calls in flight, as before. A process exits by itself when its stdin closes, so a
server that dies does not leave CLIs behind; a normal shutdown kills them.
Each call logs one Claude CLI usage line (the process's turn number, messages
sent, input, cache read/write and output tokens, duration, cost) so prompt-cache
behaviour can be measured: session_turn=1 is a new process. The CLI reports
cost cumulatively per process; the line and the usage record carry that turn's
share. A failed run
logs the CLI's error text and a stderr excerpt to the server log only; the user
sees the class of failure: a subscription usage limit is a rate-limit error, a
missing or expired login an authentication error. A fallback_profile on this
profile is not walked yet (only the Codex backend rotates).
Responses are buffered until validation completes: there is no token-by-token
streaming. Images are rejected. Only auto and none tool choices are supported;
forced/named choices are rejected. Sampling and output-token settings currently
do not control CLI generation. read_timeout is an absolute per-request deadline,
not an idle streaming timeout. CLI output per call is bounded; only the latest
stderr is kept for failure logs. Timeout, cancellation and failure terminate and
reap the process group; such a process is never reused.
The process launcher requires Linux/POSIX; Windows is not supported in this version.
No live CLI/account test was available during implementation. Verify a supported
CLI installation with a real subscription before production use.
Execution and credential boundary
A named-account model uses the dedicated directory for both HOME and
CLAUDE_CONFIG_DIR. Neither mode forwards API keys or OAuth token overrides
from the parent environment. Each process runs in its own new, empty temporary working directory (removed
when the process ends), disables native tools,
external tool-server configuration and hooks through CLI options, and does not
copy credentials into conversation workspace HOME. Codumentor's own tools still
use their configured execution strategy, including workspace isolation.
This subprocess is not an operating-system sandbox. It runs with the service
account's operating-system privileges, independently of the conversation's
workspace strategy. An empty working directory and disabled native tools do not
prevent a compromised CLI from accessing host files. Managed CLI policy may also
apply. Deploy only trusted executables, isolate the service account as needed,
and do not describe this provider as inheriting the workspace sandbox's
filesystem or network confinement.
Tokens are CLI-managed filesystem state, not encrypted by Codumentor's
credential database. Backups, filesystem permissions, revocation and account
rotation remain operator responsibilities. Removing the local directory is not
a guarantee of upstream token revocation. Avoid multiple independently copied
authentication directories for the same account; verify the installed CLI's
refresh/concurrency behavior before sharing a login across processes or hosts.
Subscription availability and provider-policy eligibility are not established by
this implementation. In particular, any reported June policy change has **not
been independently verified**. Check the current provider terms and the installed
CLI's documentation before deployment; this plugin does not promise that a given
subscription permits this use. No live subscription verification is implied by
unit-test success.
Runtime integration API
The plugin's meta.name is claude_code_cli; the exported class is
ClaudeCodeCLIPlugin. It owns the whole backend: the transport lives in the
package (chat_model.py, session.py, stream.py) and backend.py defines
ClaudeCodeCLIBackend, the claude-code-cli model backend.
While enabled the plugin answers two collect points
(plugins/collect_points.py):
model.backendswithClaudeCodeCLIBackend. Core dispatch finds it on the process's published plugin host. Itsbuild()refuses an account/model pair the organization did not declare, then callsplugin.build_chat_model(profile). It is keyless, refuses personal connections, classifies as organization cloud (personal for a user owner) whatever URL or privacy override a profile carries, and badges as public "Anthropic".provider_usage.adapterswith{"claude-code-cli": "claude"}, so the provider_usage plugin reads its rate-limit observations.
Disabled (args.enabled: false or listed in disabled_plugins), absent, or
left out of the edition, the plugin registers nothing. The claude-code-cli
backend then does not exist: a profile using it fails with UnknownBackend
naming the profile, the backend and this plugin, and a user's stored connection
to it is skipped as unusable.
The synchronous method validates profile.backend_options.account (schema: ClaudeCLIBackendOptions, checked for organization profiles at startup), then lazily imports
codumentor.plugins.claude_code_cli.chat_model.ClaudeCodeCLIChatModel and passes model_id,
executable, config_dir (Path for named accounts or None for the OS login),
read_timeout, context_window,
session_idle_timeout and max_idle_sessions (the last two from plugin args,
never from a profile).
An unset timeout defaults to 600 seconds; an unset context window is learned
from the CLI (see above). Disabled
plugins, missing/unknown accounts and unsafe paths fail closed. There are no
registered event hooks, routes, or OAuth/personal connection declarations.
config_args_model() exposes ClaudeCodeCLIArgs with unknown fields forbidden;
capabilities() reports whether named accounts are configured or the OS-login
mode is available, never account paths or login status.