masahide/agent-kit/tree/main/plugins/agentctl
agentctl
A Claude Mod that delivers messages from the agentctl CLI (tools/agentctl) to Claude Code sessions, plus an accompanying skill (skills/agentctl) that teaches an agent how to use agentctl.
About this mod
The agentctl Mod watches the inbox at ~/.agentctl/claude/<sessionId>/inbox/ every 500ms for messages placed there by the agentctl CLI, delivers them to the Claude session with $.prompt.submit, aborts an interrupt request with $.turn.abort, and writes the result to acks/. It registers the session.start / turn.start / turn.complete hooks, and records the PID and start time in mod.json to match them against the session record. The accompanying agentctl skill teaches an agent how to use agentctl. It targets Claude Code 2.1.283 function hooks (early access, CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1) and includes validation steps using claude plugin validate / test.
Installation
Check the author's README for the marketplace and plugin name first. Commands may change as the repository evolves.
claude plugin marketplace add masahide/agent-kit claude plugin install agentctl
Original text / README
agentctl Mod
agentctl CLI (tools/agentctl) が Claude Code のセッションにメッセージを届けるための Claude Mod と、agent に agentctl の使い方を教える付属スキル (skills/agentctl) です。使い方は docs/agentctl/usage.md、背景と決定は docs/agentctl/plan.md にあります。
対象は Claude Code 2.1.283 の Claude Mods (function hooks、早期アクセス) です。CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 が要ります。
何をするか
セッションの一覧と状態は、CLI が Claude Code 本体のセッション記録 (~/.claude/sessions/<pid>.json) から読みます。この Mod がするのは、受信箱のメッセージを Claude に届けることだけです。
~/.agentctl/claude/<sessionId>/
mod.json Mod が session.start で書く ({ v, sessionId, pid, modVersion, startedAt })
meta.json CLI だけが書く (名前、アーカイブの印)
inbox/<id>.json CLI が書く ({ v, id, kind: "prompt"|"interrupt", text?, createdAt })
acks/<id>.json Mod が書く ({ v, id, status, detail?, at })
session.start:mod.jsonを書きます。pidはsh -c 'echo $PPID'で取った claude の pid で、CLI はこれをセッション記録の pid と照合して、前のプロセスが残したmod.jsonを使いません。Windows ではshが無い (pidは 0) か、Git Bash のshで MSYS の pid になって一致しないので、CLI はstartedAtがプロセスの起動より後なら、pid が違っても Mod が載っているとみなします。ホームはUSERPROFILE、無ければHOMEです。AGENTCTL_HOMEがあれば~/.agentctlの代わりに使います。- 500 ms ごとに
inbox/を$.fs.listし、まだ ack の無いメッセージを古い順に処理します。prompt: turn の実行中なら先にqueuedの ack を書き、$.prompt.submitが返ったら (次の turn が始まったら)submittedに書き換えます。{ drop }ならdropped、throw したらerrorです。interrupt: main の turn の実行中なら$.turn.abortで止めてaborted、そうでなければno_turnです。
turn.start/turn.complete(main のみ): 実行中の turn の id を覚えます。- Mod はファイルを消しません。処理済みの受信箱と ack は CLI が消します。
Claude には、投入した文が「The agentctl plugin sent a message:」を前に付けた user turn として見えます (Claude Code がそう見せます)。
確かめ方
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude plugin validate plugins/agentctl
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude plugin test plugins/agentctl
npx -y -p typescript tsc -p plugins/agentctl --noEmit # 先に /plugin-types で .claude/types を作る
claude plugin validate の印字:
> ./register.ts hooks: turn.start, turn.complete, session.start
> ./register.ts calls: $.clock.every, $.clock.now, $.env.get, $.fs.exists, $.fs.list, $.fs.read, $.fs.write, $.process.run, $.prompt.submit, $.session.id, $.turn.abort, $.ui.log
> ./register.ts env reads: AGENTCTL_HOME, HOME, USERPROFILE
ファイル
| パス | 中身 |
|---|---|
| hooks/register.ts | フックの登録と受信箱の監視 |
| hooks/inbox.ts | 受信箱の処理の純関数 (ファイル名の選別、メッセージの検査、ack の作成) |
| hooks/protocol.ts | 共有ディレクトリのファイルの形。CLI の internal/claude/protocol.go と同じ |
| skills/agentctl/SKILL.md | 付属スキル。Codex でも ~/.codex/skills/ に写せば使える |
| tests/fixtures/protocol/*.json | ファイルの見本。Go のテストも読む |
| tests/fixtures/protocol.ts | 同じ見本の TS 版 (Mod のテストは JSON を import できないため)。ずれは Go の TestProtocolFixtures が見つける |