Advanced Claude Code
Techniques

Context Management, Environment Orchestration, Hooks

Markus Klug

German IT Entrepreneur since 1997, now based in Lisbon.
Award-Winning Founder and Builder, FinTech Veteran,
Agentic Coding Pioneer.

The Problem

Most developers dump everything into one CLAUDE.md

Monolithic

  • One massive CLAUDE.md
  • Everything always loaded
  • Context window bloat
  • Expensive and slow

Layered

  • Progressive disclosure
  • Load knowledge on demand
  • Lean base context
  • Fast and token-efficient

Context hierarchy beats monolithic design. Every time.

The Context Hierarchy

Seven layers, loaded progressively

~/.claude/CLAUDE.md Global persona and base rules
~/.claude/skills/*/ User-level skills — shared across all projects
project/CLAUDE.md Project-level: dev environment, tmux, scripts
project/CLAUDE.local.md Private overrides (not checked in)
project/.claude/rules/*.md Auto-loaded rules — always in context
project/.claude/skills/*/ Project skills — loaded via /skill-name
project/.claude/docs/*.md Shared reference docs — @included by skills

Rules auto-load and are always active. Skills are invoked when needed.

Two Kinds of Skills

User-invoked vs model-invoked

User-Invoked

Only triggered by the user typing /skill-name

disable-model-invocation: true

Sensitive operations

Destructive commands

Interactive workflows

Setup wizards

/generate-patches, /import-snapshot

Model-Invoked

Claude decides when to invoke based on context

disable-model-invocation: false (default)

Authoring guides and cops

Domain knowledge bases

Convention enforcement

Triggered by description match

/css-cop, /ct-backend-api-surface

Model-invoked skills maximize autonomy. User-invoked skills preserve human control where it matters.

Skill Frontmatter

Identity and invocation control

name

Skill identifier. Lowercase, numbers, hyphens only.

name: hook-management
description *

THE critical field for model-invoked skills

This is how Claude decides whether to invoke. Include exact trigger phrases. Vague = missed invocations.

description: Use when user asks to "create a hook",
  "add a PreToolUse hook", or mentions hook events.
disable-model-
invocation

When true, only the user can trigger via /skill-name

disable-model-invocation: true
user-invocable

When false, hidden from slash menu. Only Claude can invoke it.

user-invocable: false

Together these two booleans create three modes: user-only, model-only, and both (default)

Skill Frontmatter

Execution control

allowed-tools

Restrict which tools the skill can use

allowed-tools:
  - Read
  - Grep
  - Bash
model

Which Claude model executes the skill

haiku

Fast

sonnet

Balanced

opus

Max

sonnet[1m]

Extended

argument-hint

Documents expected arguments, shown in UI autocomplete

argument-hint: [app-name] [environment]
context + agent

Run skill in an isolated subagent context

context: fork
agent: Explore

Built-in: Explore, Plan, general-purpose — or custom agent name

hooks

Skill-scoped lifecycle hooks

hooks:
  PostToolUse:
    - matcher: "Edit|Write"
      hooks:
        - type: command
          command: lint.sh

Skills Taxonomy

27 skills across 4 categories

Authoring Guides

Loaded before writing code

css-cop, tsx-cop, typescript-cop

conventions-cop, conventions-index-page

UI Component Guides

Building specific UI widgets

ui-lib-data-table, ui-lib-data-list

changelog-expert, ux-expert

Domain Knowledge

Specific subsystem expertise

ct-backend-api-surface (310 ops)

ct-trade-management, ct-ingestion

Procedural Workflows

Multi-step defined processes

generate-patches, wire-permits

import-snapshot, dataset-onboarding

Deep knowledge available on demand — without polluting the base context

How Anthropic Uses Skills

9 categories from hundreds of skills in production — @trq212

1. Library & API Reference

Internal libs, SDKs, CLIs — gotchas and snippets

2. Product Verification

Test flows via Playwright, tmux — assert correctness

3. Data Fetching & Analysis

Connect to data stacks, dashboards, query patterns

4. Business Process

Standups, ticket creation, weekly recaps

5. Code Scaffolding

Templates, migrations, new app boilerplate

6. Code Quality & Review

Adversarial review, style enforcement, test practices

7. CI/CD & Deployment

Babysit PRs, gradual rollouts, cherry-picks

8. Runbooks

Symptom to investigation to structured report

9. Infrastructure Ops

Orphan cleanup, dependency approval, cost investigation

Skills are folders, not just markdown — include scripts, assets, data, and on-demand hooks

Read the Full Article

Lessons from Building Claude Code: How We Use Skills

QR Code

x.com/trq212/status/2033949937936085378

by Thariq Shihipar

Claude Code team @ Anthropic

Environment
Orchestration

Claude Owns the Dev Environment

tmux Sessions * Specialized Skills * Saves Time and Tokens

tmux Pane Layout

Structured development environment

Window Pane Purpose What Runs
srv1-2UI + Backend serverspnpm dev / dotnet run
tsc1TypeScript watchpnpm run watch
cli1-2General CLIad-hoc commands
cli-ui1UI-scoped CLIpnpm add, scripts
docker1-2Docker managementcompose up/down
cc1-31Claude Code sessionsparallel agents

Claude NEVER asks the human to run commands

All execution happens in designated panes

Dedicated restart scripts

dev-restart-backend.sh, dev-restart-frontend.sh

Checking Server State

Claude reads pane output directly

Read backend server output (last 30 lines)

$ tmux capture-pane -t eureka:srv.2 -p | grep -v '^$' | tail -30

Check TypeScript errors (last line = summary)

$ tmux capture-pane -t eureka:tsc -p | grep -v '^$' | tail -1

Never runs tsc itself

Reads the watch pane instead

Saves time and tokens

No redundant compilation

Hooks

Making Claude Self-Aware

State Indicators * Auto-Formatting * Real-Time Dashboard

18 Lifecycle Events

Shell commands, HTTP endpoints, LLM prompts, or agents — fired at every stage

*
SessionStart
Session begins or resumes
B
UserPromptSubmit
Before Claude processes prompt
*
InstructionsLoaded
CLAUDE.md or rules file loaded
B
PreToolUse
Before a tool call executes
*
PostToolUse
After a tool call succeeds
*
PostToolUseFailure
After a tool call fails
B
PermissionRequest
Permission dialog appears
B
Stop
Claude finishes responding
*
Notification
Claude sends a notification
*
SubagentStart
Subagent spawned
B
SubagentStop
Subagent finishes
B
TeammateIdle
Teammate about to go idle
B
TaskCompleted
Task marked as completed
B
ConfigChange
Config file changes mid-session
*
PreCompact
Before context compaction
B
WorktreeCreate
Worktree being created
*
WorktreeRemove
Worktree being removed
*
SessionEnd
Session terminates
B = can block * = side-effects only | 4 hook types: command, HTTP, prompt, agent

State Indicators

Claude's state reflected in tmux window titles

Hook Events

*

UserPromptSubmit

Window title: * running

+

PermissionRequest

Window title: + needs-input

-

Stop

Window title: base name

Topic System

A separate script writes a short topic to a temp file, appended to the window title:

* running:fixing auth bug

Implementation:

tmux-state.sh reads $TMUX_PANE
strips existing state suffixes
reads /tmp/claude-topic-{pane}
renames the window

Hooks in Practice

Auto-formatting pipeline — queue-and-flush pattern

Step 1: Queue

PostToolUse hook

On Edit/Write events

dprint-fmt-queue.sh
reads file path from tool input
if .md/.css/.ts/.tsx:
  append to session queue
->

Step 2: Flush

Stop hook

When Claude finishes a turn

dprint-fmt-run.sh
reads the queue file
runs dprint fmt on each file
cleans up queue

All edited files auto-formatted when Claude finishes — without interrupting the workflow

Hooks in Practice

Real-time dashboard via HTTP hooks to localhost:8002

tmux State

UserPromptSubmit → running

PermissionRequest → needs-input

Notification(idle) → idle

Stop / SessionEnd → idle

tmux-state.sh running|needs-input|idle

Auto-Format

PostToolUse(Edit|Write) → queue

Stop → flush dprint fmt

dprint-fmt-queue.sh
dprint-fmt-run.sh

Auto-Approve

PreToolUse(Edit|Write)

→ approve claude settings

auto-approve-claude-settings.sh

HTTP Dashboard — every event streams to localhost:8002/api/hooks

SessionStart
UserPromptSubmit
PreToolUse
PostToolUse
PostToolUseFailure
PermissionRequest
Stop
TaskCompleted
SubagentStart
SubagentStop
TeammateIdle
Notification
PreCompact
InstructionsLoaded
ConfigChange
WorktreeCreate
WorktreeRemove
SessionEnd

3 shell scripts + 1 HTTP endpoint = full observability over every Claude session

The Full Stack

Three pillars of advanced Claude Code

Context Management

Hierarchical CLAUDE.md layers

Rules auto-load, skills on demand

27 skills across 4 categories

Shared docs via @include

Reduce context bloat

Environment

Structured tmux sessions

7 windows, dedicated panes

Direct pane output reading

Specialized restart scripts

Save time and tokens

Hooks

Dynamic state indicators

Topic system for context

Auto-formatting pipeline

Multi-session dashboard

Real-time awareness

Claude Code as a full development platform — not just a chat assistant

Thank You

LinkedIn QR

Markus Klug

@opus131
Questions?