Your agent needs a wrapper — here's the harness pattern that makes coding agents actually ship
Your coding agent writes great code in demos. Then you put it on a real project and it dies in the first merge conflict, loses context halfway through refactoring, or ships code that breaks three other things.
The problem isn't the model. It's that you're running a powerful AI in a fragile environment without any guardrails.
Here's the wrapper pattern that fixes it:
A coding agent harness is a lightweight shell that handles session management, context preservation, and safety checks — so your agent can focus on what it does best: writing code.
Think of it like a race car driver vs. a street driver. Same engine, but one has a roll cage, fire suppression, and a pit crew. The other has airbags and hopes for the best.
The Three-Layer Harness
Layer 1 is session persistence. Your agent should never lose its place:
# Session state that survives crashes SESSION_DIR="~/.agent-sessions/$(date +%Y%m%d-%H%M%S)" echo "Working on: $PROJECT_NAME" > $SESSION_DIR/context.md echo "Last command: $LAST_CMD" > $SESSION_DIR/state.log echo "Current branch: $(git branch --show-current)" >> $SESSION_DIR/state.log
Layer 2 is safety checks. Never let your agent ship without validation:
# Pre-commit safety net
if [ "$(git diff --name-only | wc -l)" -gt 10 ]; then
echo "⚠️ More than 10 files changed. Review required."
exit 1
fi
# Run tests before any commit
npm test || { echo "Tests failed. Blocking commit."; exit 1; }Layer 3 is context management. Your agent needs to know what it's working on, what it's changed, and what's off-limits:
# Context briefing for every session echo "## Project Context" > context.md echo "Goal: $CURRENT_GOAL" >> context.md echo "Files modified this session: $(git diff --name-only)" >> context.md echo "Do not modify: package-lock.json, .env, migrations/" >> context.md
The Recovery Pattern
The best part about a harness? It makes your agent recoverable. When something goes wrong (and it will), you don't start over — you resume:
# Auto-recovery on restart if [ -f "$SESSION_DIR/state.log" ]; then echo "Resuming session from $(cat $SESSION_DIR/state.log)" git status echo "Context: $(cat $SESSION_DIR/context.md)" fi
Why This Works
Without a harness, your coding agent is flying blind. It doesn't know if the tests are passing, if it's about to overwrite something important, or even what it was doing five minutes ago.
With a harness, it becomes predictable. It can't lose its session. It can't ship broken code. It can't forget what it's supposed to be doing.
Warning: Don't over-engineer this. Start with basic session logging and safety checks. Add complexity only when you hit real problems.
The difference between a toy coding agent and a production one isn't the model — it's the infrastructure around it. Build the harness first. Everything else gets easier.