[
    {
        "role": "user",
        "content": "when%20using%20the%20copilot%20cli%20in%20windows%2C%20how%20do%20I%20pass%20in%20a%20prompt%20from%20a%20text%20file%3F%20copilot%20%3C%20prompt.txt%20does%20not%20seem%20to%20work"
    },
    {
        "role": "assistant",
        "content": "If you're trying to use GitHub Copilot CLI on Windows and pass in a prompt via a text file like this:\n\n```\ncopilot < prompt.txt\n```\n\n\u2026it won\u2019t work as expected because Copilot CLI doesn\u2019t accept redirected stdin input as its prompt. Instead, you need to use its dedicated command-line option to supply the prompt, or programmatically pass the contents of the file. Here\u2019s how:\n\n---\n\n### \ud83d\udd27 Correct ways to pass a prompt from a text file to Copilot CLI\n\n#### 1. Use the `-p` / `--prompt` flag\n\nYou can pass the prompt explicitly as a string using the `-p` or `--prompt` option. For example:\n\n```powershell\ncopilot -p \"This is my prompt...\"\n```\n\nTo use content from a file, you could read it in and pass it, something like:\n\n```powershell\n$promptText = Get-Content prompt.txt -Raw\ncopilot -p $promptText\n```\n\nThis reads the whole file into a string, then supplies it via `-p`. Docs confirm that the CLI supports this mode on Windows (PowerShell or WSL). ([docs.github.com](https://docs.github.com/en/copilot/concepts/agents/about-copilot-cli?utm_source=openai))\n\n---\n\n#### 2. Piping command-line options via a script\n\nAnother documented method is using a script to output options (including the prompt) and pipe that into `copilot`. For example (in Bash/WSL or any POSIX shell):\n\n```bash\necho '--prompt This is my prompt' | copilot\n```\n\nOr better, echo the entire command:\n\n```bash\ncat prompt.txt | (while read line; do printf -- \"-p \\\"%s\\\"\\n\" \"$line\"; done) | copilot\n```\n\nHowever, in Windows PowerShell or CMD, creating echoed or piped commands like this can get tricky because of quoting and special characters. Docs caution that in PowerShell, embedding quotes or newlines in a prompt can break things. ([naonao-na.com](https://naonao-na.com/en/posts/github-copilot-cli-call-from-subprocess/?utm_source=openai))\n\n---\n\n### \u26a0\ufe0f PowerShell quoting and redirection issues\n\nSince PowerShell is strict about quotes, special characters, and redirection, preserving the prompt content exactly (especially when it includes `\"` or newlines) often breaks. One workaround is to use PowerShell\u2019s `param` approach when automating:\n\n```powershell\npowershell.exe -NoProfile -NonInteractive -Command {\n  param($p)\n  copilot -p $p --allow-all-tools\n} -- $(Get-Content prompt.txt -Raw)\n```\n\nThis lets PowerShell pass the content in without you having to escape everything manually. Docs discussing automation point out that automation on Windows should use this kind of approach to avoid quoting issues. ([naonao-na.com](https://naonao-na.com/en/posts/github-copilot-cli-call-from-subprocess/?utm_source=openai))\n\n---\n\n### \u2705 TL;DR / Quick Steps\n\n- Don\u2019t use `copilot < prompt.txt` \u2014 that stdin redirection won't supply the prompt to Copilot.\n- Use `-p` or `--prompt`: either paste the prompt directly (`-p \"...\"`) or read it from file and supply the string.\n- If automating in PowerShell, use `Get-Content` to read the file (`-Raw` to preserve newlines), and pass into `-p`.\n- For complex content with special characters, embed via PowerShell `param` or other mechanism to avoid quoting messes.  \n\n---\n\nIf you like, I can show you exactly how this would look in cmd.exe, PowerShell, or WSL based on what you're using \u2014 want me to tailor those?"
    }
]