shlex.quote() wraps its argument in single quotes, which suppress tilde
expansion. CLAUDE_CONFIG_DIR='~/chat-<id>/.claude' was being handed to
Claude Code as a literal path beginning with `~`, so the CLI treated it
as a relative directory and created `./~/chat-<id>/.claude/` under cwd.
Concrete symptoms:
- Session history JSONLs written to the wrong path, silently defeating
#5 (disk-based session recovery couldn't find them).
- Per-chat config isolation (#9) silently degraded to a shared dir
whose actual location depended on whatever cwd the turn ran in.
- Symlinked skills placed at the correct path were never discovered by
Claude, because CLAUDE_CONFIG_DIR pointed elsewhere.
- `.claude.json` artifacts from the stray tree picked up by the
artifact walker → attempted upload → open-terminal 403 because the
`~` path segment failed its path-sanity check.
Fix by pre-expanding a leading `~/` to `$HOME/` and double-quoting so
$HOME expands at shell parse time. Also prune `.claude/` and any stray
`~` literal directory from the artifact find() so Claude's internal
state never masquerades as a user artifact going forward.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||
|---|---|---|
| anthropic-proxy | ||
| sandbox | ||
| .gitignore | ||
| README.md | ||
| claude_agent_pipe.py | ||
| claude_agent_pipe_sandboxed.py | ||
| sync_pipe.py | ||
README.md
OpenWebUI Claude Code Pipe
Run Claude Code's agent loop from inside Open WebUI chats, via the Claude Agent SDK.
This is an Open WebUI Pipe that exposes Claude Code as a selectable model. Each chat gets its own isolated workspace directory; agent turns within the same chat resume the same Claude Code session, so context (files, prior tool calls) carries forward.
Features
- Full Claude Code agent loop — Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch (configurable allowlist)
- Per-chat workspaces — each
chat_idgets a sandboxed working directory that persists across turns - Dual auth — bring your own Anthropic API key (pay-per-token) or a Claude Pro/Max OAuth token (bills against your subscription)
- Streaming UI — tool calls render inline with previews; generated images/PDFs/CSVs surface as artifacts in the chat
- Configurable valves — model, permission mode, tool allowlist, max turns, workspace root
Requirements
- Open WebUI (any recent version with the Pipes/Functions framework)
- Python deps (auto-installed by Open WebUI from the file header):
claude-agent-sdk>=0.1.60anthropic>=0.40.0
- The
claudeCLI must be available on the host running Open WebUI's Python backend (the SDK shells out to it). Install vianpm install -g @anthropic-ai/claude-code.
Installation
- In Open WebUI, go to Workspace → Functions → + (or Admin Panel → Functions).
- Paste the contents of
claude_agent_pipe.pyinto the editor. - Save and enable the function.
- Open the function's Valves and configure auth (one of):
ANTHROPIC_API_KEY— standard pay-per-token billingCLAUDE_CODE_OAUTH_TOKEN— generate on a machine with a browser viaclaude setup-token; bills against your Pro/Max/Team subscription
- A new model named Claude Code will appear in the model picker.
Configuration (Valves)
| Valve | Default | Description |
|---|---|---|
ANTHROPIC_API_KEY |
(env) | Anthropic API key. Falls back to the backend's env var. |
CLAUDE_CODE_OAUTH_TOKEN |
(empty) | Claude subscription OAuth token. Takes priority over the API key when set. |
MODEL |
claude-haiku-4-5 |
Claude model ID (e.g. claude-haiku-4-5, claude-sonnet-4-6, claude-opus-4-7). |
PERMISSION_MODE |
bypassPermissions |
default, acceptEdits, bypassPermissions, plan, or dontAsk. |
ALLOWED_TOOLS |
Read,Write,Edit,Bash,Glob,Grep,WebSearch,WebFetch |
Comma-separated tools auto-approved without prompting. |
WORKDIR_ROOT |
/tmp/claude-agent-pipe |
Root directory for per-chat workspaces. |
MAX_TURNS |
30 |
Max agent turns per user message. 0 disables the cap. |
Auth notes
When both auth methods are present, the OAuth token wins and the API key is unset before invoking the SDK so it can't override.
Per Anthropic's terms: a Claude subscription is for personal use — don't re-offer subscription auth to other end users through a shared Open WebUI deployment. For multi-user setups, use API keys.
License
MIT