Baize README

The project's README from github.com/Xu123-Bob/Baize. As one markdown file: README.md.

Baize Logo

Baize

Know all things, and code with you by intuition.

AtomGit

GitHub stars GitHub forks License GitHub Closed Pull Requests GitHub Contributors

GitHub release Python 3.10+

简体中文 | English | 日本語 | 한국어 | Español | Français | Русский


Baize — an auspicious beast in ancient Chinese mythology that knows all things, now reincarnated as a Vibe Coding assistant.

An open-source AI Coding Agent CLI and a drop-in alternative to Claude Code CLI. Supports multiple backends (DeepSeek / OpenAI-compatible / GLM / Qwen / Kimi / local Ollama), privacy sanitization, and multilingual interaction, with a complete toolkit: tool invocation, skill loading, subagent delegation, context compression, and secure sandbox.


Features

Installation

Prerequisites

Install from Source

Two download methods

  1. pip install https://github.com/Xu123-Bob/Baize.git

bash -- Press Win+R and enter cmd

baize
  1. <>Code --> Download ZIP

(1) After unzipping, enter this file directory:

bash -- Press Win+R and enter cmd

cd path/to/extracted/directory # If you are already in this file directory and press Win+R then cmd, skip this step

pip install -r requirements.txt

python -m Baize

After installation, press Win+R, enter cmd, open the CLI, type baize, and run it.

(2) After downloading the ZIP, install locally: unzip, enter the directory, and run:

bash -- Press Win+R and enter cmd

pip install .

After installation, press Win+R, enter cmd, open the CLI, type baize, and run it.

Quick Start

  1. First run
baize

On first run, Baize automatically generates two configuration files:

~/.baize/config.toml   # Backend configuration (choose DeepSeek / OpenAI / Ollama)

~/.baize/.env          # Key file

Windows path: C:\Users\your-username\.baize\.

  1. Choose a backend

Open ~/.baize/config.toml and modify active_provider:

active_provider = "deepseek"    # or "openai" / "ollama"

[model_providers.deepseek]
name = "DeepSeek"
base_url = "https://api.deepseek.com"
env_key = "DEEPSEEK_API_KEY"
model = "deepseek-v4-pro"

[model_providers.openai]
name = "OpenAI"
base_url = "https://api.openai.com/v1"
env_key = "OPENAI_API_KEY"
model = "gpt-4o-mini"

[model_providers.ollama]
name = "Ollama (local)"
base_url = "http://localhost:11434/v1"
env_key = ""
model = "qwen2.5:7b"
  1. Fill in the key

Edit ~/.baize/.env:

# Required for DeepSeek backend

DEEPSEEK_API_KEY=sk-your-key


# Required for OpenAI-compatible APIs (GLM / Qwen / Kimi / OpenAI)

#OPENAI_API_KEY=your-key

#Ollama local requires no key
  1. Restart
baize

If you see the black-gold logo and welcome message, startup succeeded.

Usage Examples

After startup, describe your needs in natural language at the >>> Decree: prompt:

>>> 降旨: Write a Python script to scrape Douban Top250 and save it as CSV

>>> 降旨: Help me check type errors in all Python files under src/

>>> 降旨: Find all places in this repository that use requests and change them to httpx

Multilingual Interaction

Baize supports six languages: 中文, English, 日本語, 한국어, Español, Français.

Two ways to switch:

Option 1: Just speak (auto-detect)

Baize automatically detects your input language:

>>> 降旨:Hello, help me write a Python script
[system] Detected input language: English. Baize switched to English.
(replies in English)

>>> 降旨:日本語で答えてください
[system] Detected input language: 日本語. Baize switched to 日本語.
(replies in Japanese)

Option 2: Manual command

>>> 降旨:/lang                # Show current language and available list
[system] Current language: English (en)
[system] Available:
    zh    中文
    en    English ←
    ja    日本語
    ko    한국어
    es    Español
    fr    Français

>>> 降旨:/lang English        # Switch by language name
>>> 降旨:/lang ja             # Switch by language code
>>> 降旨:/lang 西班牙语        # Chinese names work too

Supports language name / language code / localized name. To switch to English, any of English, en, 英语, 英文 works.

Baize CLI Interface

Baize CLI startup screen

Baize CLI startup screen

Baize CLI running screen

Baize CLI running screen

Built-in Commands

Ollama Local Models (Zero Cost)

Don't want to use a cloud API? Use local Ollama:

#1. Install Ollama: https://ollama.com/download
#2. Pull a model
ollama pull qwen2.5:7b

#3. Start the Ollama service
ollama serve

#4. Modify ~/.baize/config.toml
active_provider = "ollama"

