Loading...
    • 개발자 가이드
    • API 레퍼런스
    • MCP
    • 리소스
    • 릴리스 노트
    Search...
    ⌘K
    시작하기
    Claude 소개빠른 시작
    모델 및 가격
    모델 개요모델 선택Claude 4.6의 새로운 기능마이그레이션 가이드모델 지원 중단가격
    Claude로 구축하기
    기능 개요Messages API 사용중지 사유 처리프롬프트 모범 사례
    컨텍스트 관리
    컨텍스트 윈도우압축컨텍스트 편집
    기능
    프롬프트 캐싱확장 사고적응형 사고노력 수준메시지 스트리밍배치 처리인용다국어 지원토큰 카운팅임베딩비전PDF 지원Files API검색 결과구조화된 출력
    도구
    개요도구 사용 구현 방법세분화된 도구 스트리밍Bash 도구코드 실행 도구프로그래밍 방식 도구 호출컴퓨터 사용 도구텍스트 편집기 도구웹 페치 도구웹 검색 도구메모리 도구도구 검색 도구
    Agent Skills
    개요빠른 시작모범 사례엔터프라이즈용 SkillsAPI로 Skills 사용
    Agent SDK
    개요빠른 시작TypeScript SDKTypeScript V2 (미리보기)Python SDK마이그레이션 가이드
    스트리밍 입력실시간 응답 스트리밍중지 사유 처리권한 처리사용자 승인 및 입력훅으로 실행 제어세션 관리파일 체크포인팅SDK에서 구조화된 출력Agent SDK 호스팅AI 에이전트 안전한 배포시스템 프롬프트 수정SDK에서 MCP커스텀 도구SDK에서 서브에이전트SDK에서 슬래시 명령어SDK에서 Agent Skills비용 및 사용량 추적할 일 목록SDK에서 플러그인
    API에서 MCP
    MCP 커넥터원격 MCP 서버
    서드파티 플랫폼의 Claude
    Amazon BedrockMicrosoft FoundryVertex AI
    프롬프트 엔지니어링
    개요프롬프트 생성기프롬프트 템플릿 사용프롬프트 개선기명확하고 직접적으로 작성예시 사용 (멀티샷 프롬프팅)Claude에게 생각하게 하기 (CoT)XML 태그 사용Claude에게 역할 부여 (시스템 프롬프트)복잡한 프롬프트 연결긴 컨텍스트 팁확장 사고 팁
    테스트 및 평가
    성공 기준 정의테스트 케이스 개발평가 도구 사용지연 시간 줄이기
    가드레일 강화
    환각 줄이기출력 일관성 높이기탈옥 방지스트리밍 거부프롬프트 유출 줄이기Claude 캐릭터 유지
    관리 및 모니터링
    Admin API 개요데이터 상주워크스페이스사용량 및 비용 APIClaude Code Analytics API제로 데이터 보존
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    가이드

    SDK에서의 슬래시 명령어

    SDK를 통해 Claude Code 세션을 제어하기 위한 슬래시 명령어 사용 방법을 알아보세요

    슬래시 명령어는 /로 시작하는 특수 명령어를 사용하여 Claude Code 세션을 제어하는 방법을 제공합니다. 이러한 명령어는 SDK를 통해 전송하여 대화 기록 지우기, 메시지 압축, 도움말 가져오기 등의 작업을 수행할 수 있습니다.

    사용 가능한 슬래시 명령어 확인하기

    Claude Agent SDK는 시스템 초기화 메시지에서 사용 가능한 슬래시 명령어에 대한 정보를 제공합니다. 세션이 시작될 때 이 정보에 접근하세요:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    for await (const message of query({
      prompt: "Hello Claude",
      options: { maxTurns: 1 }
    })) {
      if (message.type === "system" && message.subtype === "init") {
        console.log("Available slash commands:", message.slash_commands);
        // 출력 예시: ["/compact", "/clear", "/help"]
      }
    }

    슬래시 명령어 보내기

    일반 텍스트처럼 프롬프트 문자열에 포함하여 슬래시 명령어를 보내세요:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    // 슬래시 명령어 보내기
    for await (const message of query({
      prompt: "/compact",
      options: { maxTurns: 1 }
    })) {
      if (message.type === "result") {
        console.log("Command executed:", message.result);
      }
    }

    일반적인 슬래시 명령어

    /compact - 대화 기록 압축

    /compact 명령어는 중요한 컨텍스트를 보존하면서 이전 메시지를 요약하여 대화 기록의 크기를 줄입니다:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    for await (const message of query({
      prompt: "/compact",
      options: { maxTurns: 1 }
    })) {
      if (message.type === "system" && message.subtype === "compact_boundary") {
        console.log("Compaction completed");
        console.log("Pre-compaction tokens:", message.compact_metadata.pre_tokens);
        console.log("Trigger:", message.compact_metadata.trigger);
      }
    }

    /clear - 대화 지우기

    /clear 명령어는 이전 기록을 모두 지우고 새로운 대화를 시작합니다:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    // 대화를 지우고 새로 시작
    for await (const message of query({
      prompt: "/clear",
      options: { maxTurns: 1 }
    })) {
      if (message.type === "system" && message.subtype === "init") {
        console.log("Conversation cleared, new session started");
        console.log("Session ID:", message.session_id);
      }
    }

    커스텀 슬래시 명령어 만들기

    내장 슬래시 명령어를 사용하는 것 외에도, SDK를 통해 사용할 수 있는 자체 커스텀 명령어를 만들 수 있습니다. 커스텀 명령어는 서브에이전트를 구성하는 방식과 유사하게 특정 디렉토리에 마크다운 파일로 정의됩니다.

    파일 위치

    커스텀 슬래시 명령어는 범위에 따라 지정된 디렉토리에 저장됩니다:

    • 프로젝트 명령어: .claude/commands/ - 현재 프로젝트에서만 사용 가능
    • 개인 명령어: ~/.claude/commands/ - 모든 프로젝트에서 사용 가능

    파일 형식

    각 커스텀 명령어는 마크다운 파일이며:

    • 파일명(.md 확장자 제외)이 명령어 이름이 됩니다
    • 파일 내용이 명령어의 동작을 정의합니다
    • 선택적 YAML 프론트매터가 구성을 제공합니다

    기본 예시

    .claude/commands/refactor.md를 생성합니다:

    Refactor the selected code to improve readability and maintainability.
    Focus on clean code principles and best practices.

    이렇게 하면 SDK를 통해 사용할 수 있는 /refactor 명령어가 생성됩니다.

    프론트매터 포함

    .claude/commands/security-check.md를 생성합니다:

    ---
    allowed-tools: Read, Grep, Glob
    description: Run security vulnerability scan
    model: claude-opus-4-6
    ---
    
    Analyze the codebase for security vulnerabilities including:
    - SQL injection risks
    - XSS vulnerabilities
    - Exposed credentials
    - Insecure configurations

    SDK에서 커스텀 명령어 사용하기

    파일 시스템에 정의되면 커스텀 명령어는 SDK를 통해 자동으로 사용할 수 있습니다:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    // 커스텀 명령어 사용
    for await (const message of query({
      prompt: "/refactor src/auth/login.ts",
      options: { maxTurns: 3 }
    })) {
      if (message.type === "assistant") {
        console.log("Refactoring suggestions:", message.message);
      }
    }
    
    // 커스텀 명령어는 slash_commands 목록에 나타남
    for await (const message of query({
      prompt: "Hello",
      options: { maxTurns: 1 }
    })) {
      if (message.type === "system" && message.subtype === "init") {
        // 내장 명령어와 커스텀 명령어 모두 포함됨
        console.log("Available commands:", message.slash_commands);
        // 예시: ["/compact", "/clear", "/help", "/refactor", "/security-check"]
      }
    }

    고급 기능

    인수와 플레이스홀더

    커스텀 명령어는 플레이스홀더를 사용하여 동적 인수를 지원합니다:

    .claude/commands/fix-issue.md를 생성합니다:

    ---
    argument-hint: [issue-number] [priority]
    description: Fix a GitHub issue
    ---
    
    Fix issue #$1 with priority $2.
    Check the issue description and implement the necessary changes.

    SDK에서 사용:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    // 커스텀 명령어에 인수 전달
    for await (const message of query({
      prompt: "/fix-issue 123 high",
      options: { maxTurns: 5 }
    })) {
      // 명령어는 $1="123"과 $2="high"로 처리됨
      if (message.type === "result") {
        console.log("Issue fixed:", message.result);
      }
    }

    Bash 명령어 실행

    커스텀 명령어는 bash 명령어를 실행하고 그 출력을 포함할 수 있습니다:

    .claude/commands/git-commit.md를 생성합니다:

    ---
    allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
    description: Create a git commit
    ---
    
    ## Context
    
    - Current status: !`git status`
    - Current diff: !`git diff HEAD`
    
    ## Task
    
    Create a git commit with appropriate message based on the changes.

    파일 참조

    @ 접두사를 사용하여 파일 내용을 포함합니다:

    .claude/commands/review-config.md를 생성합니다:

    ---
    description: Review configuration files
    ---
    
    Review the following configuration files for issues:
    - Package config: @package.json
    - TypeScript config: @tsconfig.json
    - Environment config: @.env
    
    Check for security issues, outdated dependencies, and misconfigurations.

    네임스페이스를 활용한 구성

    더 나은 구조를 위해 하위 디렉토리에 명령어를 구성합니다:

    .claude/commands/
    ├── frontend/
    │   ├── component.md      # /component 생성 (project:frontend)
    │   └── style-check.md     # /style-check 생성 (project:frontend)
    ├── backend/
    │   ├── api-test.md        # /api-test 생성 (project:backend)
    │   └── db-migrate.md      # /db-migrate 생성 (project:backend)
    └── review.md              # /review 생성 (project)

    하위 디렉토리는 명령어 설명에 나타나지만 명령어 이름 자체에는 영향을 미치지 않습니다.

    실용적인 예시

    코드 리뷰 명령어

    .claude/commands/code-review.md를 생성합니다:

    ---
    allowed-tools: Read, Grep, Glob, Bash(git diff:*)
    description: Comprehensive code review
    ---
    
    ## Changed Files
    !`git diff --name-only HEAD~1`
    
    ## Detailed Changes
    !`git diff HEAD~1`
    
    ## Review Checklist
    
    Review the above changes for:
    1. Code quality and readability
    2. Security vulnerabilities
    3. Performance implications
    4. Test coverage
    5. Documentation completeness
    
    Provide specific, actionable feedback organized by priority.

    테스트 실행 명령어

    .claude/commands/test.md를 생성합니다:

    ---
    allowed-tools: Bash, Read, Edit
    argument-hint: [test-pattern]
    description: Run tests with optional pattern
    ---
    
    Run tests matching pattern: $ARGUMENTS
    
    1. Detect the test framework (Jest, pytest, etc.)
    2. Run tests with the provided pattern
    3. If tests fail, analyze and fix them
    4. Re-run to verify fixes

    SDK를 통해 이러한 명령어를 사용합니다:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    // 코드 리뷰 실행
    for await (const message of query({
      prompt: "/code-review",
      options: { maxTurns: 3 }
    })) {
      // 리뷰 피드백 처리
    }
    
    // 특정 테스트 실행
    for await (const message of query({
      prompt: "/test auth",
      options: { maxTurns: 5 }
    })) {
      // 테스트 결과 처리
    }

    참고 자료

    • 슬래시 명령어 - 슬래시 명령어 전체 문서
    • SDK에서의 서브에이전트 - 서브에이전트를 위한 유사한 파일 시스템 기반 구성
    • TypeScript SDK 레퍼런스 - 전체 API 문서
    • SDK 개요 - 일반적인 SDK 개념
    • CLI 레퍼런스 - 명령줄 인터페이스

    Was this page helpful?

    • /compact - 대화 기록 압축
    • /clear - 대화 지우기
    • SDK에서 커스텀 명령어 사용하기