Skip to main content

How I Turned Claude Code into a Fabric-Aware Engineering Partner

Agents, slash commands, hooks and deny rules — and the specific mistakes each one prevents.

Updated 7 min readMarkdown

The Problem With a Raw Claude Code Session

I run 22 Fabric workspaces across four repos. At some point, "Claude in a terminal" stopped being enough.

A fresh Claude Code session knows nothing about your project except what it can read from disk. It will happily open rayfin/.env, modify model.tmdl without asking, force-push to main, and forget everything the moment the terminal closes. Those are not hypothetical. All four happened to me before I had guardrails in place.

The fix is not prompt engineering. It is infrastructure.


Agents: Bounded Experts That Run Read-Only First

An agent in Claude Code is a .md file in .claude/agents/. It gets its own system prompt and — critically — its own tool permissions. That second part is what makes agents useful for infrastructure work: you can give a reviewer read-only scope and it cannot accidentally write anything.

Here is what I settled on across my three repos.

Fabric-Analytics-Projects (workspace-level Fabric work):

  • design-brief-writer — produces a Layout Trifecta brief for a report before any PBIR or DAX is touched. Read-only. The brief has to be confirmed before anything gets saved to disk.

  • fabric-explorer — reads workspace state from the Fabric Core MCP and surfaces drift between what CONTEXT.md says and what is actually deployed.

  • tmdl-reviewer — reads staged TMDL and flags broken references, hidden fields left exposed, and measures missing VAR/RETURN. Read-only.

  • pbir-reviewer — checks staged PBIR JSON for escaped-string config values, missing visual descriptions, and semantic model field references that do not match the hidden column list.

  • session-recap-writer — the only write agent. Runs at end of session, updates CONTEXT.md and PROJECTS.md, and commits to dev-fabric-sync. Fabric-Apps-Projects (Rayfin app development):

  • app-explorer — inventories all apps under apps/, shows connector type, deploy state and last-modified date.

  • deploy-checker — reads rayfin/.deployments.json and flags stale deployments and workspace ID mismatches before you run npx rayfin up.

  • entity-reviewer — checks entity schema files for field naming inconsistencies and type mismatches against the connector definition. Business-Intelligence-Projects (PBIP semantic model and report work):

  • model-reviewer — reviews a staged semantic model for star schema violations, calculated columns that should be measures, and hidden columns still referenced in visuals.

  • project-state-reviewer — reads PROJECTS.md and surfaces the next action for a named project without opening every CONTEXT.md manually. The pattern across all of them: reviewers are read-only, and only the recap writer touches files. That matters because Claude Code can get enthusiastic about fixing things it was only asked to review.


Commands: Protocols That Run Consistently

A command is also a .md file, in .claude/commands/. The difference from agents is that commands orchestrate: they read state, run tools in a defined order, and produce a specific output. Agents are experts; commands are procedures.

The three I use most:

/session-start <name> runs before any real work begins. It reads the workspace's CONTEXT.md and PROJECTS.md entry, checks whether the Fabric Core MCP can reach the workspace, and warns if the two are out of sync. It also offers to run fabric-explorer if significant time has passed since the last session. The whole thing is read-only, so it cannot go wrong.

/end-session <name> triggers session-recap-writer. Before I had this, I was manually updating CONTEXT.md at the end of every session. I stopped doing it. Important context accumulated in my head and never made it back to the file. The command makes the recap impossible to skip.

/validate (Business-Intelligence-Projects only) is a pre-commit checklist: it checks for Desktop-managed TMDL modifications, BOM characters in staged PBIR JSON, and runs powerbi-report-author validate. The key lesson: it runs git diff --cached --name-status and looks under *.SemanticModel/definition/, not *.Report/definition/. An earlier version had the wrong path and silently never fired.


Hooks: Event-Driven Automation That Runs Without Asking

Claude Code hooks fire on tool events. I use two.

