How to add a code typing animation with Claude

A dark code editor window slides up under the product and four lines of Python type into it in pink, yellow and green syntax colors, line numbers down the side.

Get this effect

  1. Switch to Code in your Claude Desktop App

  2. Install the skill (once)

    Show the prompt
    Install the Recharm video effects skill: download https://recharm-growth-staging.s3.us-east-2.amazonaws.com/website/downloads/recharm-video-effects.zip and unzip it into ~/.claude/skills
  3. Ask for the effect

    Add a code typing animation to input.mp4
    Code: ["def glow_up(skin):", "    serum = \"Vitamin C\"", "    skin.apply(serum, drops=3)", "    return \"radiant\""]
    Filename: glow.py
    Colors: Monokai pink, yellow, purple, green, off-white

Several videos, several effects, one ask

Put your clips in the folder, mention them with @, and ask for everything at once. Claude runs one tested script after another on each clip, then joins them.

Add a code typing animation to @clip1.mp4, put a sale badge on @clip2.mp4, give @clip3.mp4 a VHS look, then join all three with crossfades.

Settings you can change

Ask Claude to change any of these, or edit them at the top of the script.

SettingDefaultWhat it does
CODE["def glow_up(skin):", " serum = \"Vitamin C\"", " skin.apply(serum, drops=3)", " return \"radiant\""]The lines of code that get typed, top to bottom.
FILENAMEglow.pyName on the window's tab.
APPEAR0.3Second the window slides up and fades in.
START0.7Second the first line starts typing.
CPS28Characters typed per second.
PAUSE0.2Seconds between one line finishing and the next starting.
COLORSMonokai pink, yellow, purple, green, off-whiteSyntax colors for keywords, strings, numbers, function calls and the rest.

Without the skill

Don’t want to install the skill? Paste this prompt into Claude Code and Claude writes the script itself.

Show the prompt
Add a code typing animation to input.mp4 (540x960). At 0.3 seconds a dark code editor window slides up 6% of the frame width and fades in over 0.3 seconds (ease-out): 88% of the frame width wide, its left edge 6% from the left (so centered horizontally), its top 70% down the frame, background (39, 40, 34) with rounded corners and a soft black drop shadow. It has a darker (30, 31, 26) title bar with red (255, 95, 87), yellow (254, 188, 46) and green (40, 200, 64) dots at the left and "glow.py" centered in gray (150, 150, 140). Below it, gray (117, 113, 94) line numbers 1 to 4 run down the left side and these four lines of Python type out in Menlo at 3.8% of the frame width, 1.7 text heights apart: def glow_up(skin): / serum = "Vitamin C" / skin.apply(serum, drops=3) / return "radiant" (lines 2 to 4 indented 4 spaces). Color them like Monokai: keywords def and return pink (249, 38, 114), strings yellow (230, 219, 116), the number purple (174, 129, 255), function names before "(" green (166, 226, 46) and everything else off-white (248, 248, 242). The first line starts typing at 0.7 seconds at 28 characters per second; each indent appears at once and each next line starts 0.2 seconds after the previous one finishes, so typing ends at about 4.1 seconds. A thin off-white bar cursor follows the last typed letter, solid while typing and blinking after. The window stays to the end. Use Python with Pillow to draw it and ffmpeg to put it on the video (don't rely on ffmpeg's drawtext filter), keep the audio, and save it as output.mp4.

Run it without Claude

This is the exact script we tested. Save it as code-typing-animation.py and run:

python3 code-typing-animation.py input.mp4 output.mp4
Show the script
#!/usr/bin/env python3
"""Code typing animation: a dark editor window slides up and syntax-colored code types into it line by line.

Usage: python3 code-typing-animation.py input.mp4 output.mp4
Needs ffmpeg and Pillow (pip install pillow).
"""
import json
import math
import re
import subprocess
import sys
from pathlib import Path

from PIL import Image, ImageDraw, ImageFilter, ImageFont

CODE = ["def glow_up(skin):",
        "    serum = \"Vitamin C\"",
        "    skin.apply(serum, drops=3)",
        "    return \"radiant\""]
FILENAME = "glow.py"     # name on the window's tab
APPEAR = 0.3             # second the window slides up and fades in (over 0.3 seconds)
START = 0.7              # second the first line starts typing
CPS = 28                 # characters typed per second (indents appear at once, like an editor's auto-indent)
PAUSE = 0.2              # seconds between one line finishing and the next starting
SIZE = 0.038             # text height as a share of the frame width
LEFT, TOP, WIDTH = 0.06, 0.70, 0.88   # window's left edge and top (0-1 across and down) and width (share of frame width)
BACKGROUND = (39, 40, 34)             # editor background (Monokai)
COLORS = {"keyword": (249, 38, 114),  # def, return: pink
          "string": (230, 219, 116),  # "...": yellow
          "number": (174, 129, 255),  # 3: purple
          "call": (166, 226, 46),     # glow_up(, apply(: green
          "plain": (248, 248, 242)}   # everything else: off-white
