12 Claude Code and Codex CLI Flags for Running AI Agents From Scripts on Your Mac (2026)
If your agent scripts still pass --full-auto to codex exec, they're out of date. OpenAI's non-interactive mode docs now say the flag is no longer supported. Both big coding agents have quietly grown a solid set of flags
If your agent scripts still pass --full-auto to codex exec, they're out of date. OpenAI's non-interactive mode docs now say the flag is no longer supported.
Both big coding agents have quietly grown a solid set of flags for running without a chat window: in a shell alias, a git hook, a cron job or CI. Here are the 12 I'd learn first, all checked against the official docs this month.
Claude Code
1. claude -p for one-shot answers
Print mode runs a single query and exits, and it reads piped input. cat logs.txt | claude -p "explain" is the whole trick, and it's the base for everything below. Details in the CLI reference.
2. --output-format json and --json-schema
--output-format accepts text, json or stream-json in print mode. Add --json-schema with a JSON Schema and you get validated output that matches it, so the next step in your script can parse fields instead of scraping prose.
3. --max-turns and --max-budget-usd
There's no turn limit by default. claude -p --max-turns 3 "query" caps how long an unattended run can wander, and --max-budget-usd stops it once estimated API spend hits your number. The docs warn spend can pass the cap, so leave headroom.
4. --allowedTools with narrow patterns
Pre-approve only what the job needs, like --allowedTools "Bash(git log *)" "Bash(git diff *)" "Read". A script that only reads history never gets to run anything else without asking.
5. -n to name a session, -r to come back to it
claude -n "auth-refactor" names the session, and claude -r "auth-refactor" "Finish this PR" resumes it by name later. claude -c picks up the most recent conversation in the current directory if you forgot to name it.
6. -w for a throwaway worktree
claude -w feature-auth starts Claude in an isolated git worktree under .claude/worktrees/, so an experiment never touches your main checkout. You can also pass a GitHub PR URL to branch the worktree from that PR.
7. --bare for faster scripted calls
claude --bare -p "query" skips auto-discovery of hooks, skills, plugins, MCP servers and CLAUDE.md. Useful when a script fires dozens of small calls and doesn't need your whole setup loaded each time.
Codex CLI
8. codex exec prints only the final answer
Progress streams to stderr and only the final agent message goes to stdout. That makes codex exec "generate release notes for the last 10 commits" | tee release-notes.md work cleanly, and on a Mac you can end the pipe in pbcopy instead.
9. --sandbox workspace-write instead of --full-auto
codex exec runs in a read-only sandbox by default. Use --sandbox workspace-write when the job should edit files, and save danger-full-access for an isolated runner or container, as the docs recommend.
10. --json, -o and --output-schema
--json turns stdout into a JSON Lines stream of events like turn.completed, which includes token counts. -o result.md writes just the final message to a file, and --output-schema ./schema.json asks for a final response that matches your schema.
11. codex exec resume --last
Two-stage pipelines get easy: codex exec "review the change for race conditions", then codex exec resume --last "fix the race conditions you found". It reuses the session's working directory and sandbox settings. Add --ephemeral to runs you don't want saved to disk.
Before you schedule any of it
12. TokenBar
A codex exec script signed in with your ChatGPT plan instead of an API key counts against the same plan limits as your interactive sessions, so a batch job can eat the window you planned to code in. TokenBar is a Mac menu bar app that shows usage and reset times for Claude, Codex, Cursor, Gemini and Copilot, so I check it before kicking off a long run. It doesn't add any quota.
It's built on Peter Steinberger's MIT-licensed CodexBar and credits Pixel Agents. $5/month Basic or $15 lifetime Pro, macOS 14+.
Cheat sheet
| Job | Claude Code | Codex CLI |
|---|---|---|
| One-shot, piped input | claude -p |
codex exec |
| Machine-readable output | --output-format json |
--json |
| Output that matches a schema | --json-schema |
--output-schema |
| Keep a run on a leash |
--max-turns, --allowedTools
|
--sandbox (read-only default) |
| Pick up where it stopped |
-r <name>, -c
|
exec resume --last |
Flags change fast in both tools, so run claude --help or codex exec --help before you wire one into CI.
Which of these are already in your shell aliases, and which flag do you wish existed?
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.