Token导航 LogoToken导航TokenDH.com
研究检索执行命令github未标认证来源可访问许可证需确认审计提醒

claude-cli-agent-protocolClaude CLI Agent protocol 搜索

Agent Skill

claude-cli-agent-protocol 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

240

周安装

10

GitHub Stars

公开资料未说明

下载量

80
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:claude-cli-agent-protocol(Claude CLI Agent protocol 搜索)
来源仓库:https://github.com/bohdan-shulha/skills
仓库路径:skills/claude-cli-agent-protocol
安装命令:
npx skills add https://github.com/bohdan-shulha/skills --skill claude-cli-agent-protocol
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/bohdan-shulha/skills --skill claude-cli-agent-protocol

简介

claude-cli-agent-protocol 定义如何通过 NDJSON 流可靠集成 Claude Code CLI。

  • 重点解决 stdout 解析、 stdin 控制、中断恢复和批准流程一致性等问题。
  • 推荐使用 --output-format stream-json 和 --replay-user-messages 参数保障稳定性。
  • 适用于希望构建自定义 IDE 或 CI/CD 集成工具的开发者参考。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Claude CLI Agent Protocol

Overview

Integrate Claude Code CLI via NDJSON in a way that preserves true runtime state in the host UI:

  • parse all relevant stdout message types
  • send correctly shaped stdin control messages
  • handle replay and partial-stream behavior explicitly
  • keep interrupt and approval flows consistent

This skill is optimized for host builders who need reliable liveness, queueing, replay dedup, and approval UX.

Required CLI Flags

claude \
  -p \
  --output-format stream-json \
  --input-format stream-json \
  --verbose \
  --permission-prompt-tool stdio

Optional but important:

  • --replay-user-messages

- Re-emits user stdin messages on stdout for acknowledgment. - Echoed user messages include isReplay, uuid, and parent_tool_use_id.

  • --include-partial-messages

- Required if your host expects stream_event partial deltas (message_start, content_block_delta, etc.). - Without this flag, many runs emit only final assistant + result turn outputs.

Important flag constraints:

  • --input-format=stream-json requires --output-format=stream-json.
  • --replay-user-messages requires stream-json input and output.
  • --include-partial-messages works with --print and stream-json output.
  • Do not rely on prompt positional arg when building a long-lived host; send user envelopes via stdin.

Protocol Shape (NDJSON)

All messages are newline-delimited JSON objects with top-level type.

For streaming, the runtime envelope is:

{
  "type": "stream_event",
  "event": {
    "type": "content_block_delta",
    "index": 0,
    "delta": {"type": "text_delta", "text": "chunk"}
  }
}

Do not assume top-level content_block_delta envelopes in host parsing.


Emission Semantics (Critical)

Partial output behavior

  • With --include-partial-messages: host receives stream_event payloads.
  • Without it: host often receives only final assistant and result messages.

Host impact:

  • If UI "Thinking/Writing" depends only on partial deltas, it may appear idle/blank unless --include-partial-messages is enabled.

Replay behavior

With --replay-user-messages, echoed user messages include replay markers:

{
  "type": "user",
  "message": {"role": "user", "content": [{"type": "text", "text": "ping"}]},
  "session_id": "...",
  "parent_tool_use_id": null,
  "uuid": "...",
  "isReplay": true
}

Host rule:

  • Deduplicate using uuid (plus turn/session context if needed).

Result semantics

result.subtype == "success" does not mean no error by itself. Always evaluate is_error as authoritative:

{
  "type": "result",
  "subtype": "success",
  "is_error": true,
  "result": "Not logged in - Please run /login"
}

This can also accompany non-zero process exit status.


Request Lifecycles

Normal request (init -> response -> result)

  1. Host starts process.
  2. CLI emits system subtype:init.
  3. Host sends user stdin message.
  4. CLI may emit stream_event messages (if partial enabled).
  5. CLI emits assistant message(s).
  6. CLI may emit control_request (tool approval).
  7. Host sends control_response.
  8. CLI emits user tool_result echoes.
  9. CLI emits terminal result.