post-edit-rayfin.ps1 fires on every Edit or Write tool call in Fabric-Apps-Projects. It reads the tool input, checks whether the edited file is a connector or an entity schema, and if so emits a deploy reminder into the session context. The reminder says exactly which npx rayfin command to run. Before this, I would edit a connector and then debug a "wrong workspace" error ten minutes later after a partial deploy.

session-start.ps1 fires at session startup in all three repos. It runs the MCP health check and prints branch and uncommitted changes to the session context immediately. The session starts with current state instead of with whatever Claude Code assumes.

One thing worth knowing: hooks fire before the tool result is returned. That means the reminder arrives in context before Claude Code has a chance to continue on to the next edit. That is the right order.


The Pre-Commit Hook: What the Agent Cannot Enforce

The .githooks/pre-commit hook runs at commit time and operates on the index, not on tool calls. It catches what the agent might miss:

  • rayfin/.temp/ and rayfin/.deployments.json at any depth — not root-anchored, which was the original bug
  • Any .env or .env.* file except .env.example
  • Secrets: SP client secrets, account keys, SAS tokens, bearer tokens, plaintext passwords matching a fixed pattern The pattern had to be a single-line grep -E because Git Bash breaks multi-line continuations. That cost me two failed hooks and one confused commit before I learned it. The rule is now documented in dev-environment and in every HARNESS.md.

For database.tmdl and model.tmdl the hook warns without blocking. Both are required PBIP files: a new project's first commit includes them, and model.tmdl changes whenever a table is added. Hard-blocking them stops a legitimate first commit. The original hook did exactly that.


Deny Rules: The Last Line of Defence

Hooks run at commit time. Deny rules in .claude/settings.json run at tool-call time — before the agent touches anything.

The ones I added, with zero breakage to any existing workflow:

"deny": [
  "Bash(git push origin main*)",
  "Bash(git push --force*)",
  "Bash(git push -f*)",
  "Bash(git push * --force*)",
  "Bash(git push * -f*)",
  "Read(**/.env)",
  "Read(**/.env.*)"
]

The force-push patterns need four variants because --force can appear before or after the branch name and Claude Code matches the full command string. One pattern misses the other position.

One important limitation: Read and Edit deny rules apply to Claude Code's built-in file tools, not to Bash subprocesses. A Read(**/.env) deny rule blocks the Read tool but does not prevent cat .env in a Bash call. The hook is still the enforcement point for the index. The deny rule prevents the content from landing in the session transcript.


How It All Connects

Each tool covers a gap the others leave open.

Agents bound what Claude Code can see and touch per task. Commands make session protocols reproducible — the recap gets written whether I remember to ask for it or not. Post-tool hooks surface deploy consequences immediately, in context, before the next edit. Pre-commit hooks enforce what cannot be committed regardless of how the file was written. Deny rules prevent sensitive content from entering the transcript and block destructive git operations at tool-call time.

The source of truth for all of it is dev-environment, a private repo with one script per profile (common, fabric, fabric-apps, pbip). A new repo gets the full set in one command. An existing repo diffs against the templates before anything is overwritten.

The setup took about two weeks of incremental work across six Claude_Audit sessions. Most of that time was testing: each hook and each deny rule was tested against real staged files or live tool calls, not by reasoning about what the pattern should match. That is the part the documentation always skips. A pattern that looks right and a pattern that fires correctly are not the same thing, and the difference only shows up against real data.


What's Next

The layer I've described here is the foundation. The thing I'm building on top of it now is a Fabric Governance app — a Rayfin application that inventories all 22 workspaces, runs health rules against tenant settings, and surfaces violations in a live dashboard. The agent/command/hook layer is what makes that build tractable: each session starts with current state, nothing gets committed without review, and the transcript never contains credentials.

That build will be the next post.


Source: Fabric Analytics Projects on GitHub

2 views

About the author

  • Microsoft Fabric Analytics Engineer (DP-600) and PhD in Computational Physics. Founder of Lotusoftware, a data analytics consultancy in Vantaa, Finland. Writing about Microsoft Fabric, Power BI, agentic BI systems, and AI-powered analytics.

No comments yet. Be the first to comment.