November 22, 2026

Hard-Coding Discipline: Why LLM Agent Instructions Must Become Enforced Logic to Control Context and Cost

In addition to the hard blocks, a "hint hook" named long_session_hint.py was introduced. This script triggers during the prompt-submit event and acts as a non-blocking advisory. When a main conversation context exceeds 200,000 tokens, and at every 100,000-token interval thereafter, the system injects a notification. This notification advises the model to transition new results to a fresh session and informs the human operator of the current context size.

This was necessitated by the observation that while subagents were being successfully constrained, the "main" sessions were still operating at context levels between 220,000 and 490,000 tokens. In contrast, the Codex threads managed by the guards maintained a median context of only 67,000 tokens. The goal is to bring the main session’s efficiency in line with the subagents’ performance.

Lessons for the Future of Agentic Workflows

The experience of managing Claude Code and Codex highlights a broader truth about the current state of AI: models are optimized for task completion, not for cost-efficiency or structural adherence. If an agent is given a choice between a complex but "correct" workflow (opening new sessions) and a simple but "expensive" one (continuing in the current session), it will frequently choose the latter unless the former is the only path available.

For developers and architects, the takeaway is a new litmus test for agent instructions. One must ask: "If the agent never read this sentence, what would happen?" If the answer is "nothing," then the rule is not a rule—it is merely a wish.

True enforcement requires three components:

  1. A Registry: A persistent record of which agents have performed which tasks.
  2. Context Identification: A reliable method to determine which specific agent is attempting an action.
  3. Ubiquitous Guards: Checks that live inside the most common and unavoidable commands, ensuring that there is no "path of least resistance" that bypasses the intended architecture.

As AI agents take on more autonomous responsibility, the "manager" agents will inevitably incur higher costs than the "engineer" agents they supervise. However, by transforming prompt-based wishes into hard-coded logical constraints, developers can ensure that those costs remain within the bounds of reason and that the agents remain focused, efficient, and disciplined.