Loading...
    • 개발자 가이드
    • API 참고자료
    • MCP
    • 리소스
    • 릴리스 노트
    Search...
    ⌘K

    첫 번째 단계

    Claude 소개빠른 시작

    모델 및 가격

    모델 개요모델 선택하기Claude 4.5의 새로운 기능Claude 4.5로 마이그레이션모델 지원 중단가격 정책

    Claude로 빌드하기

    기능 개요Messages API 작업컨텍스트 윈도우프롬프트 작성 모범 사례

    기능

    프롬프트 캐싱컨텍스트 편집확장된 사고스트리밍 메시지배치 처리인용다국어 지원토큰 카운팅임베딩비전PDF 지원Files API검색 결과Google Sheets 애드온

    도구

    개요도구 사용을 구현하는 방법토큰 효율적인 도구 사용세밀한 도구 스트리밍Bash 도구코드 실행 도구컴퓨터 사용 도구텍스트 편집기 도구웹 페치 도구웹 검색 도구메모리 도구

    에이전트 스킬

    개요빠른 시작Skill 작성 모범 사례Skills 사용하기

    Agent SDK

    개요Agent SDK 참조 - TypeScriptPython SDK

    가이드

    스트리밍 입력권한 처리세션 관리Agent SDK 호스팅시스템 프롬프트 수정하기SDK에서의 MCP사용자 정의 도구SDK의 서브에이전트SDK의 슬래시 명령어SDK의 에이전트 스킬비용 및 사용량 추적할 일 목록SDK의 플러그인

    API의 MCP

    MCP 커넥터원격 MCP 서버

    타사 플랫폼의 Claude

    Amazon BedrockVertex AI

    프롬프트 엔지니어링

    개요프롬프트 생성기프롬프트 템플릿 사용하기프롬프트 개선기명확하고 직접적으로예시(멀티샷 프롬프팅) 사용Claude가 생각하도록 하기(CoT)XML 태그 사용Claude에게 역할 부여하기 (시스템 프롬프트)Claude의 응답 미리 채우기복잡한 프롬프트 체이닝긴 컨텍스트 팁확장 사고 팁

    테스트 및 평가

    성공 기준 정의하기테스트 케이스 개발평가 도구 사용하기지연 시간 줄이기

    보안 강화

    환각 현상 줄이기출력 일관성 높이기탈옥 완화handle-streaming-refusals프롬프트 유출 감소Claude의 캐릭터 유지

    관리 및 모니터링

    Admin API 개요사용량 및 비용 APIClaude Code Analytics API
    Console
    도구

    Bash 도구

    bash 도구를 사용하여 Claude가 지속적인 bash 세션에서 셸 명령을 실행하고 시스템 작업, 스크립트 실행 및 명령줄 자동화를 수행할 수 있습니다.

    bash 도구를 사용하면 Claude가 지속적인 bash 세션에서 셸 명령을 실행할 수 있으므로 시스템 작업, 스크립트 실행 및 명령줄 자동화가 가능합니다.

    개요

    bash 도구는 Claude에게 다음을 제공합니다:

    • 상태를 유지하는 지속적인 bash 세션
    • 모든 셸 명령 실행 능력
    • 환경 변수 및 작업 디렉토리에 대한 액세스
    • 명령 체이닝 및 스크립팅 기능

    모델 호환성

    모델도구 버전
    Claude 4 모델 및 Sonnet 3.7 (지원 중단)bash_20250124

    이전 도구 버전은 최신 모델과의 하위 호환성이 보장되지 않습니다. 항상 모델 버전에 해당하는 도구 버전을 사용하세요.

    사용 사례

    • 개발 워크플로우: 빌드 명령, 테스트 및 개발 도구 실행
    • 시스템 자동화: 스크립트 실행, 파일 관리, 작업 자동화
    • 데이터 처리: 파일 처리, 분석 스크립트 실행, 데이터세트 관리
    • 환경 설정: 패키지 설치, 환경 구성

    빠른 시작

    Python
    import anthropic
    
    client = anthropic.Anthropic()
    
    response = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        tools=[
            {
                "type": "bash_20250124",
                "name": "bash"
            }
        ],
        messages=[
            {"role": "user", "content": "현재 디렉토리의 모든 Python 파일을 나열하세요."}
        ]
    )
    Shell
    curl https://api.anthropic.com/v1/messages \
      -H "content-type: application/json" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -d '{
        "model": "claude-sonnet-4-5",
        "max_tokens": 1024,
        "tools": [
          {
            "type": "bash_20250124",
            "name": "bash"
          }
        ],
        "messages": [
          {
            "role": "user",
            "content": "현재 디렉토리의 모든 Python 파일을 나열하세요."
          }
        ]
      }'

    작동 방식

    bash 도구는 지속적인 세션을 유지합니다:

    1. Claude가 실행할 명령을 결정합니다
    2. bash 셸에서 명령을 실행합니다
    3. 출력(stdout 및 stderr)을 Claude에게 반환합니다
    4. 세션 상태는 명령 간에 유지됩니다(환경 변수, 작업 디렉토리)

    매개변수

    매개변수필수설명
    command예*실행할 bash 명령
    restart아니오bash 세션을 다시 시작하려면 true로 설정

    *restart를 사용하지 않는 한 필수

    예시: 다단계 자동화

    Claude는 명령을 연결하여 복잡한 작업을 완료할 수 있습니다:

    # 사용자 요청
    "requests 라이브러리를 설치하고 API에서 농담을 가져오는 간단한 Python 스크립트를 만든 다음 실행하세요."
    
    # Claude의 도구 사용:
    # 1. 패키지 설치
    {"command": "pip install requests"}
    
    # 2. 스크립트 생성
    {"command": "cat > fetch_joke.py << 'EOF'\nimport requests\nresponse = requests.get('https://official-joke-api.appspot.com/random_joke')\njoke = response.json()\nprint(f\"Setup: {joke['setup']}\")\nprint(f\"Punchline: {joke['punchline']}\")\nEOF"}
    
    # 3. 스크립트 실행
    {"command": "python fetch_joke.py"}

    세션은 명령 간에 상태를 유지하므로 2단계에서 생성된 파일을 3단계에서 사용할 수 있습니다.


    bash 도구 구현

    bash 도구는 스키마 없는 도구로 구현됩니다. 이 도구를 사용할 때 다른 도구처럼 입력 스키마를 제공할 필요가 없습니다. 스키마는 Claude의 모델에 내장되어 있으며 수정할 수 없습니다.

    1. 1

      bash 환경 설정

      Claude가 상호작용할 수 있는 지속적인 bash 세션을 만듭니다:

      import subprocess
      import threading
      import queue
      
      class BashSession:
          def __init__(self):
              self.process = subprocess.Popen(
                  ['/bin/bash'],
                  stdin=subprocess.PIPE,
                  stdout=subprocess.PIPE,
                  stderr=subprocess.PIPE,
                  text=True,
                  bufsize=0
              )
              self.output_queue = queue.Queue()
              self.error_queue = queue.Queue()
              self._start_readers()
    2. 2

      명령 실행 처리

      명령을 실행하고 출력을 캡처하는 함수를 만듭니다:

      def execute_command(self, command):
          # bash에 명령 전송
          self.process.stdin.write(command + '\n')
          self.process.stdin.flush()
          
          # 타임아웃으로 출력 캡처
          output = self._read_output(timeout=10)
          return output
    3. 3

      Claude의 도구 호출 처리

      Claude의 응답에서 명령을 추출하고 실행합니다:

      for content in response.content:
          if content.type == "tool_use" and content.name == "bash":
              if content.input.get("restart"):
                  bash_session.restart()
                  result = "Bash session restarted"
              else:
                  command = content.input.get("command")
                  result = bash_session.execute_command(command)
              
              # Claude에 결과 반환
              tool_result = {
                  "type": "tool_result",
                  "tool_use_id": content.id,
                  "content": result
              }
    4. 4

      안전 조치 구현

      검증 및 제한을 추가합니다:

      def validate_command(command):
          # 위험한 명령 차단
          dangerous_patterns = ['rm -rf /', 'format', ':(){:|:&};:']
          for pattern in dangerous_patterns:
              if pattern in command:
                  return False, f"Command contains dangerous pattern: {pattern}"
          
          # 필요에 따라 더 많은 검증 추가
          return True, None

    오류 처리

    bash 도구를 구현할 때 다양한 오류 시나리오를 처리합니다:

    구현 모범 사례 따르기

    보안

    bash 도구는 직접적인 시스템 액세스를 제공합니다. 다음과 같은 필수 안전 조치를 구현하세요:

    • 격리된 환경(Docker/VM)에서 실행
    • 명령 필터링 및 허용 목록 구현
    • 리소스 제한 설정(CPU, 메모리, 디스크)
    • 실행된 모든 명령 기록

    주요 권장사항

    • ulimit을 사용하여 리소스 제약 설정
    • 위험한 명령(sudo, rm -rf 등) 필터링
    • 최소 사용자 권한으로 실행
    • 모든 명령 실행 모니터링 및 기록

    가격 책정

    The bash tool adds 245 input tokens to your API calls.

    Additional tokens are consumed by:

    • Command outputs (stdout/stderr)
    • Error messages
    • Large file contents

    전체 가격 책정 세부사항은 도구 사용 가격 책정을 참조하세요.

    일반적인 패턴

    개발 워크플로우

    • 테스트 실행: pytest && coverage report
    • 프로젝트 빌드: npm install && npm run build
    • Git 작업: git status && git add . && git commit -m "message"

    파일 작업

    • 데이터 처리: wc -l *.csv && ls -lh *.csv
    • 파일 검색: find . -name "*.py" | xargs grep "pattern"
    • 백업 생성: tar -czf backup.tar.gz ./data

    시스템 작업

    • 리소스 확인: df -h && free -m
    • 프로세스 관리: ps aux | grep python
    • 환경 설정: export PATH=$PATH:/new/path && echo $PATH

    제한사항

    • 대화형 명령 없음: vim, less 또는 암호 프롬프트를 처리할 수 없음
    • GUI 애플리케이션 없음: 명령줄만 가능
    • 세션 범위: 대화 내에서 지속되며 API 호출 간에 손실됨
    • 출력 제한: 큰 출력이 잘릴 수 있음
    • 스트리밍 없음: 완료 후 결과 반환

    다른 도구와 결합

    bash 도구는 텍스트 편집기 및 기타 도구와 결합할 때 가장 강력합니다.

    다음 단계

    도구 사용 개요

    Claude와 함께 도구 사용에 대해 알아보세요

    텍스트 편집기 도구

    Claude로 텍스트 파일 보기 및 편집

    • bash 도구 구현
    © 2025 ANTHROPIC PBC

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

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

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    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

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

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

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

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

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    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

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    © 2025 ANTHROPIC PBC