According to folk etymology, the adjective cloak-and-dagger has its origin in fencing: the cloak, wrapped around one arm, was used as a defensive weapon. The illustration and quotation are from Old Sword-Play (1892) by Alfred Hutton:
Rapier and cloak
In this exercise the cloak takes the place, as a defensive weapon, of the buckler or the dagger. It must be turned twice round the left arm in such a manner as to cover the elbow, while the collar is grasped in the left hand the ends are to be passed over the arm so as to hang down in folds on the outside of it, and with these folds (never with the part which rests on the arm) the various attacks are parried. (Plate 30)
involving or characterised by mystery, intrigue, or espionage
This adjective is a development from the earlier cloak and sword, a translation of (comedia) de capa y espada*, a Spanish literary term for a type of dramas of romance, intrigue and melodrama in which the main characters are from the ranks of society which formerly wore cloaks and swords or daggers. One of the dramatists who established the popularity of this type of plays during the Spanish Golden Age (approximately from 1492 to 1659) was Lope de Vega Carpio (1562-1635).
(* The French translation is de cape et d’épée.)
The English term seems to have been introduced by Henry Richard Lord Holland (1773-1840) in Some Account of the Life and Writings of Lope Felix de Vega Carpio (1806):
The plays of that period do not admit of the distinction of tragedies and comedies, according to the common, or at least the French acceptation of those terms. They are not comedies; for not only distressing situations and personages of high rank, but assassinations and murders are admitted into their plots: on the other hand, the sprightliness of the dialogue, the lowness of some of the characters, the familiarity of the language, and the conclusion of the piece, which is generally fortunate, deprive them of all claims to the title of tragedies. Yet even in Lope’s works there is an evident difference in his conception as well as execution of two distinct species of dramatic compositions. In one, the characters and incidents are intended to excite surprise and admiration; in the other, merriment mixed occasionally with interest. Love indeed is the subject of both: but in one it is the love which distinguished the ages of chivalry; in the other, the gallantry which succeeded to it, and which the poets had only to copy from the times in which they lived. The plays of the latter description, when the distinction became more marked, acquired the name of Comedias de Capa y Espada, Comedies of the Cloak and Sword, from the dresses in which they were represented; and the former that of Heroic Comedies, from the character of the personages and incidents which compose them.
The English novelist Hugh Seymour Walpole (1884-1941) used the original expression as late as 1921 in The Young Enchanted: A Romantic Story:
In literature her great period had been during the Romantic Tushery* of 1895 to 1905. How she had torn and scarified the Kailyard novelists**, how the Cloak and Sword Romances had bled beneath her whip. Now none of these remained, and the modern Realism had gone far beyond her most confident anticipations.
(* tushery: used by R. L. Stevenson for a conventional style of romance characterised by excessive use of affected archaisms such as ‘tush!’; hence, sentimental or romanticising writing
** Kailyard School: a late 19th-century movement in Scottish fiction characterised by a sentimental idealisation of humble village life)
The current form cloak-and-dagger might have been popularised by the English novelist Charles Dickens (1812-70), who wrote, in Barnaby Rudge: A Tale of the Riots of Eighty (1840-41):
His servant brought in a very small scrap of dirty paper, tightly sealed in two places, on the inside whereof was inscribed in pretty large text these words. “A friend. Desiring of a conference. Immediate. Private. Burn it when you’ve read it.”
“Where in the name of the Gunpowder Plot did you pick up this?” said his master.
It was given him by a person then waiting at the door, the man replied.
“With a cloak and dagger?” said Mr. Chester.
With nothing more threatening about him, it appeared, than a leather apron and a dirty face.
But the terms cloak and dagger were associated with dramas of intrigue and romantic or melodramatic adventure before Dickens wrote his novel. For example, a review of “a very successful melo-drama entitled The Goldsmith, translated from the French” in La Belle Assemblée, or Court and Fashionable Magazine of September 1827 contains:
Cardillac, the goldsmith, though possessed of considerable wealth, is in the constant practice of murdering his victims, most frequently his own customers. He has an amiable daughter, lsabelIa, who is in love with Oliver, the assistant of Cardillac. Oliver, at an early period of the piece detects the horrid practices of the goldsmith, but cannot urge himself to betray the murderer, he being the father of Isabella. Oliver still continues to watch the practice of Cardillac, and intercepts him just as he has unsuccessfully attacked Count Rosenberg; the goldsmith, mortally wounded, ﬂees, leaving his cloak and dagger at the feet of Oliver, who is arraigned of the attempt at murder, but who refuses to save himself by the betrayal of Cardillac. While the examination, which takes place in the goldsmith’s house, is proceeding, Cardillac rushes in, confesses his crimes, asserts the innocence of Oliver, and dies.