Claude Code 사용법 — mod를 만들어 도구 호출 수를 세고 명령을 추가하기
Claude Code의 mod 작성과 화면 그리기, 그리고 Claude API의 custom tool 연결과 worker 배포 방식 선택을 단계별로 보여 줍니다.
TL;DR
Claude Code의 mod를 만들고 화면에 그리는 방법을 다룹니다. Claude API에서는 worker에 custom tool을 붙이고 배포 방식을 고르는 방법을 보여 줍니다.
Create a mod
mod는 hooks module이라는 진입 파일을 가진 Claude Code plugin입니다. Claude Code는 .js와 .ts 파일을 직접 불러오므로 Node.js나 빌드 단계가 필요하지 않습니다.
먼저 claude --version으로 버전을 확인합니다. mod에는 Claude Code v2.1.287 이상이 필요합니다.
다음으로 대화형 세션에서 원하는 mod를 설명하면 Claude가 작성합니다. 이때 plugin-authoring skill을 쓰며 /plugin-authoring으로 직접 불러올 수도 있습니다.
직접 만든다면 아래 코드의 first-mod 디렉터리 구조를 따릅니다. 마지막으로 claude plugin validate로 검증합니다.
first-mod/
├── .claude-plugin/
│ └── plugin.json
└── hooks/
├── hooks.json
└── register.js Custom tools and MCP servers
custom tool은 에이전트가 agent.custom_tool_use 이벤트를 보내면 여러분의 코드가 실행하는 도구입니다. worker가 그 코드가 될 수 있습니다.
custom tool 제공에는 SDK worker가 필요합니다. ant CLI worker는 custom tool 구현을 등록할 수 없습니다.
먼저 에이전트의 tools에 custom 항목을 추가하고 name을 worker가 등록한 도구 이름과 맞춥니다. 아래 코드가 그 선언입니다.
다음으로 worker의 tools 팩토리에 도구를 넘기고 내장 toolset과 함께 둡니다. go에서는 ToolsFunc를 씁니다.
{
"type": "custom",
"name": "get_order_status",
"description": "Look up an order in the internal fulfillment system by order ID.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string", "description": "The order ID" }
},
"required": ["order_id"]
}
} Deploy workers
worker를 배포할 때는 작업을 가져오는 방법과 세션이 실행되는 위치를 각각 고릅니다.
Always-on은 프로세스가 계속 polling하며 outbound HTTPS만 필요합니다. Webhook-triggered는 session.status_run_started에서 깨어나 polling을 시작합니다.
In process는 같은 working directory에서 도구 호출을 실행합니다. Sandbox per session은 세션마다 새 sandbox를 띄웁니다.
먼저 아래 코드의 ant beta:worker poll --workdir /workspace로 시작합니다. Webhook-triggered는 ant CLI에서는 지원하지 않고 SDK에서 지원합니다.
ant beta:worker poll --workdir /workspace Draw in the interface with a mod
mod는 render site라 부르는 위치에 직접 UI를 그리거나 기존 UI를 바꿀 수 있습니다. pane, 프롬프트 위의 band, spinner가 그 예입니다.
Claude Code는 render site를 그리기 직전에 ui.render 이벤트를 발생시킵니다. 이 이벤트의 hook이 그릴 내용을 반환합니다.
먼저 claude --plugin-dir ./hello-tabs로 mod를 불러옵니다. 아래 코드는 hello-tabs의 설정 예시입니다.
다음으로 Spinner에 대한 ui.render hook에서 next를 호출해 spinner 문구를 바꿉니다. next를 호출하지 않으면 반환한 줄이 spinner 자리에 그려집니다.
{
"name": "hello-tabs",
"version": "0.1.0",
"description": "Opens a pane with two tabs and a counter",
"author": { "name": "Your Name" }
} 정리
Claude Code mod는 claude plugin validate로 검증하면서 만들 수 있습니다. Claude API worker는 배포 방식을 고른 뒤 custom tool을 붙이면 됩니다.
공식 문서와 예제에 적힌 내용만 담았습니다.