How to Tame Claude Code - Stop AI Slop with Hooks and Agents

Stop AI Slop Before It Starts

AI Slop Is Just Spaghetti Code in a New Wrapper

I've used Claude Code almost since its inception, and here's the truth: it's great if you want to "wing it" - that is, you're not implementing production-ready apps that are allowed to fail (sometimes even catastrophically). We've all heard terms like AI slop, tech debt, and other backlash against using these incredible models to code.

Conversely, along with the backlash and the sheer amount of companies locking out their employees from using AI in anything remotely private or production-grade (just like Samsung after getting their source code leaked on these models), we're still seeing users going against these orders. Seems like there are two types of jobs these days: the ones where you can't / aren't allowed to use AI and the ones where your colleague just got laid off because of AI.

But we're on quite a tangent. This post is about solving specific Claude Code problems, namely, AI slop (we'll tackle tech debt and privacy another time). How do we go about it? First, we need to understand how humans write slop. Because AI didn't come with this term. Its distant uncle "Spaghetti Code" has been around for ages, and it stems from mainly one thing: lack of structure. I had an incredible uni teacher who would not let us write any line of code in our project until we followed the waterfall to a tee. And many companies also behaved and still behave to this day this way, even if now we get a little more leeway because of agile.

Before we tackle AI slop, we need to narrow down the scope a bit more. We already chose our vibe coder: Claude Code. Next, we need a specific scenario: I choose my own, solo / indie developer creating Micro SaaS. As a person who has developed many apps already, I feel in the possession of enough knowledge to find the biggest pitfalls when vibe coding.

The Biggest Pitfalls of Vibe Coding with Claude Code

To name a few, here are the biggest pitfalls when creating apps with Claude Code (or any vibe coding app, for that matter):

Context Limits Will Kill Your Session

As your session goes on, the worse your LLM will perform. This is because your context window gets cluttered with what it needs and what it doesn't need for any given task. And when it autocompacts, it's like you're starting everything all over again. Truth is, 200k tokens (the context limits of Claude Sonnet 4.5), is less than what it seems, especially when we slap MCP servers, which are great at consuming context and are therefore slightly overrated.

Imperfect Prompts Snowball Into Disasters

No matter how good you are at writing prompts, you will forget something. And what happens when you forget something? Either the LLM catches it and warns you, or it deduces what you want and creates mistake upon mistake, which when stacked come at you like a gigantic snowball down Mount Everest. Have fun fixing that.

Large Scope Tasks Spiral Out of Control

A big problem caused by the grouping of the previous two is the sheer scope we are giving to Claude Code. "Implement a web app that does XYZ" usually translates to a bunch of smaller tasks. The LLM divides this large task into smaller chunks, but it still tries to do everything within one session, and even if you try to add safeguards, sometimes they are not completely followed by the LLM. Subagents are popping up and help deal with this (because they have their own context), but the orchestrator is the LLM, which is not the greatest at obeying our orders. From my experience, even a well orchestrated master prompt is not good enough to deal with this.

Lack of Supervision Creates Silent Failures

Even if you're watching closely, as soon as you hit the "auto-accept edits" button, you're at risk of Claude Code doing what it wants, and sometimes their outputs go against your inputs. When you catch it, no problem, but sometimes you don't see it, and that's another source of problems. I know a guy who was using a local model instead of an API for OpenAI's Whisper API. I'm not saying that I know who it was and on which app (me, Narralyn), but I'm sure you can relate.

Documentation and Tests Get Ignored

I have lost count at how many times I've prompted Claude Code to "Please create unit tests and documentation" after its implementations. It's crazy that even if this is part of my master prompt, it just doesn't care half the time. And when it creates the tests, of course it doesn't use the incredible unit test agent you just created or downloaded online.

You Assume It Knows Everything (It Doesn't)

I propose you a small test: shove a document to Claude Code and ask it questions. Was the response accurate? Half the time, incredibly, no. It's the good part of MCP Servers, they give proper tools to the LLM, but they have the context issue. Sometimes it's best to let the LLM do what it's best at - write code to create your set of tools (a band-aid for the MCP Server issues). The second part: how do you know the LLM limits? Experience and validation.

Now that we've outlined some of the main issues, we need to take the next step.

How to Bring Order to the Claude Code Chaos

As you can see by the issues outlined above, it's not so easy to stop Claude Code from doing bad things, but it's not impossible! I've made some experiments to help you find the best place to intercept Claude Code and add our own custom instructions to it.

Here's the best place I've found to intercept Claude Code operations: hooks. There are many opportunities in the form of hooks for us to inject our custom operations:

PreToolUse - Your First Line of Defense

Called every time Claude Code runs a tool, from bash commands to writing files. This is likely the best place you can pre-emptively stop Claude Code from getting you into trouble.

PostToolUse - React After Actions

Reactionary hook to tool uses from Claude Code, where you can trigger post-processing actions.

UserPromptSubmit - Enforce Best Practices

Right before your prompt is sent to Claude Code. Likely the best place to nicely enforce your best practices.

Notification - Permission Interceptor

Whenever Claude Code prompts you with permissions. Likely how yolo mode gets its functionality.

Stop/SubagentStop - Clean Up Operations

When Claude Code or an agent it triggered finishes an operation. Useful to clean up house.

SessionStart/SessionEnd - Session Lifecycle

Triggered at the beginning or end of a Claude Code Session.

The Missing Piece: Enforced Agents

Ok, now that we know the vehicle we will use to enforce good manners into Claude Code, what are we missing to turn this into something useful? I have a suggestion: agents. Except, this time, they will always be enforced, as opposed to when Claude Code uses them, which it may or may not do. Do you want to be at its mercy, or ensure that 100% of the time your rules are enforced? Exactly.

And now, all we need to do is create agents and connect them!


Building in public. Follow my journey at InvisiblePuzzle (opens in a new tab) where I document how I'm building B2B automation tools while working full-time.

Tags: #claudecode #ai #agents #hooks #productivity #development #bestpractices #versioncontrol

© 2025 InvisiblePuzzle

Building Software Tools for B2B