Interrupted request

Preferred:

  1. Host sends stdin control_request with request.subtype: "interrupt".
  2. CLI emits control_response success.
  3. CLI emits result for terminated turn.
  4. Host sends next queued user message.

Interrupt during pending tool approval

Two valid strategies:

  1. Cancel then interrupt:
  • Send control_cancel_request for pending request_id.
  • Send control_request interrupt.
  1. Deny + interrupt in one response:
  • Send control_response with behavior: "deny" and interrupt: true.

Pick one strategy and apply it consistently.


Stdout Message Types (CLI -> Host)

These are the host-relevant types to parse.

system

Common subtypes:

  • init
  • status
  • informational
  • api_error
  • hook_started
  • hook_progress
  • hook_response
  • stop_hook_summary
  • task_notification
  • turn_duration
  • compact_boundary
  • microcompact_boundary
  • local_command

Typical init fields include: cwd, session_id, tools, mcp_servers, model, permissionMode, slash_commands, claude_code_version, agents, skills, plugins, uuid.

assistant

Contains complete assistant message blocks:

  • text
  • tool_use
  • thinking (if enabled)

May include parent_tool_use_id for subagent/tool-threaded messages.

user

Used for:

  • tool result echo blocks (type: tool_result)
  • replayed user echo events when replay flag is enabled (isReplay: true)

stream_event

Contains nested event payload.

Event types:

  • message_start
  • content_block_start
  • content_block_delta
  • content_block_stop
  • message_delta
  • message_stop

Observed delta types:

  • text_delta
  • input_json_delta
  • thinking_delta
  • signature_delta
  • citations_delta

control_request

Approval or control prompt from CLI, including:

  • request.subtype: "can_use_tool"
  • request_id
  • tool details (tool_name, input, tool_use_id, optional decision_reason)

control_response

Control command acknowledgment emitted by CLI (for host-issued control requests like interrupt/set mode/model).

control_cancel_request

Cancellation signal path exists in protocol surface for pending control requests. Treat as control-plane event.

result

Terminal turn summary with:

  • subtype
  • is_error
  • token/cost/turn metadata

Result subtypes:

  • success
  • error_during_execution
  • error_max_turns
  • error_max_budget_usd
  • error_max_structured_output_retries

keep_alive

Heartbeat ping message.

tool_use_summary

Optional summarized tool-use event stream for condensed status rendering.

auth_status

Optional authentication status updates.

streamlined_text and streamlined_tool_use_summary

Optional condensed output channels. Useful for thin UIs; safe to ignore in fully structured hosts.

Observed Type and Subtype Surface (2.1.37)

Observed host-facing top-level type values (runtime + binary scan):

  • system
  • assistant
  • user
  • stream_event
  • result
  • control_request
  • control_response
  • control_cancel_request
  • keep_alive
  • tool_use_summary
  • auth_status
  • streamlined_text
  • streamlined_tool_use_summary

Observed protocol-relevant subtype values from local 2.1.37 binary:

  • api_error
  • can_use_tool
  • compact_boundary
  • error
  • error_during_execution
  • error_max_budget_usd
  • error_max_structured_output_retries
  • error_max_turns
  • hook_callback
  • hook_progress
  • hook_response
  • hook_started
  • informational
  • init
  • interrupt
  • local_command
  • mcp_message
  • microcompact_boundary
  • status
  • stop_hook_summary
  • success
  • task_notification
  • turn_duration

Stdin Message Types (Host -> CLI)

user

{
  "type": "user",
  "message": {
    "role": "user",
    "content": [{"type": "text", "text": "Your prompt"}]
  },
  "uuid": "optional-client-uuid"
}

control_request

{
  "type": "control_request",
  "request_id": "req_123",
  "request": {
    "subtype": "interrupt"
  }
}

Supported subtypes (host-facing):

  • interrupt
  • initialize
  • set_permission_mode
  • set_model
  • set_max_thinking_tokens
  • mcp_status
  • mcp_message
  • mcp_set_servers
  • mcp_reconnect
  • mcp_toggle
  • rewind_files

control_response

