[
    {
        "role": "user",
        "content": "using%20github%20copilot%20cli%2C%20it%20doesn%27t%20look%20like%20we%20can%20pass%20standard%20input%20to%20it%2C%20i.e.%20copilot%20%3C%20input.txt%20-%20how%20to%20overcome%20this%3F"
    },
    {
        "role": "assistant",
        "content": "You're right: you can't do exactly `copilot < input.txt` to feed standard input the way many UNIX tools accept stdin. The GitHub Copilot CLI supports different modes to get input\u2014like prompts via `-p`/`--prompt` or piped input\u2014but it doesn\u2019t treat input from stdin as a \u201cfile\u201d to operate on directly the way shell redirection would.  \n\nHere are ways to work around that limitation, plus what the docs say and how to use them effectively.\n\n---\n\n### What the docs say\n\n- The CLI supports **programmatic use**: you can pass a prompt via `-p` / `--prompt` and have it complete and exit. ([docs.github.com](https://docs.github.com/en/copilot/how-tos/copilot-cli/automate-copilot-cli/run-cli-programmatically?utm_source=openai))  \n- It also accepts **piped input**: so you can do something like:\n\n  ```\n  echo \"Explain this file: ./complex.ts\" | copilot\n  ```\n\n  ([docs.github.com](https://docs.github.com/en/copilot/how-tos/copilot-cli/automate-copilot-cli/run-cli-programmatically?utm_source=openai))  \n- But note: piped input is ignored if you also supply `--prompt`. ([docs.github.com](https://docs.github.com/en/copilot/how-tos/copilot-cli/automate-copilot-cli/run-cli-programmatically?utm_source=openai))  \n\n---\n\n### Why `copilot < input.txt` doesn\u2019t work as expected\n\nBecause Copilot CLI doesn\u2019t read raw stdin as a content source to parse and operate upon (in \"file-processing\" mode). It interprets stdin only in the sense of a prompt: it reads it (if `--prompt` is *not* provided) as text to use as the task / query. But it doesn\u2019t, for example, read file content via redirection and then modify it or operate on it with tools\u2014it isn't wired for that model yet.  \n\n---\n\n### Workarounds\n\nHere are some ways to simulate feeding input from a file:\n\n1. **Use pipe instead of `<`**\n\n   ```\n   cat input.txt | copilot\n   ```\n\n   This works like piped input. Whatever\u2019s in `input.txt` becomes the prompt to Copilot. Good if you want to run a single request based on file content.  \n\n2. **Wrap in echo or here-doc**\n\n   If the file is multiline or has special formatting, a here-doc can help:\n\n   ```\n   copilot <<EOF\n   $(cat input.txt)\n   EOF\n   ```\n\n   Or:\n\n   ```\n   copilot <<EOF\n   <paste the text of input.txt>\n   EOF\n   ```\n\n3. **Read file contents into `--prompt`**\n\n   Especially in scripts, you can do:\n\n   ```bash\n   prompt_text=$(<input.txt)\n   copilot -p \"$prompt_text\"\n   ```\n\n   This captures file content into a shell variable, then passes it as `--prompt`.  \n\n4. **Script wrapper**\n\n   For more complex workflows, write a small shell script:\n\n   ```bash\n   #!/bin/bash\n   prompt=$(cat \"$1\")\n   copilot -p \"$prompt\" \"${@:2}\"\n   ```\n\n   Save this as, say, `cop-run`, make it executable (`chmod +x cop-run`), then:\n\n   ```\n   ./cop-run input.txt --allow-tool='shell(...)'\n   ```\n\n   This lets you pass additional CLI args after the filename.\n\n---\n\n### Things to watch out for\n\n- If you use both piped input and `--prompt`, `--prompt` takes precedence. Pipe will be ignored. ([docs.github.com](https://docs.github.com/en/copilot/how-tos/copilot-cli/automate-copilot-cli/run-cli-programmatically?utm_source=openai))  \n- Multiline prompts may need proper quoting or escaping in shell.  \n- Copilot may request approvals when using tools or modifying files. If you're using the CLI non-interactively, you may need flags like `--allow-tool` or `--allow-all-tools` to prevent it from stopping for manual approvals. ([docs.github.com](https://docs.github.com/en/copilot/concepts/agents/copilot-cli/about-copilot-cli?utm_source=openai))  \n\n---\n\nLet me know your goal: are you trying to:\n\n- feed in code and have Copilot review it?\n- pass a large prompt from a file?\n- apply patch-like transformations?\n\nIf you tell me the use-case, I can suggest a script or command exactly suited to that."
    }
]