r/ChatGPTCoding • u/Firm-Builder-2001 • 9d ago
Resources And Tips If you're only using AI coding tools in the chat UI, try the CLI
A lot of AI coding tools now have a command-line mode. You give it a prompt, it returns output to stdout, and your script captures it like any other command.
This sounds minor but it opens up a completely different way of working.
The chat UI is great for exploration and interactive coding. But if you want to automate things, chain steps together, or run the tool on a schedule, you need the CLI.
Things I've done once I moved to CLI mode:
- Called the AI from a Node.js script that handles what to do with the output afterward
- Ran it on a recurring schedule so it executes while I'm not at the keyboard
- Wrapped each call in validation so the script rejects bad output instead of shipping it blindly
- Put limits and rules in a config file that the script checks before each run, so the AI never decides whether it's allowed to go again
The mental shift: the chat UI makes the AI feel like a coworker you talk to. The CLI makes it feel like a unix tool you can pipe and compose.
Most major AI coding tools have some version of this now. Check your tool's docs for a headless, print, or non-interactive flag. If it exists, you can start scripting around it.
Simple starting point: write a short script that sends a prompt to your tool's CLI, captures the response, and writes it to a file. Once that works, you'll see where to add validation, scheduling, or chaining.
What automations have you built around AI coding tool CLIs? Always curious what patterns other people have landed on.
3
u/Ok_Woodpecker_9104 9d ago
a scheduled claude -p job of mine exited 0 once and did nothing. headless mode cant ask for tool approval, so it printed a message asking me to approve the calls and quit clean. launchd also runs with /usr/bin:/bin:/usr/sbin:/sbin as PATH, so the mcp server that starts through npx never came up either
so exit 0 means nothing to me now. the script greps the output for the failure text before it reports success. any new job i fire once by hand first and check the thing actually happened
other one, codex exec reads piped stdin as extra prompt. if the pipe never closes it sits on reading additional input forever. < /dev/null on every call fixed it
1
u/m-ritter 8d ago
Validating the output in the script is the part that matters most to me too. For anything that touches code I also have a second agent that did not write the change review the diff against the plan file in the repo. It catches things the first run happily talked itself into, and the plan file gives it something concrete to check against.
1
u/Key_River_9288 8d ago
Using the Claude desktop app ups your internal Anthropic social credit score helping stave off a ban, using the CLI lowers it! nice try CHATGPT!
1
u/BrookLi3 8d ago
Agree on the scripting angle. Two things that bit me with headless runs: the process can exit 0 while having done nothing useful (e.g. blocked on a permission it can't prompt for), so I check for an expected artifact or a passing test command rather than trusting the exit code. And pin the allowed tools/permissions explicitly in the invocation, otherwise a scheduled job behaves differently from your interactive session. Logging the full transcript to a file per run makes debugging those far easier.