# Fix Nested Code Fences

> Use when a markdown file has nested code fences that break rendering — when a ```markdown, ```bash, or similar block appears inside another ``` block anywhere in a generated or edited markdown file.

- Skill: `slogsdon/fix-nested-code-fences` (Agent Skill)
- Install (CLI): `npx skillmds@latest add slogsdon/fix-nested-code-fences`
- Raw SKILL.md: https://api.skillmd.com/api/skills/slogsdon/fix-nested-code-fences/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Docs & Writing
- Author: slogsdon (https://skillmd.com/u/slogsdon)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/slogsdon/fix-nested-code-fences

---


# Skill: fix-nested-code-fences

When a code block contains inner triple-backtick fences, replace the outer fence with `~~~` — the minimum change that fixes rendering without altering any content.

**Don't:** change inner fences — only the outer fence needs replacing. Don't apply this to tilde fences that are already correct.

## The Problem

When markdown is generated or written that contains code block examples inside other code blocks, the inner fences terminate the outer block early, breaking rendered output. Common in: skill templates, documentation generators, README examples, any file where markdown is shown inside markdown.

## The Fix

Replace the **outer** fence with `~~~` when the block contains inner ` ``` ` fences. Inner fences stay as-is.

**Before:**
````
```markdown
## Example

```bash
VAR=value
```
```
````

**After:**
~~~~
~~~markdown
## Example

```bash
VAR=value
```
~~~
~~~~

## Steps

1. Read the file
2. Find any fenced code block that contains inner ` ``` ` fences
3. Replace the outer opening and closing fences with `~~~`
4. Leave inner fences unchanged
5. Confirm the fix and offer to commit if in a git repo

