Skip to content

feat(llm): add Claude Code CLI as an LLM provider - #625

Open
IkoAfianando wants to merge 1 commit into
BaaRai:mainfrom
IkoAfianando:feat/claude-code-provider
Open

IkoAfianando wants to merge 1 commit into
BaaRai:mainfrom
IkoAfianando:feat/claude-code-provider

Conversation

@IkoAfianando

@IkoAfianando IkoAfianando commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

Adds a claude-code LLM profile format that drives ARTEX's agents with the local claude binary instead of an HTTP endpoint, so a Claude subscription (or a claude setup-token OAuth token) can power exploration.

ARTEX keeps its own agent loop, tools, permissions and transcripts. Norma still speaks Anthropic Messages to a placeholder URL; a new transport answers each request by running one claude -p process with every built-in tool, MCP server, settings source and slash command disabled, so the CLI only produces text:

  • ARTEX's tool definitions go into the system prompt with a small JSON reply protocol, and the reply's tool calls are turned back into tool_use blocks, so tools still run under ARTEX's executor and interception rules.
  • The whole conversation is rendered into the prompt on stdin (each process is a fresh, stateless session).
  • The process gets a minimal environment, never the server's secrets; CLAUDE_CODE_OAUTH_TOKEN is added to the startup env scrub.

Keyless like Ollama: no API key needed when the CLI has its own login. Model is an alias (opus/sonnet/haiku) or a full model ID.

Changes

  • agent/claude_code.go (new) + tests — the transport, reply protocol, prompt rendering and error/status mapping.
  • agent/provider.go — FormatClaudeCode, IsKeylessFormat, FromEnv, ConfigFrom, Provider(), NewProvider() wiring.
  • server — model-list endpoint (offers the aliases), connection test, task resolution, env scrub.
  • db — relaxed llm_profiles format check + migration 0016.
  • web — System → LLM format option, token field, hidden base URL, types, tr/zh-CN i18n.
  • Docker / docs — image installs the CLI and keeps its login in the root-only keys volume; README section and .env.example.

Testing

  • go test ./agent/ ./server/ ./db/ pass; new unit tests cover tool-call round-trips, streaming, prose fallback, auth-error handling (not retried, token scrubbed) and server-secret isolation.
  • Verified live against the real claude CLI: connection test returns OK; the agent loop returns a valid Bash tool call.
  • Rebuilt the Docker image: claude present, isolation self-test still passes, migration 0016 applied.

Notes / limitations

  • Each turn resends the whole conversation and runs a CLI process (~1–3s overhead); no token-by-token streaming; images in tool results become a placeholder.
  • Usage counts against the subscription's limits — a usage-limit reply maps to HTTP 429, a missing login to 401.
  • ARTEX_CLAUDE_CODE_MAX_PROCS (default 4) caps concurrent CLI processes.

Add a "claude-code" LLM profile format that drives ARTEX's agents with the
local `claude` binary instead of an HTTP endpoint, so a Claude subscription
(or a `claude setup-token` OAuth token) can power exploration.

ARTEX keeps its own agent loop, tools, permissions and transcripts. Norma still
speaks Anthropic Messages to a placeholder URL; claudeCodeTransport answers each
request by running one `claude -p` process with every built-in tool, MCP server,
settings source and slash command disabled, so the CLI only produces text:

- ARTEX's tool definitions go into the system prompt with a small JSON reply
  protocol, and the reply's tool calls are turned back into tool_use blocks;
- the whole conversation is rendered into the prompt on stdin (each process is a
  fresh, stateless session);
- the process gets a minimal environment, never the server's secrets, and the
  OAuth token is scrubbed from the environment after startup.

Keyless like Ollama: no API key required when the CLI has its own login. Model
is an alias (opus/sonnet/haiku) or a full model ID. Wired through FromEnv,
ConfigFrom, the model-list and connection-test endpoints, task resolution, the
System -> LLM UI (format option, token field, hidden base URL) and i18n. The
Docker image installs the CLI and keeps its login in the root-only keys volume.

Adds migration 0016 relaxing the llm_profiles format check, plus unit tests
covering tool-call round-trips, streaming, prose fallback, auth-error handling
and secret isolation.
@BaaRai

BaaRai commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Holding this as a fallback. The older #622 covers the Claude Code provider and is under review; no action is needed unless #622 cannot address its review, in which case this PR would be the replacement and would need a rebase plus the no-token profile fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants