DEV Community

Ogasawara Kakeru
Ogasawara Kakeru

Posted on Edited on

Claude Code ~Harness Engineering~

Harness Engineering with Claude Code: A Five-Layer Design Pattern

Main Thesis

Good prompts alone are not enough to use Claude Code well. The author argues for harness engineering: designing the environment around the model, using Claude Code's configuration mechanisms (CLAUDE.md, Rules, Skills, Agents, Settings, Hooks) to steer its behavior deliberately. The article presents a five-layer implementation from a personal information-collection and knowledge-management repository. Hooks are not used yet.

Background

  • Origin: Mitchell Hashimoto introduced the term in February 2026. When an agent makes a mistake, you fix the environment permanently so it doesn't repeat it.
  • Why it's needed: LLMs are stateless. Conversation history and project context are re-injected on every request, and anything not injected effectively doesn't exist for the model.
  • Three disciplines:
    • Prompt engineering optimizes what you ask.
    • Context engineering optimizes what the model sees.
    • Harness engineering is broader: tools, permissions, and guardrails, with context engineering as a part of it.

The Five Layers

1. CLAUDE.md (the "constitution")

  • Covers project purpose, structure, technical rules, and security rules.
  • Explicitly lists what the assistant should not do. This defines behavioral scope rather than suppressing reasoning, and reduces drift.
  • In team repos, personal preferences go in a gitignored file imported with @. Missing import targets are ignored, so the import is safe to commit.

2. Rules (domain-specific rulebooks)

  • Markdown files in .claude/rules/, split by domain to keep CLAUDE.md small.
  • A globs frontmatter field enables lazy loading and saves context. The author reports parsing bugs with the documented paths field, so globs is safer for now.

3. Skills (reusable workflows)

  • Invoked as /command and defined in SKILL.md. The author runs 13.
  • Principle: separate what the LLM does from what a script does. Moving RSS fetching and parsing into Python, and leaving only translation and classification to the LLM, cut token use to about one-sixth and processing time to about one-third.
  • Running scripts with uv run and pinned versions needs no environment setup and lowers supply-chain risk.
  • A good description field lets Claude Code suggest relevant skills on its own.

4. Agents (specialized subagents)

  • Invoked as @name and run in a separate context.
  • Main benefit is context isolation: searching hundreds of notes doesn't fill the main context, and only a summary returns.

5. Settings (permissions and security)

  • settings.json allow and deny lists act as the safety mechanism.
  • Allow routine commands broadly, explicitly deny destructive operations (such as repo deletion), and keep machine-specific permissions in settings.local.json.
  • Piped commands are evaluated per subcommand and are hard to match with allow patterns. Running commands without pipes and letting the LLM parse the output is more reliable.

Lessons Learned

  • Defining "what not to do" is the most cost-effective choice. It prevents unrequested "improvements."
  • Separate deterministic work from LLM judgment. API calls, parsing, and file I/O go in scripts; judgment and generation go to the LLM.
  • Keep CLAUDE.md lean. Treat it as a constitution, not an encyclopedia. Domain detail goes to Rules, workflows to Skills.
  • Tune permissions iteratively. Run the workflow, note the prompts that appear, and add patterns over time.
  • Defer Hooks. CLAUDE.md and Rules are advisory; Hooks are deterministic. Static deny patterns cover most needs, and LLM-based Hooks add token cost on every tool call. Start minimal and add Hooks after observing real failures.

Conclusion

Layering CLAUDE.md, Rules, Skills, Agents, and Settings turns Claude Code from a "smart chatbot" into a personalized development environment that carries context across sessions and works within defined rules, which the author calls a "personal team."

Top comments (0)