#5. Start Baize
baize

Recommended models: qwen2.5:7b (strong Chinese), llama3.1:8b, deepseek-r1:7b.

Extension Mechanisms

Baize supports four extension methods. Place them in the current working directory to take effect.

Skills

Write domain knowledge in ./skills/skill-name/SKILL.md. The AI will proactively load it when encountering complex tasks.

---
name: pandas-eda

description: Best practices for exploratory data analysis with pandas

tags: data,python
---

# Pandas EDA Guide

## Core Steps
1. Use df.info() to inspect field types and missing values
2. Use df.describe() for statistical description
...

You can also manually load it in conversation with /pandas-eda.

Subagents

Define specialized subagents in ./subagent/role-name/AGENT.md. The main agent can delegate tasks through the agent tool.

---
name: code-reviewer

description: A strict code reviewer
---

You are a senior code reviewer. During review, prioritize:
1. Boundary conditions and exception handling
2. Resource leaks
3. Concurrency safety
...

Hooks

Place the following under ./hooks/:

They receive JSON input and return a decision:

#!/bin/bash

#PreToolUse-guard.sh

read -r input

if echo "$input" | grep -q "rm -rf"; then

echo '{"hookSpecificOutput":{"permissionDecision":"block","permissionDecisionReason":"Deletion prohibited"}}'

fi

Python hooks can directly call built-in APIs (see the hook_* functions in Baize.py).

MCP Servers

Configure external tool servers in ./MCP/mcp_config.json:

{
  "mcpServers": [
    {
      "name": "filesystem",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "."],
      "env": {},
      "enabled": true
    }
  ]
}

Security Design

Baize enables the following security mechanisms by default:

If you need to relax restrictions in a trusted project, modify ALLOWED_COMMANDS and FORBIDDEN_PATH_PATTERNS in Baize.py.

Privacy Sanitization

Baize ships with a bidirectional, reversible privacy sanitization mechanism. Sensitive information is replaced with placeholders before being sent to the LLM, and restored automatically in the response — completely transparent to you. What you see (history, tool arguments, final answer) is always the original text; what the LLM sees is always [[PHONE_1]], [[EMAIL_1]], etc.

Off by default. Enable when needed.

Two ways to enable

Option 1: Natural language

>>> 降旨:enable privacy sanitization
[system] Privacy sanitization enabled (standard mode).

>>> 降旨:enable strict sanitization
[system] Privacy sanitization enabled (strict mode).

>>> 降旨:disable privacy protection
[system] Privacy sanitization disabled.

Option 2: Slash commands

Two levels

Standard :Mainland China phone numbers, ID cards, bank cards (Luhn check), emails, IPv4/IPv6, OpenAI/Anthropic/GitHub/AWS API keys, Bearer tokens, private key blocks, password fields, URL credentials

Strict:All of standard + Chinese names, QQ numbers, WeChat IDs, Mainland China license plates

How it works

User input (with real PII) → messages store original text

↓ sanitize_messages()

What the LLM sees: [[PHONE_1]], [[EMAIL_1]]

↓ LLM response

Placeholders → restore_message()

Restored to original → stored / displayed / executed

Same original text reuses the same placeholder, so one phone number stays as [[PHONE_1]] throughout a session.

Tool arguments are graded by sensitivity: text-only tools like todo, ask_user_question, task_* have their arguments sanitized; path/command/URL tools like run_read, run_bash, run_webfetch are left alone (otherwise they would fail because the path was replaced).

Subagents are protected too: tasks delegated from the main agent go through the same sanitize/restore pipeline.

Example

>>> 降旨:/privacy test My phone is 13812345678, email [email protected]
Original: My phone is 13812345678, email [email protected]
Masked : My phone is [[PHONE_1]], email [[EMAIL_1]]
Restored: My phone is 13812345678, email [email protected]

>>> 降旨: /privacy status
[Privacy Sanitization]
Current mode : standard
Active rules : 15 / 19
Placeholders : 2
Sanitize calls: 3
Restore calls : 3

Directory Structure

baize-agent/
├── pyproject.toml              # Packaging configuration
├── README.md
├── tests/                      # Tests (not shipped with the package)
|   ├── __init__.py
|   ├── test_history.py
|   └── test_skill_loader.py
├── .env.example                # Environment variable example
├── .gitignore
└── agent/                      # Main package
    ├── __init__.py
    ├── Baize.py                # Main program and Agent Loop
    ├── config.py               # Multi-backend configuration loading
    ├── ui_theme.py             # CLI rendering theme
    ├── utils.py                # General utilities
    ├── logo.txt
    ├── skills/                 # Built-in skills
    ├── subagent/               # Built-in subagents
    ├── core/                   # Core logic (side-effect free, unit-testable)
    |   ├── __init__.py
    |   ├── history.py          # Session history cleaning / token estimation / compression
    |   └── privacy.py          # Privacy sanitization
    ├── hooks/                  # Built-in hooks
    └── MCP/                    # MCP client and configuration
        ├── __init__.py
        ├── mcp_client.py
        └── mcp_config.json