FONTS = [("/System/Library/Fonts/Menlo.ttc", 0),                     # macOS
         ("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 0),  # Linux
         ("C:/Windows/Fonts/consola.ttf", 0)]                         # Windows
FONT_FILE, FONT_INDEX = next((f for f in FONTS if Path(f[0]).exists()), None) or sys.exit("No monospace font found: add one to FONTS")
TOKENS = re.compile(r'(?P<string>"[^"]*"?)|(?P<keyword>\b(?:def|return|import|from|if|else|for|in)\b)'
                    r'|(?P<number>\b\d+\b)|(?P<call>\w+(?=\())|(?P<plain>.)')


def colored(line):
    """Split a line of Python into (text, color) pieces."""
    return [(m.group(), COLORS[m.lastgroup]) for m in TOKENS.finditer(line)]


def window(t):
    """The editor window with the code typed so far at second t."""
    img = Image.new("RGBA", (win_w, win_h))
    draw = ImageDraw.Draw(img)
    draw.rounded_rectangle([0, 0, win_w - 1, win_h - 1], radius=pad, fill=BACKGROUND)
    draw.rounded_rectangle([0, 0, win_w - 1, bar_h], radius=pad, fill=(30, 31, 26))  # title bar
    draw.rectangle([0, bar_h - pad, win_w - 1, bar_h], fill=(30, 31, 26))
    for i, dot in enumerate([(255, 95, 87), (254, 188, 46), (40, 200, 64)]):  # close, minimize, zoom
        cx, r = pad * 1.4 + i * pad * 1.5, pad * 0.45
        draw.ellipse([cx - r, bar_h / 2 - r, cx + r, bar_h / 2 + r], fill=dot)
    draw.text((win_w / 2, bar_h / 2), FILENAME, font=font, anchor="mm", fill=(150, 150, 140))
    for i, (line, begin) in enumerate(zip(CODE, starts)):
        indent = len(line) - len(line.lstrip())
        typed = line[:indent + max(0, int((t - begin) * CPS))] if t >= begin else ""
        y = bar_h + pad + i * line_h
        draw.text((pad, y), str(i + 1).rjust(2), font=font, fill=(117, 113, 94))  # line number
        x = code_x
        for piece, color in colored(typed):
            draw.text((x, y), piece, font=font, fill=color)
            x += font.getlength(piece)
        typing = begin <= t and (i == len(CODE) - 1 or t < starts[i + 1])
        if typing and (t < done or int(t * 2.5) % 2 == 0):  # cursor stays solid while typing, blinks after
            draw.rectangle([x + 1, y - font.size * 0.1, x + 3, y + font.size * 1.1], fill=COLORS["plain"])
    return img


def overlay(t):
    img = Image.new("RGBA", (w, h))
    p = min(max((t - APPEAR) / 0.3, 0), 1)
    if p == 0:
        return img
    ease = 1 - (1 - p) ** 3
    x, y = round(w * LEFT), round(h * TOP + (1 - ease) * w * 0.06)  # slides up 6% of the frame width
    layer = Image.new("RGBA", (w, h))
    layer.alpha_composite(shadow, (x - pad * 2, y - pad))
    layer.alpha_composite(window(t), (x, y))
    layer.putalpha(layer.getchannel("A").point(lambda a: round(a * ease)))
    img.alpha_composite(layer)
    return img


def probe(path):
    info = json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries",
                                               "stream=width,height,r_frame_rate:format=duration", "-of", "json", path]))
    s = info["streams"][0]
    num, den = s["r_frame_rate"].split("/")
    return s["width"], s["height"], s["r_frame_rate"], float(num) / float(den), float(info["format"]["duration"])


def render(src, out):
    """Draw overlay(t) on every frame of src and save to out, keeping the audio."""
    ff = subprocess.Popen(["ffmpeg", "-y", "-v", "error", "-i", src,
                           "-f", "rawvideo", "-pix_fmt", "rgba", "-s", f"{w}x{h}", "-r", rate, "-i", "-",
                           "-filter_complex", "[0:v][1:v]overlay=shortest=1,format=yuv420p[v]",
                           "-map", "[v]", "-map", "0:a?", "-c:v", "libx264", "-crf", "18", "-c:a", "copy", out],
                          stdin=subprocess.PIPE)
    for i in range(math.ceil(duration * fps)):
        ff.stdin.write(overlay(i / fps).tobytes())
    ff.stdin.close()
    if ff.wait():
        sys.exit("ffmpeg failed")


src, out = sys.argv[1:3]
w, h, rate, fps, duration = probe(src)
font = ImageFont.truetype(FONT_FILE, round(w * SIZE), index=FONT_INDEX)
pad, line_h = round(font.size * 0.8), round(font.size * 1.7)
bar_h = round(font.size * 1.9)
code_x = pad + font.getlength("00") + pad
win_w, win_h = round(w * WIDTH), bar_h + pad * 2 + line_h * len(CODE)
shadow = Image.new("RGBA", (win_w + pad * 4, win_h + pad * 4))  # soft drop shadow under the window
ImageDraw.Draw(shadow).rounded_rectangle([pad * 2, pad * 2, win_w + pad * 2, win_h + pad * 2], radius=pad, fill=(0, 0, 0, 150))
shadow = shadow.filter(ImageFilter.GaussianBlur(pad))
starts = [START]  # each line starts once the one above it has finished and paused
for line in CODE:
    starts.append(starts[-1] + len(line.lstrip()) / CPS + PAUSE)
done = starts.pop() - PAUSE
render(src, out)

Find 3x winning ads

Recharm cuts your ad footage into tagged, searchable clips: hooks, testimonials, product shots. Find the shots that win, add the effect with Claude, and ship 3x more ad edits.

Start 14-day free trial