⌥+⌃AltPlusCtrl

How to Attach a File in Codex CLI (@ and Tab)

Windows: @ then Tab or Enter
Mac: @ then Tab or Enter
Linux: @ then Tab or Enter
Typing @ in the Codex CLI composer opens a fuzzy search across your workspace. Keep typing to narrow the list, then press Tab or Enter to accept a match, and that file is attached to the conversation for the model to read. **Why this beats describing the path.** Telling an agent to 'look at the auth middleware' asks it to spend a turn searching, guess which of three plausible files you meant, and possibly get it wrong in a way that is not obvious until later. Attaching the file removes all of that: the contents are simply present. On a repository of any size, the difference between naming a file and attaching it is the difference between a reliable turn and a coin flip. **The search is fuzzy, which matters in practice.** You do not need the path, or even the full filename — a distinctive fragment is usually enough, and the matcher handles the gaps. `@authmid` will find `src/server/middleware/authentication.ts` without you remembering where it lives or how it was spelled. For anyone working across a codebase they did not write, this is often faster than navigating to the file in an editor to check its path first. **Attachments consume context, and large files consume a lot.** Everything attached occupies part of the context window, so pulling in a 4,000-line file to ask about one function is expensive. /status shows how much of the window is in use, and /compact reclaims some by summarising the conversation without ending the session. On a long working session, being deliberate about what gets attached is one of the more effective ways to keep responses sharp. **@ is one of three prefixes worth knowing together.** Typing ! runs the rest of the line as a shell command outside the sandbox, showing the output locally without sending it to the model — useful for checking something yourself at no context cost. Typing / opens the slash-command popup. And @ attaches a file. Three characters, three entirely different behaviours, all in the same input, which is how a terminal interface reaches the functionality a graphical one spreads across menus. **Images work alongside this.** Screenshots paste directly into the composer in terminals that support it, and the -i flag attaches them at launch. For a broken layout or an error dialog, showing the thing is faster and less lossy than describing it — and the composer's draft history, reachable with the Up arrow, restores image placeholders along with text, so a prompt you drafted with an attachment is not lost if you navigate away from it. **A related command for the same job.** /mention attaches a file through the slash-command interface rather than the @ prefix. The result is the same; the difference is only which route your fingers prefer once the popup is already open. **Directories and globs behave differently from single files.** The @ search matches files, so attaching an entire directory is not what it offers — and that constraint is doing you a favour, since a directory's worth of content would consume the context window quickly and dilute the model's attention across material that is mostly irrelevant. When the task genuinely spans many files, describing the area and letting the agent search is usually better than attaching everything, with @ reserved for the two or three files you know matter.

Related shortcuts