Environment Variable Reference

Write variables to ~/.baize/.env; there is no need to modify shell config files.

Development

Running Tests

This project uses pytest. Before development, install the package in editable mode with dev dependencies:

pip install -e ".[dev]"

Run all tests:

python -m pytest tests/ -v

Run a single file:

python -m pytest tests/test_history.py -v

Code Structure Conventions

❓ FAQ

A: ~/.baize/.env, not the .env in the project root.

A: No. Just change active_provider in ~/.baize/config.toml.

A: No. Select active_provider = "ollama" and leave env_key empty.

A: Just say "switch to /path/to/project" in the conversation, and Baize will call the set_workspace tool.

A: Baize automatically performs two-level compression: first truncating old tool results, then requesting the LLM to generate a summary. You can also manually run /compact.

A: The default command whitelist blocks dangerous operations such as rm -rf /; before writing files, it shows a Diff and asks for confirmation.

🤝 Contributing

Issues and PRs are welcome. It is recommended to first read the agent_loop function in Baize.py to understand the Agent main loop before extending it.

Thank you for every Contributor to Submit PR

Contributors

License

MIT License

Acknowledgements

☕ Support

If Baize is useful to you, you’re welcome to sponsor or tip. Independent development also takes a lot of time. Sponsorship will not change the product update schedule. Thank you for your support!

WeChat QR

Contact Me

WeChat QR code

Scan the QR code with WeChat. Please indicate "Baize Open Source Cooperation" or "Corporate Recruitment".

Douyin QR code

Scan with Douyin to follow

Baize (Xu123-Bob/Baize)

Searching Database…

581 ·GitHub
这是什么?Baize 是一个开源的 AI 编程代理 CLI,可作为 Claude Code CLI 的直接替代品:你用自然语言描述任务,它替你编写、编辑和运行代码。
它像 Claude Code 那样绑定在一家 AI 提供方上吗?不——它是一个独立的终端代理,只需改一个配置项,就能在 DeepSeek、任何 OpenAI 兼容 API(GLM/Qwen/Kimi/OpenAI)或本地 Ollama 模型之间切换。
怎么安装并开始使用它?用 pip 从源码安装,或从 GitHub 下载 ZIP,然后在终端运行 `baize`;它会在首次运行时自动生成配置文件,并引导你选择后端、输入 API 密钥。
运行它之前我需要准备什么?你需要 Python 3.10+(如果正好是 3.10 还需要 tomli)和 pip,再加上所选后端的 API 密钥——除非你对接本地 Ollama 运行,那样完全不需要密钥。
把代码交给它之前,有什么坑需要知道?默认情况下,命令白名单和路径逃逸检查会拦下 rm -rf / 这类危险操作,但对受信任的项目可以通过直接编辑 Baize.py 放宽限制;写入操作始终会先显示 Diff 并请求确认。
它会把我的个人数据发给 LLM 吗?隐私脱敏默认是关闭的;启用后,它会在发送给 LLM 之前用占位符遮盖电话号码、邮箱、身份证、银行卡和 API 密钥,并在你看到的回复里还原真实值。
Baize 里的 Skills 和 Subagents 是什么?Skills 是带有领域知识的 SKILL.md 文件,Baize 会按需为特定任务加载它们;Subagents 则是单独定义的代理(AGENT.md),主代理可以把复杂工作委托给它们,让它们的上下文不进入主对话。
我能完全离线、免费地运行 Baize 吗?可以——在 config.toml 里把 activeprovider 设为“ollama”,运行 qwen2.5:7b 或 llama3.1:8b 之类的本地模型;不需要 API 密钥,也不需要联网。
对话变得太长时会发生什么?Baize 会自动执行两级上下文压缩——先截断旧的工具结果,再让 LLM 进行总结——你也可以用 /compact 命令手动触发。
我能把 Baize 连接到外部工具吗?可以,通过 Model Context Protocol:在 ./MCP/mcpconfig.json 里配置 GitHub 或 Filesystem 等服务器,Baize 就能在会话期间直接调用它们。
Creator
Xu123-Bob
Size
30.7 MB
Stars
581
Age
1mo
Commits · 90 Days