一键调用 Claude Code,即时返回完整结果
简介
通过 OpenClaw 调用本地 Claude Code CLI 执行代码任务并即时返回结果,适合需要文件编辑、代码分析和 Bash 命令的自动化场景。
原始描述
Delegate a task to Claude Code CLI and immediately report the result back in chat. Supports persistent sessions — Claude Code remembers previous context with...
通过你的 Agent 添加
安装目录:ask-claude-skill/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
技能正文
name: ask-claude
description: >
Run Claude Code CLI from inside OpenClaw and immediately report the result back to the user in chat.
Use when the user asks to: run Claude, ask Claude something, execute a coding task via Claude,
or any task that benefits from Claude Code's tools (file editing, code analysis, bash commands, etc.).
ALWAYS run synchronously and ALWAYS paste the full result in this chat — never just say "done".
metadata:
{
"openclaw": {
"emoji": "🤖",
"requires": { "anyBins": ["claude"] }
}
}
Ask Claude — Execute & Report
Delegates a task to the local Claude Code CLI and reports the full result back in chat without requiring the user to follow up.
The Pattern (always follow this exactly)
# IMPORTANT: env -u CLAUDECODE is required to avoid "nested session" error
OUTPUT=$(cd "${WORKDIR:-$HOME}" && env -u CLAUDECODE claude \
--permission-mode bypassPermissions \
--print \
"your task here" 2>&1)
echo "$OUTPUT"
# IMPORTANT: env -u CLAUDECODE is required to avoid "nested session" error
OUTPUT=$(cd "${WORKDIR:-$HOME}" && env -u CLAUDECODE claude \
--permission-mode bypassPermissions \
--print \
"your task here" 2>&1)
echo "$OUTPUT"
After the bash call completes, immediately include the result in your reply:
✅ Claude did: [result here]
Rules
- NEVER use
background: true for Claude tasks unless the user explicitly says they don't need the result now
- ALWAYS include the actual output in your response — don't just say "done" or "executed"
- If the output is long (>50 lines), summarize the key points and offer to share the rest
- If Claude edited or created files, mention which ones
- If Claude returned an error, analyze it and suggest a fix
Trigger phrases
- "ask claude to..."
- "run claude and..."
- "use claude code to..."
- "let claude analyze..."
- "have claude fix..."
- "delegate to claude..."
Why env -u CLAUDECODE?
background: true for Claude tasks unless the user explicitly says they don't need the result now- "ask claude to..."
- "run claude and..."
- "use claude code to..."
- "let claude analyze..."
- "have claude fix..."
- "delegate to claude..."
Why env -u CLAUDECODE?
Claude Code sets the CLAUDECODE environment variable when it's running. If OpenClaw inherits this variable and tries to launch another claude process, the nested session check blocks it. Unsetting it with env -u CLAUDECODE bypasses this safely — it only affects the subprocess, not the parent.
Example
User: "ask claude to check if there are any syntax errors in my project"
OUTPUT=$(cd ~/my-project && env -u CLAUDECODE claude \
--permission-mode bypassPermissions \
--print \
"check all Python files in this directory for syntax errors and list any issues" 2>&1)
echo "$OUTPUT"
Then reply with what Claude found.
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。