需配置钉钉自定义机器人Webhook并禁用加签,修改.codex/config.json启用通知,在post-run.js和on-error.js中用axios推送执行结果与错误日志,安装axios依赖后验证消息可达性。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 多模态理解力帮你轻松跨越从0到1的创作门槛☜☜☜

要让Codex自动把代码执行结果、错误日志或关键调试信息推送到钉钉群,必须绕过手动复制粘贴,建立稳定、可复用的HTTP消息通道。
获取钉钉自定义机器人Webhook地址
打开目标钉钉群 → 点击右上角「群设置」→「智能群助手」→「添加机器人」→ 选择「自定义机器人」→ 勾选「我已阅读并同意」→ 输入机器人名称(如“Codex-Debug”)→ 点击「完成」。
在弹出的配置页中,复制完整Webhook地址,格式为:https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxx。
【务必关闭“安全设置”中的“加签”选项】——Codex当前不原生支持HMAC-SHA256加签逻辑,开启后所有POST请求将被钉钉拒绝返回401错误。
在Codex项目中注入钉钉通知逻辑
进入Codex项目根目录,在.codex/config.json中新增notifications字段:
"notifications": {"dingtalk": {"webhook": "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxx","enabled": true}}
若使用Qwen3-4B-Thinking-2507-GPT-5-Codex-Distill-GGUF模型,需确保其运行时环境已安装node-fetch或axios:运行npm install axios --save-dev。
这一步不能跳过,否则后续调用sendDingtalkMessage()函数会直接报ReferenceError: axios is not defined。
编写触发式通知脚本
方法一:任务结束钩子(推荐)
在.codex/hooks/post-run.js中写入:
const axios = require('axios');
module.exports = async (context) => {
if (!context.config.notifications?.dingtalk?.enabled) return;
通过本地 Codex 或 OpenClaw OAuth 凭证直接调用 ChatGPT/Codex Responses 的 image_generation 工具来生成或编辑光栅图像,然后保存
await axios.post(context.config.notifications.dingtalk.webhook, {
msgtype: 'text',
text: { content: `[Codex] ✅ ${context.taskId} 执行完成|耗时 ${context.durationMs}ms|输出行数:${context.outputLines || 0}` }
});
};
方法二:错误拦截推送
在.codex/hooks/on-error.js中补充:
await axios.post(webhookUrl, { msgtype: 'markdown', markdown: { title: '⚠️ Codex 运行异常', text: `### 错误摘要\n- 任务ID:${context.taskId}\n- 错误类型:${err.name}\n- 堆栈片段:\n\`\`\`${err.stack?.split('\n').slice(0,3).join('\n')}\`\`\`` } });
注意:此处err.stack未做长度截断,若原始堆栈超2000字符,钉钉API会返回400错误并丢弃整条消息。
验证消息是否成功发出
第一步:在Codex CLI中执行一个最小测试任务:codex run --script "console.log('test from codex')"。
第二步:观察钉钉群是否收到格式为「[Codex] ✅ task-xxxxxx 执行完成|耗时 xxxms|输出行数:1」的消息。
第三步:故意触发一次语法错误:codex run --script "consol.log('crash')",确认钉钉群同步收到带堆栈片段的⚠️警告消息。

