Use for answering can_use_tool approval requests.

Allow:

{
  "type": "control_response",
  "response": {
    "subtype": "success",
    "request_id": "req_abc123",
    "response": {
      "behavior": "allow",
      "updatedInput": {"command": "ls -la"}
    }
  }
}

Deny:

{
  "type": "control_response",
  "response": {
    "subtype": "success",
    "request_id": "req_abc123",
    "response": {
      "behavior": "deny",
      "message": "User denied"
    }
  }
}

Deny + interrupt:

{
  "type": "control_response",
  "response": {
    "subtype": "success",
    "request_id": "req_abc123",
    "response": {
      "behavior": "deny",
      "message": "User denied and wants to stop",
      "interrupt": true
    }
  }
}

control_cancel_request

Cancel pending control request by request_id.

{
  "type": "control_cancel_request",
  "request_id": "req_abc123"
}

Tool Names and Input Fields

Common tool names and key inputs:

ToolInput Fields
Bashcommand, description, timeout, run_in_background
Readfile_path, offset, limit
Writefile_path, content
Editfile_path, old_string, new_string, replace_all
Globpattern, path
Greppattern, path, glob, type, output_mode, -A, -B, -C, -i, -n
WebFetchurl, prompt
WebSearchquery, allowed_domains, blocked_domains
Tasksubagent_type, description, prompt, model, run_in_background, resume
TaskOutputtask_id, block, timeout
TaskStoptask_id
NotebookEditnotebook_path, new_source, cell_id, cell_type, edit_mode
AskUserQuestionquestions
EnterPlanModeno params
ExitPlanModeallowedPrompts, pushToRemote
Skillskill, args
TaskCreatesubject, description, activeForm, metadata
TaskGettaskId
TaskUpdatetaskId, status, subject, description, owner, addBlocks, addBlockedBy
TaskListno params

Liveness Mapping for Host UI

Recommended runtime state mapping:

  • process started -> starting
  • system:init -> ready
  • stream_event or in-flight assistant turn -> thinking/streaming
  • control_request can_use_tool -> awaiting_approval
  • result -> idle (or error if is_error=true)
  • process exit / fatal stderr / repeated auth failures -> disconnected/error

Always expose last event timestamp so users can trust the session is alive.


Process Interruption

Preferred: protocol interrupt (control_request subtype:interrupt).

Fallback: OS signal only if protocol interrupt path fails or times out.

kill(processId, SIGINT);
process.terminate();
process.waitForFinished(500);
if (process.state() != NotRunning) process.kill();

Replay and Partial Handling Rules for Hosts

  1. Treat replayed user messages as acknowledgments, not new user intent.
  2. Deduplicate by uuid before rendering persistent chat bubbles.
  3. Merge stream_event deltas into one in-progress assistant draft per turn.
  4. Replace/complete draft on final assistant or result.
  5. Do not infer completion from lack of partial events if partial streaming is disabled.

Debugging

DEBUG_CLAUDE_AGENT_SDK=1 claude --debug ...

Capture debug logs:

claude ... --debug --debug-file /tmp/claude-debug.log

Protocol Discovery (Installed Binary)

Inspect local type and subtype surfaces for the exact installed version:

strings /path/to/claude | grep -o 'type:"[a-z_][a-z_]*"' | sort -u
strings /path/to/claude | grep -o 'subtype:"[a-z_][a-z_]*"' | sort -u

Sanity-check stream-json runtime quickly:

tmpid=$(uuidgen | tr '[:upper:]' '[:lower:]')
printf '%s\n' '{"type":"user","message":{"role":"user","content":[{"type":"text","text":"ping"}]},"uuid":"'"$tmpid"'"}' \
| claude -p --output-format stream-json --input-format stream-json --verbose --replay-user-messages --permission-prompt-tool stdio --session-id "$tmpid"

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.34%
按下载量换算29

Claude

31.06%
按下载量换算25

Cursor

19.99%
按下载量换算16

Gemini CLI

8.66%
按下载量换算7

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/bohdan-shulha/skills --skill claude-cli-agent-protocol 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills