How Codex, Gemini CLI, OpenCode and ZCode authorize tool actions
A Juejin AI source-code analysis compares user authorization and permission handling in Codex, Gemini CLI, OpenCode and ZCode. It describes how each framework resolves tool-call requests through once, session or persistent approvals, with differences in sandboxes, trust directories, ordered permission rules, sub-agent inheritance and dangerous-command safeguards. The comparison is based on repository snapshots the author says were checked line by line in November 2026, but the findings have not been independently verified.
The analysis gives developers and security researchers a concrete view of how four coding agents gate commands and file operations before execution, making it useful for understanding the approval boundaries of local AI agents.
系列第八篇。前作:四大 Agent 源码对比、循环与 Token 压缩、防跑偏机制、上下文 Context 构成与管理、工具/MCP/插件/Skill 机制、系统提示词注入机制、永久记忆与记忆召回。 本文基于 2026-11 拉取的四个仓库最新源码逐行核验:openai/codex(codex-rs, Rust)、google-gemini/gemini-cli(TypeScript)、sst/opencode(dev 分支, Effect 重写版)、zai-org/ZCode(TypeScript monorepo)。所有
文件:行号均真实存在,可自行对照。
一、开场故事:新来的实习生
想象你开了一家公司,雇了个超级能干的实习生(大模型)。
它聪明、勤奋、随叫随到,但它有个致命特点:它是从天而降的,跟你没有任何共同记忆。你让它"清理一下临时文件夹",它的理解可能是 rm -rf /tmp——也可能是 rm -rf /。它不是坏,它是真的不知道轻重。
更麻烦的是,这个实习生不是直接用手干活。它每做一个动作,都要通过一张"工具工单"(tool call):工单 #1024:申请执行 rm -rf /tmp/cache。你的电脑就是它的工作现场,工单一签,当场执行。