{"meta":{"title":"프로그래밍 방식으로 실행 GitHub Copilot CLI","intro":"Copilot CLI을(를) 터미널, 스크립트 또는 작업 워크플로에서 사용합니다.","product":"GitHub Copilot","breadcrumbs":[{"href":"/ko/copilot","title":"GitHub Copilot"},{"href":"/ko/copilot/how-tos","title":"방법"},{"href":"/ko/copilot/how-tos/copilot-cli","title":"Copilot CLI"},{"href":"/ko/copilot/how-tos/copilot-cli/automate-copilot-cli","title":"Copilot CLI를 사용하여 자동화"},{"href":"/ko/copilot/how-tos/copilot-cli/automate-copilot-cli/run-cli-programmatically","title":"프로그래밍 방식으로 CLI 실행"}],"documentType":"article"},"body":"# 프로그래밍 방식으로 실행 GitHub Copilot CLI\n\nCopilot CLI을(를) 터미널, 스크립트 또는 작업 워크플로에서 사용합니다.\n\n## 소개\n\n대화형 세션을 입력하지 않고 단일 명령으로 직접 Copilot CLI 프롬프트를 전달할 수 있습니다. 이렇게 하면 터미널에서 직접 사용할 Copilot 수 있지만 스크립트, CI/CD 파이프라인 및 자동화 워크플로에서 프로그래밍 방식으로 CLI를 사용할 수도 있습니다.\n\n프로그래밍 방식으로 사용 Copilot CLI 하려면 다음 중 하나를 수행할 수 있습니다.\n\n* `copilot` 명령과 `-p` 또는 `--prompt` 명령줄 옵션을 사용한 후 프롬프트를 입력하세요.\n\n  ```shell copy\n  copilot -p \"Explain this file: ./complex.ts\"\n  ```\n\n* `copilot` 명령에 프롬프트를 파이프합니다.\n\n  ```shell copy\n  echo \"Explain this file: ./complex.ts\" | copilot\n  ```\n\n  > \\[!NOTE]\n  > 프롬프트나 `-p` 또는 `--prompt` 옵션이 제공되면 파이프 입력은 처리되지 않습니다.\n\n## 프로그램을 프로그래밍 방식으로 사용하기 위한 팁Copilot CLI\n\n* **정확한 프롬프트를 제공합니다.** 명확하고 명확한 지침은 모호한 요청보다 더 나은 결과를 생성합니다. 파일 이름, 함수 이름, 정확한 변경과 같은 컨텍스트를 더 많이 제공할수록 추측 Copilot 이 줄어듭니다.\n* **프롬프트를 신중하게 따옴표 처리하기** - 셸에서 특수 문자가 해석되지 않도록 하려면 프롬프트를 작은따옴표로 사용하면 됩니다.\n* **항상 최소한의 사용 권한을 부여합니다**. 명령 `--allow-tool=[TOOLS...]` 줄 옵션을 사용하여 `--allow-url=[URLs...]` 작업을 완료하는 데 필요한 도구와 액세스 권한만 사용할 수 있는 권한을 부여 Copilot 합니다. 샌드박스 환경에서 작업하지 않는 한 지나치게 허용되는 옵션(예: `--allow-all`)을 사용하지 마세요. 자세한 내용은 [클라우드 및 로컬 샌드박스 정보 GitHub Copilot](/ko/copilot/concepts/about-cloud-and-local-sandboxes)을(를) 참조하세요.\n* 출력을 캡처할 때 **(자동)를 사용합니다`-s`**. 이렇게 하면 세션 메타데이터가 표시되지 않으므로 텍스트가 정리됩니다.\n* **사용 `--no-ask-user`** 에이전트가 명확한 질문을 하지 못하도록 합니다.\n* 환경 전체에서 일관된 동작을 위해 명시적으로 \\*\\*\\*\\*`--model`.\n\n프로그래밍 방식으로 실행할 [](/ko/copilot/reference/copilot-cli-reference/cli-programmatic-reference) 때 특히 유용한 옵션은 Copilot CLI을 참조하세요.\n\n## CI/CD 통합\n\n프로그래밍 방식으로 실행하는 Copilot CLI 일반적인 사용 사례는 CI/CD 워크플로 단계에 CLI 명령을 포함하는 것입니다.\n\n본 GitHub Actions 워크플로 발췌는 Copilot CLI 명령을 실행하는 간단한 예시를 보여줍니다.\n\n```yaml\n# Workflow step using Copilot CLI\n- name: Generate test coverage report\n  env:\n    COPILOT_GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}\n  run: |\n    copilot -p \"Run the test suite and produce a coverage summary\" \\\n      -s --allow-tool='shell(npm:*), write' --no-ask-user\n```\n\n자세한 내용은 [Copilot CLI 및 GitHub Actions 사용하여 작업 자동화](/ko/copilot/how-tos/copilot-cli/automate-copilot-cli/automate-with-actions)을(를) 참조하세요.\n\n## 프로그래밍 방식 사용의 예\n\n### 커밋 메시지 생성\n\n```bash copy\ncopilot -p 'Write a commit message in plain text for the staged changes' -s \\\n  --allow-tool='shell(git:*)'\n```\n\n### 파일 요약\n\n```bash copy\ncopilot -p 'Summarize what src/auth/login.ts does in no more than 100 words' -s\n```\n\n### 모듈에 대한 테스트 작성\n\n```bash copy\ncopilot -p 'Write unit tests for src/utils/validators.ts' \\\n  --allow-tool='write, shell(npm:*), shell(npx:*)'\n```\n\n### lint 오류 수정\n\n```bash copy\ncopilot -p 'Fix all ESLint errors in this project' \\\n  --allow-tool='write, shell(npm:*), shell(npx:*), shell(git:*)'\n```\n\n### 차이 설명\n\n```bash copy\ncopilot -p 'Explain the changes in the latest commit on this branch and flag any potential issues' -s\n```\n\n### 분기를 검토하는 코드\n\n슬래시 명령을 사용하여 `/review` 기본 제공 `code-review` 에이전트가 현재 분기의 코드 변경 내용을 검토하도록 합니다.\n\n```bash copy\ncopilot -p '/review the changes on this branch compared to main. Focus on bugs and security issues.' \\\n  -s --allow-tool='shell(git:*)'\n```\n\n### 설명서 생성\n\n```bash copy\ncopilot -p 'Generate JSDoc comments for all exported functions in src/api/' \\\n  --allow-tool=write\n```\n\n### 세션 내보내기\n\n전체 세션 기록을 로컬 파일 시스템의 Markdown 파일에 저장합니다.\n\n```bash copy\ncopilot -p \"Audit this project's dependencies for vulnerabilities\" \\\n  --allow-tool='shell(npm:*), shell(npx:*)' \\\n  --share='./audit-report.md'\n```\n\n쉽게 공유할 수 있도록 세션 대본을 GitHub.com에서 Gist에 저장합니다.\n\n```bash copy\ncopilot -p 'Summarize the architecture of this project' --share-gist\n```\n\n> \\[!NOTE]\n> Gists는 Enterprise Managed Users사용자가 사용할 수 없으며, 데이터 레지던시(\\*.ghe.com)가 적용된 GitHub Enterprise Cloud를 사용하는 경우에도 이용할 수 없습니다.\n\n## 셸 스크립팅 패턴\n\n### Copilot의 출력을 변수에 캡처하세요\n\n```bash copy\nresult=$(copilot -p 'What version of Node.js does this project require? \\\n  Give the number only. No other text.' -s)\necho \"Required Node version: $result\"\n```\n\n### 조건부에서 사용\n\n```bash copy\nif copilot -p 'Does this project have any TypeScript errors? Reply only YES or NO.' -s \\\n  | grep -qi \"no\"; then\n  echo \"No type errors found.\"\nelse\n  echo \"Type errors detected.\"\nfi\n```\n\n### 여러 파일 처리\n\n```bash copy\nfor file in src/api/*.ts; do\n  echo \"--- Reviewing $file ---\" | tee -a review-results.md\n  copilot -p \"Review $file for error handling issues\" -s --allow-all-tools | tee -a review-results.md\ndone\n```\n\n## 추가 읽기\n\n* [GitHub Copilot CLI](/ko/copilot/how-tos/copilot-cli)\n* [GitHub Copilot CLI 프로그래밍 방식 참조](/ko/copilot/reference/copilot-cli-reference/cli-programmatic-reference)\n* [GitHub Copilot CLI 명령 참조](/ko/copilot/reference/copilot-cli-reference/cli-command-reference#command-line-options)"}