命令行参数
本文档详细介绍了 Codely CLI 的所有命令行参数和子命令的用法。
基本用法
codely [选项] [命令]
启动 Codely CLI 交互式界面,或使用 -p/--prompt 进入非交互模式。
全局选项
模型相关选项
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --model | -m | string | GEMINI_MODEL 环境变量 | 指定使用的主要模型 |
| --multimodal | - | string | CODELY_MULTIMODAL 环境变量 | 用于图像/视频分析的多模态模型 |
| --flash | - | string | CODELY_FLASH_MODEL 环境变量 | 用于内部操作的 Flash 模型(作为回退目标) |
示例:
codely --model qwen-max
codely --multimodal qwen-vl-max
codely --flash qwen-turbo
交互模式选项
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --prompt | -p | string | - | 提供提示词(非交互模式)。如果同时提供 stdin 输入,会追加到输入后 |
| --prompt-interactive | -i | string | - | 执行提供的提示词后继续进入交互模式 |
注意: --prompt 和 --prompt-interactive 不能同时使用。
示例:
# 非交互模式,执行单个提示词
codely -p "帮我写一个 Python 函数"
# 执行提示词后进入交互模式
codely -i "初始化一个 React 项目"
文件和上下文选项
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --all-files | -a | boolean | false | 将所有文件包含在上下文中 |
| --include-directories | - | array | - | 额外要包含在工作区中的目录(逗号分隔或多次使用该选项) |
已弃用: --all_files(请使用 --all-files)
示例:
# 包含所有文件
codely --all-files
# 包含额外目录
codely --include-directories /path/to/extra --include-directories /another/path
codely --include-directories /path1,/path2
审批和安全选项
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --yolo | -y | boolean | false | 自动接受所有操作(YOLO 模式) |
| --approval-mode | - | string | default | 设置审批模式: - default: 提示审批 - auto_edit: 自动批准编辑工具 - yolo: 自动批准所有工具 |
注意: --yolo 和 --approval-mode 不能同时使用。
示例:
# YOLO 模式(自动批准所有操作)
codely --yolo
# 自动批准编辑工具,其他工具仍需审批
codely --approval-mode auto_edit
调试和日志选项
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --debug | -d | boolean | false | 以调试模式运行 |
| --show-memory-usage | - | boolean | false | 在状态栏显示内存使用情况 |
已弃用: --show_memory_usage(请使用 --show-memory-usage)
示例:
codely --debug
codely --show-memory-usage
MCP 服务器选项
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --allowed-mcp-server-names | array | - | 允许的 MCP 服务器名称列表 |
示例:
codely --allowed-mcp-server-names server1,server2
codely --allowed-mcp-server-names server1 --allowed-mcp-server-names server2
扩展选项
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --extensions | -e | array | - | 要使用的扩展列表。如果未提供,则使用所有扩展 |
| --list-extensions | -l | boolean | false | 列出所有可用扩展并退出 |
示例:
# 只使用指定的扩展
codely --extensions github,jira
# 列出所有可用扩展
codely --list-extensions
沙箱选项 ** experimental **
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --sandbox | -s | boolean | - | 在沙箱中运行 |
| --sandbox-image | - | string | - | 沙箱镜像 URI |
示例:
codely --sandbox
codely --sandbox-image my-sandbox-image:latest
功能开关
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --checkpointing | -c | boolean | false |
| --experimental-acp | boolean | false | 在 ACP 模式下启动代理 |
| --agents | boolean | true | 启用或禁用代理系统 |
示例:
codely --checkpointing
codely --experimental-acp
codely --agents=false
网络和代理选项
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --proxy | string | - | Gemini 客户端的代理,格式:schema://user:password@host:port |
示例:
codely --proxy http://user:pass@proxy.example.com:8080
codely --proxy socks5://127.0.0.1:1080
OpenAI 兼容性选项
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --openai-logging | boolean | - | 启用 OpenAI API 调用的日志记录以进行调试和分析 |
| --openai-api-key | string | - | 用于身份验证的 OpenAI API 密钥 |
| --openai-base-url | string | - | OpenAI 基础 URL(用于自定义端点) |
| --reasoning_effort | string | - | OpenAI reasoning_effort 参数(minimal|low|medium|high) |
| --enable_thinking | boolean | - | OpenAI 兼容扩展:设置 chat_template_kwargs.enable_thinking |
别名: --reasoning_effort 可简写为 --reasoningEffort --enable_thinking 可简写为 --enableThinking
示例:
codely --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1
codely --reasoning_effort high --enable_thinking
Web 搜索选项
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --tavily-api-key | string | - | Tavily API 密钥,用于 Web 搜索功能 |
| --searxng-url | string | - | SearXNG 实例 URL,用于 Web 搜索 |
示例:
codely --tavily-api-key tvly-xxx
codely --searxng-url https://searx.example.com
示例提示词和工具选项
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --example-prompt | string | - | 从 example-prompts 文件夹加载并执行示例提示词(仅非交互模式) |
| --list-example-prompts | boolean | false | 列出所有可用的示例提示词 |
| --list-tools | boolean | false | 列出所有可用的内置工具 |
| --exclude-tools | array | - | 为此会话排除特定工具(不修改设置) |
注意: --example-prompt 不能与 --prompt 或 --prompt-interactive 同时使用。
示例:
# 列出所有示例提示词
codely --list-example-prompts
# 使用示例提示词
codely --example-prompt my-prompt
# 列出所有工具
codely --list-tools
# 排除特定工具
codely --exclude-tools shell,edit
输出格式选项
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --output-format | string | text | 响应的输出格式(text|json|stream-json) |
示例:
codely --output-format json
codely --output-format stream-json
通用选项
| 参数 | 简写 | 描述 |
|---|---|---|
| --version | -v | 显示版本号并退出 |
| --help | -h | 显示帮助信息 |
子命令
mcp 命令
管理 MCP 服务器,以扩展 Tuanjie AI 的功能和外部工具及服务。
mcp add
添加新的 MCP 服务器。
codely mcp add <name> <commandOrUrl> [args...] [选项]
选项:
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --scope | -s | string | project | 配置范围(user 或 project) |
| --transport | -t | string | stdio | 传输类型(stdio|sse|http) |
| --env | -e | array | - | 设置环境变量(如 -e KEY=value) |
| --header | -H | array | - | 为 SSE 和 HTTP 传输设置 HTTP 头 |
| --timeout | - | number | - | 设置连接超时(毫秒) |
| --trust | - | boolean | - | 信任服务器(绕过所有工具调用确认提示) |
| --description | - | string | - | 设置服务器的描述 |
| --include-tools | - | array | - | 要包含的工具列表(逗号分隔) |
| --exclude-tools | - | array | - | 要排除的工具列表(逗号分隔) |
示例:
# 添加 stdio 服务器
codely mcp add my-server python /path/to/server.py --env API_KEY=abc123 --env DEBUG=true
# 添加 HTTP 服务器
codely mcp add my-http-server http://localhost:8000 --transport http --header "Authorization: Bearer token"
# 添加带有工具过滤的服务器
codely mcp add my-server python /path/to/server.py --include-tools tool1,tool2 --exclude-tools dangerous-tool
# 添加用户级配置
codely mcp add my-server python /path/to/server.py --scope user --description "我的个人工具服务器"
# 添加受信任的远程 HTTP 服务器
codely mcp add secure-server https://api.example.com/mcp --transport http --header "X-API-Key: abc123xyz" --trust
mcp remove
移除指定的 MCP 服务器。
codely mcp remove <name> [选项]
选项:
| 参数 | 简写 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| --scope | -s | string | project | 配置范围(user 或 project) |
示例:
# 移除项目级服务器
codely mcp remove my-server
# 移除用户级服务器
codely mcp remove my-server --scope user
mcp list
列出所有已配置的 MCP 服务器及其连接状态。
codely mcp list
输出示例:
✓ my-server: python /path/to/server.py (stdio) - Connected
✗ http-server: http://localhost:8000 (http) - Disconnected
extensions 命令
管理 Codely CLI 扩展。完全兼容 https://geminicli.com/extensions/
extensions install
从 git 仓库 URL 或本地路径安装扩展。
codely extensions install <source> [选项]
位置参数:
| 参数 | 描述 |
|---|---|
| source | GitHub URL(如 https://github.com/owner/repo 或 owner/repo)、git URL 或扩展的本地路径 |
选项:
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| --ref | string | - | 要安装的 git 引用 |
| --auto-update | boolean | - | 为此扩展启用自动更新 |
| --pre-release | boolean | - | 为此扩展启用预发布版本 |
| --consent | boolean | false | 确认安装扩展的安全风险并跳过确认提示 |
示例:
# 从 GitHub 安装(完整 URL)
codely extensions install https://github.com/owner/repo
# 从 GitHub 安装(简写)
codely extensions install owner/repo
# 指定分支或标签
codely extensions install https://github.com/owner/repo --ref main
# 启用自动更新
codely extensions install https://github.com/owner/repo --auto-update
# 安装预发布版本
codely extensions install https://github.com/owner/repo --pre-release
# 从本地路径安装
codely extensions install /path/to/local/extension
# 跳过确认提示
codely extensions install https://github.com/owner/repo --consent
extensions uninstall
卸载已安装的扩展。
codely extensions uninstall <name>
extensions list
列出所有已安装的扩展。
codely extensions list
extensions update
更新已安装的扩展。
codely extensions update [name]
如果不指定名称,则更新所有扩展。
extensions enable
启用已禁用的扩展。
codely extensions enable <name>
extensions disable
禁用已安装的扩展。
codely extensions disable <name>
extensions link
链接本地扩展进行开发。
codely extensions link <name> <path>
extensions new
创建一个新的扩展脚手架。
codely extensions new <name>
环境变量
除了命令行参数,Codely CLI 还支持以下环境变量:
| 环境变量 | 描述 |
|---|---|
| GEMINI_MODEL | 默认使用的模型 |
| CODELY_MULTIMODAL | 默认的多模态模型 |
| CODELY_FLASH_MODEL | 默认的 Flash 模型 |
| OPENAI_API_KEY | OpenAI API 密钥 |
| OPENAI_BASE_URL | OpenAI 基础 URL |
| OPENAI_MODEL | OpenAI 模型名称 |
| TAVILY_API_KEY | Tavily API 密钥 |
| SEARXNG_URL | SearXNG 实例 URL |
| HTTP_PROXY / http_proxy | HTTP 代理 |
| HTTPS_PROXY / https_proxy | HTTPS 代理 |
| OTEL_EXPORTER_OTLP_ENDPOINT | OTLP 导出端点 |
| DEBUG / DEBUG_MODE | 启用调试模式(设置为 true 或 1) |
| NO_BROWSER | 禁用浏览器功能 |
示例
基本使用
# 启动交互式模式
codely
# 使用指定模型启动
codely --model qwen-max
# 非交互模式执行单个任务
codely -p "帮我写一个快速排序算法"
高级用法
# YOLO 模式 + 包含所有文件
codely -y -a -p "重构整个项目"
# 启用遥测并输出到文件
codely --telemetry --telemetry-outfile /tmp/telemetry.log
# 只使用特定扩展
codely -e github,jira
# 使用 OpenAI 兼容 API
codely --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1 --model gpt-4
# 使用 Web 搜索
codely --tavily-api-key tvly-xxx -p "搜索最新的 AI 新闻"
# JSON 格式输出
codely --output-format json -p "分析这个项目的结构"
MCP 服务器管理
# 添加 stdio MCP 服务器
codely mcp add filesystem node /path/to/mcp-filesystem-server/dist/index.js --env ALLOW_READ=/path/to/project
# 添加 HTTP MCP 服务器
codely mcp add custom-tools http://localhost:3000 --transport http --header "Authorization: Bearer token"
# 列出所有 MCP 服务器
codely mcp list
# 移除 MCP 服务器
codely mcp remove filesystem
扩展管理
# 安装扩展
codely extensions install https://github.com/owner/my-extension
# 安装并启用自动更新
codely extensions install https://github.com/owner/my-extension --auto-update
# 列出所有扩展
codely extensions list
# 禁用扩展
codely extensions disable my-extension
# 更新所有扩展
codely extensions update
Unity 集成
# 启动 Unity MCP 服务器(HTTP 模式)
codely serve unity-mcp --http --unity-project-path /path/to/UnityProject
# 启 动 Unity MCP 服务器(stdio 模式,用于 Claude Desktop)
codely serve unity-mcp --stdio --unity-project-path /path/to/UnityProject
# 启用调试模式
codely serve unity-mcp --http --unity-project-path /path/to/UnityProject --debug
注意事项
参数优先级:命令行参数的优先级高于环境变量,环境变量的优先级高于配置文件。
互斥参数:某些参数不能同时使用,如 --prompt 和 --prompt-interactive,--yolo 和 --approval-mode。
已弃用参数:以下参数已弃用,请使用新参数: --all_files → --all-files --show_memory_usage → --show-memory-usage
沙箱模式:在沙箱模式下运行时,文件系统访问会受到限制。
遥测:使用 --telemetry 标志来启用遥测,仅设置其他 --telemetry-* 标志不会自动启用遥测。
MCP 服务器:添加 MCP 服务器时,如果 URL 以 http:// 或 https:// 开头,会自动检测为 HTTP 传输类型。